partial refactor but need to switch branches

This commit is contained in:
bunnie 2021-03-28 19:36:55 +08:00
parent e889765caf
commit 88d66f4fd2
4 changed files with 54 additions and 26 deletions

2
Cargo.lock generated
View file

@ -1691,6 +1691,8 @@ dependencies = [
"heapless",
"log",
"log-server",
"num-derive",
"num-traits",
"rkyv 0.4.3",
"ticktimer-server",
"utralib",

View file

@ -9,6 +9,8 @@ version = "0.1.0"
hash32 = "0.1.0"
hash32-derive = "0.1.0"
heapless = "0.5"
num-derive = {version = "0.3", default-features = false}
num-traits = {version = "0.2", default-features = false}
log = "0.4"
log-server = {path = "../log-server"}
ticktimer-server = {path = "../ticktimer-server"}

View file

@ -1,16 +1,33 @@
#![allow(dead_code)]
use xous::CID;
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
#[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 {
/// Create a new server with the given name and return its SID.
Register(xous_ipc::String::<64>),
@ -24,7 +41,7 @@ pub(crate) enum Request {
// Return values
/// The caller must perform an AuthenticatedLookup using this challenge
AuthenticateRequest([u32; 8]),
AuthenticateRequest(AuthenticatedRequest),
/// The connection failed for some reason
Failure,
@ -34,12 +51,7 @@ pub(crate) enum Request {
/// A connection was successfully made with the given 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)]
pub(crate) struct AuthenticatedLookup {
@ -48,21 +60,18 @@ pub(crate) struct AuthenticatedLookup {
pub challenge: [u32; 8],
}
#[derive(Debug)]
pub struct Authenticate {
pub name: xous_ipc::String::<64>,
pub success: bool,
pub response_to_challenge: [u32; 8],
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
pub(crate) struct AuthenticatedRequest {
pub request: AuthenicatedLookup, // a copy of the original request. We don't trust it, but it's helpful to have for reference
pub nonce: [u32; 4],
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
// burdening the Kernel String type with the Hash32 methods
//////////////////////////////////////////////////////////////////////////////////////////////
// --------------------- Taken from rkyv docs https://docs.rs/rkyv/0.3.0/rkyv/trait.Archive.html //
#[derive(Debug, Copy, Clone)]

View file

@ -4,6 +4,21 @@ pub mod api;
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> {
// 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();