mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
partial refactor but need to switch branches
This commit is contained in:
parent
e889765caf
commit
88d66f4fd2
4 changed files with 54 additions and 26 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -1691,6 +1691,8 @@ dependencies = [
|
||||||
"heapless",
|
"heapless",
|
||||||
"log",
|
"log",
|
||||||
"log-server",
|
"log-server",
|
||||||
|
"num-derive",
|
||||||
|
"num-traits",
|
||||||
"rkyv 0.4.3",
|
"rkyv 0.4.3",
|
||||||
"ticktimer-server",
|
"ticktimer-server",
|
||||||
"utralib",
|
"utralib",
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@ version = "0.1.0"
|
||||||
hash32 = "0.1.0"
|
hash32 = "0.1.0"
|
||||||
hash32-derive = "0.1.0"
|
hash32-derive = "0.1.0"
|
||||||
heapless = "0.5"
|
heapless = "0.5"
|
||||||
|
num-derive = {version = "0.3", default-features = false}
|
||||||
|
num-traits = {version = "0.2", default-features = false}
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
log-server = {path = "../log-server"}
|
log-server = {path = "../log-server"}
|
||||||
ticktimer-server = {path = "../ticktimer-server"}
|
ticktimer-server = {path = "../ticktimer-server"}
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,33 @@
|
||||||
#![allow(dead_code)]
|
|
||||||
|
|
||||||
use xous::CID;
|
|
||||||
use hash32::{Hash, Hasher};
|
use hash32::{Hash, Hasher};
|
||||||
|
|
||||||
// bottom 16 bits are reserved for structure re-use by other servers
|
|
||||||
pub const ID_REGISTER_NAME: u32 = 0x1_0000;
|
|
||||||
pub const ID_LOOKUP_NAME: u32 = 0x2_0000;
|
|
||||||
pub const ID_AUTHENTICATE: u32 = 0x3_0000;
|
|
||||||
|
|
||||||
pub const AUTHENTICATE_TIMEOUT: u32 = 10_000; // time in ms that a process has to respond to an authentication request
|
pub const AUTHENTICATE_TIMEOUT: u32 = 10_000; // time in ms that a process has to respond to an authentication request
|
||||||
|
|
||||||
#[derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Debug)]
|
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
||||||
|
pub(crate) enum Request {
|
||||||
|
/// Create a new server with the given name and return its SID.
|
||||||
|
Register,
|
||||||
|
|
||||||
|
/// Create a connection to the target server.
|
||||||
|
Lookup,
|
||||||
|
|
||||||
|
/// Create an authenticated connection to the target server.
|
||||||
|
AuthenticatedLookup,
|
||||||
|
|
||||||
|
// Return values
|
||||||
|
|
||||||
|
/// The caller must perform an AuthenticatedLookup using this challenge
|
||||||
|
AuthenticateRequest,
|
||||||
|
|
||||||
|
/// The connection failed for some reason
|
||||||
|
Failure,
|
||||||
|
|
||||||
|
/// A server was successfully created with the given SID
|
||||||
|
SID,
|
||||||
|
|
||||||
|
/// A connection was successfully made with the given CID
|
||||||
|
CID,
|
||||||
|
}
|
||||||
|
/*
|
||||||
pub(crate) enum Request {
|
pub(crate) enum Request {
|
||||||
/// Create a new server with the given name and return its SID.
|
/// Create a new server with the given name and return its SID.
|
||||||
Register(xous_ipc::String::<64>),
|
Register(xous_ipc::String::<64>),
|
||||||
|
|
@ -24,7 +41,7 @@ pub(crate) enum Request {
|
||||||
// Return values
|
// Return values
|
||||||
|
|
||||||
/// The caller must perform an AuthenticatedLookup using this challenge
|
/// The caller must perform an AuthenticatedLookup using this challenge
|
||||||
AuthenticateRequest([u32; 8]),
|
AuthenticateRequest(AuthenticatedRequest),
|
||||||
|
|
||||||
/// The connection failed for some reason
|
/// The connection failed for some reason
|
||||||
Failure,
|
Failure,
|
||||||
|
|
@ -34,12 +51,7 @@ pub(crate) enum Request {
|
||||||
|
|
||||||
/// A connection was successfully made with the given CID
|
/// A connection was successfully made with the given CID
|
||||||
CID(CID),
|
CID(CID),
|
||||||
}
|
}*/
|
||||||
|
|
||||||
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
|
||||||
pub(crate) struct Lookup {
|
|
||||||
pub name: xous_ipc::String::<64>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
||||||
pub(crate) struct AuthenticatedLookup {
|
pub(crate) struct AuthenticatedLookup {
|
||||||
|
|
@ -48,21 +60,18 @@ pub(crate) struct AuthenticatedLookup {
|
||||||
pub challenge: [u32; 8],
|
pub challenge: [u32; 8],
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
||||||
pub struct Authenticate {
|
pub(crate) struct AuthenticatedRequest {
|
||||||
pub name: xous_ipc::String::<64>,
|
pub request: AuthenicatedLookup, // a copy of the original request. We don't trust it, but it's helpful to have for reference
|
||||||
pub success: bool,
|
pub nonce: [u32; 4],
|
||||||
pub response_to_challenge: [u32; 8],
|
pub response: [u32; 8],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Authenticate {
|
|
||||||
pub fn mid(&self) -> u32 {
|
|
||||||
ID_AUTHENTICATE as u32
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// We keep XousServerName around because want to be able to index off the server name, without
|
// We keep XousServerName around because want to be able to index off the server name, without
|
||||||
// burdening the Kernel String type with the Hash32 methods
|
// burdening the Kernel String type with the Hash32 methods
|
||||||
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// --------------------- Taken from rkyv docs https://docs.rs/rkyv/0.3.0/rkyv/trait.Archive.html //
|
// --------------------- Taken from rkyv docs https://docs.rs/rkyv/0.3.0/rkyv/trait.Archive.html //
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,21 @@ pub mod api;
|
||||||
|
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
|
|
||||||
|
pub struct XousNames {
|
||||||
|
conn: xous::CID,
|
||||||
|
}
|
||||||
|
impl XousNames {
|
||||||
|
pub fn new() -> Result<Self, Error> {
|
||||||
|
let conn = xous::connect(xous::SID::from_bytes(b"xous-name-server").unwrap()).expect("Couldn't connect to XousNames");
|
||||||
|
Ok(XousNames {
|
||||||
|
conn,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
pub fn register_name(&self, name: &str) -> Result<xous::SID, xous::Error> {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn register_name(name: &str) -> Result<xous::SID, xous::Error> {
|
pub fn register_name(name: &str) -> Result<xous::SID, xous::Error> {
|
||||||
// Ensure we have a connection to the nameserver. If one exists, this is a no-op.
|
// Ensure we have a connection to the nameserver. If one exists, this is a no-op.
|
||||||
let ns_id = xous::SID::from_bytes(b"xous-name-server").unwrap();
|
let ns_id = xous::SID::from_bytes(b"xous-name-server").unwrap();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue