mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
the name server itself
This commit is contained in:
parent
cce89395f6
commit
1075dff559
4 changed files with 159 additions and 0 deletions
21
services/xous-names/Cargo.toml
Normal file
21
services/xous-names/Cargo.toml
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
[package]
|
||||
name = "xous-names"
|
||||
version = "0.1.0"
|
||||
authors = ["bunnie <bunnie@kosagi.com>"]
|
||||
edition = "2018"
|
||||
description = ""
|
||||
|
||||
[dependencies]
|
||||
xous = { path = "../../xous-rs" }
|
||||
heapless = "0.5"
|
||||
log-server = { path = "../log-server" }
|
||||
log = "0.4"
|
||||
|
||||
[target.'cfg(not(any(windows,unix)))'.dependencies]
|
||||
utralib = { path = "../../utralib"}
|
||||
|
||||
[target.'cfg(any(windows,unix))'.dependencies]
|
||||
|
||||
[features]
|
||||
debugprint = []
|
||||
default = [] # "debugprint"
|
||||
92
services/xous-names/src/api.rs
Normal file
92
services/xous-names/src/api.rs
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
use xous::{Message, ScalarMessage, SID};
|
||||
|
||||
pub struct Registration {
|
||||
pub sid: SID,
|
||||
pub name: [u8; 64],
|
||||
pub name_len: usize,
|
||||
pub success: bool,
|
||||
// _padding: [u8; 4096-(core::mem::size_of::<SID>() + 64 + core::mem::size_of::<usize>() + core::mem::size_of::<bool>],
|
||||
}
|
||||
|
||||
pub struct Lookup {
|
||||
sid: SID,
|
||||
name: [u8; 64],
|
||||
name_len: usize,
|
||||
success: bool,
|
||||
autheticate: bool,
|
||||
challenge: [u32; 8],
|
||||
response: [u32; 8],
|
||||
// _padding: [u8; 4096-(core::mem::size_of::<SID>() + 64 + core::mem::size_of::<usize>() + core::mem::size_of::<bool>],
|
||||
}
|
||||
|
||||
pub const ID_REGISTER_NAME: usize = 0;
|
||||
pub const ID_LOOKUP_NAME: usize = 1;
|
||||
pub const ID_AUTHENTICATE: usize = 2;
|
||||
|
||||
/*
|
||||
#[derive(Debug)]
|
||||
pub enum Opcode {
|
||||
/// Register a 128-bit SID with a preferred, unique lookup name
|
||||
RegisterName(Registration),
|
||||
|
||||
/// Retrieve the 128-bit SID for a server, given its unique lookup name
|
||||
LookupName(Lookup),
|
||||
|
||||
/// Authenticate to the name server, based on nonce embedded in LookupName response
|
||||
/// this is always as a response to a lookupname that reqeusts the authentication challenge-response
|
||||
Authenticate(Lookup),
|
||||
}
|
||||
|
||||
impl<'a> core::convert::TryFrom<&'a Message> for Opcode {
|
||||
type Error = &'static str;
|
||||
fn try_from(message: &'a Message) -> Result<Self, Self::Error> {
|
||||
match message {
|
||||
Message::MutableBorrow(m) => {
|
||||
if m.id as u16 == ID_REGISTER_NAME {
|
||||
let registration: Registration = unsafe {
|
||||
&mut *(m.buf.as_mut_ptr() as *mut Registration)
|
||||
};
|
||||
Ok(Opcode::RegisterName(registration))
|
||||
}
|
||||
}
|
||||
_ => Err("unhandled message type"),
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
/* No "Into<>" methods -- we use the ipc::lend() to create messages
|
||||
impl Into<Message> for Opcode {
|
||||
fn into(self) -> Message {
|
||||
match self {
|
||||
Opcode::Reset => Message::Scalar(ScalarMessage {
|
||||
id: 1,
|
||||
arg1: 0,
|
||||
arg2: 0,
|
||||
arg3: 0,
|
||||
arg4: 0,
|
||||
}),
|
||||
Opcode::RecalculateSleep => Message::Scalar(ScalarMessage {
|
||||
id: 131072,
|
||||
arg1: 0,
|
||||
arg2: 0,
|
||||
arg3: 0,
|
||||
arg4: 0,
|
||||
}),
|
||||
Opcode::ElapsedMs => Message::BlockingScalar(ScalarMessage {
|
||||
id: 4919,
|
||||
arg1: 0,
|
||||
arg2: 0,
|
||||
arg3: 0,
|
||||
arg4: 0,
|
||||
}),
|
||||
Opcode::SleepMs(ms) => Message::BlockingScalar(ScalarMessage {
|
||||
id: 3,
|
||||
arg1: ms,
|
||||
arg2: 0,
|
||||
arg3: 0,
|
||||
arg4: 0,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
5
services/xous-names/src/lib.rs
Normal file
5
services/xous-names/src/lib.rs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#![cfg_attr(target_os = "none", no_std)]
|
||||
|
||||
pub mod api;
|
||||
|
||||
use xous::{send_message, Error, CID};
|
||||
41
services/xous-names/src/main.rs
Normal file
41
services/xous-names/src/main.rs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
#![cfg_attr(target_os = "none", no_std)]
|
||||
#![cfg_attr(target_os = "none", no_main)]
|
||||
|
||||
mod api;
|
||||
use api::*;
|
||||
|
||||
use heapless::String;
|
||||
use heapless::Vec;
|
||||
use heapless::consts::*;
|
||||
|
||||
use log::{error, info};
|
||||
|
||||
#[xous::xous_main]
|
||||
fn xmain() -> ! {
|
||||
log_server::init_wait().unwrap();
|
||||
|
||||
let name_server =
|
||||
xous::create_server_with_address(b"xousnames-server").expect("Couldn't create xousnames-server");
|
||||
|
||||
info!("NS: started");
|
||||
loop {
|
||||
let envelope = xous::receive_message(name_server).unwrap();
|
||||
info!("NS: received message");
|
||||
if let xous::Message::MutableBorrow(m) = &envelope.body {
|
||||
if m.id == ID_REGISTER_NAME {
|
||||
let registration: &mut Registration = unsafe {
|
||||
&mut *(m.buf.as_mut_ptr() as *mut Registration)
|
||||
};
|
||||
let namevec: Vec<u8, U64> = Vec::from_slice(®istration.name).unwrap();
|
||||
let name: String<U64> = String::from_utf8(namevec).unwrap();
|
||||
info!("NS: registration request for {}", name);
|
||||
registration.success = true;
|
||||
xous::return_memory(envelope.sender, m.buf).unwrap();
|
||||
} else {
|
||||
error!("NS: unknown message ID received");
|
||||
}
|
||||
} else {
|
||||
error!("NS: couldn't convert opcode");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue