Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F73638
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Subscribers
None
View Options
diff --git a/crates/api/src/lib.rs b/crates/api/src/lib.rs
index a768ab8..85b5404 100644
--- a/crates/api/src/lib.rs
+++ b/crates/api/src/lib.rs
@@ -1,36 +1,48 @@
use std::sync::Arc;
use tower_http::trace::TraceLayer;
use axum::{
routing::get,
extract::{State, Request, Json, Path, Extension, Query},
routing::post,
};
pub use axum::serve;
struct AppState {
collar: libcollar::State,
}
pub fn app(collar: libcollar::State) -> axum::Router {
let state = Arc::new(AppState { collar });
// build our application with a single route
let app = axum::Router::new()
.route("/", get(|| async { "collared." }))
.route("/ng/eiface/{name}", post(post_ng_eiface))
+ .route("/store/namespace/{name}/{key}/{value}", post(post_ns_key))
+ .route("/store/namespace/{name}/{key}", get(get_ns_key))
.with_state(state)
.layer(tower_http::trace::TraceLayer::new_for_http());
app
}
+async fn post_ns_key(State(state): State<Arc<AppState>>, Path((name, key, value)): Path<(String, String, String)>) -> Result<String, String> {
+ let ns = state.collar.store.namespaces();
+ Ok("todo".to_string())
+}
+
+async fn get_ns_key(State(state): State<Arc<AppState>>, Path((name, key)): Path<(String, String)>) -> Result<String, String> {
+ let ns = state.collar.store.namespaces();
+ Ok("todo".to_string())
+}
+
async fn post_ng_eiface(State(state): State<Arc<AppState>>, Path(name): Path<String>) -> Result<String, String> {
let fname = name.clone();
let result = state.collar.leash().gated(move || {
Ok(libcollar::ng::new_eiface(&name))
}).await;
Ok(format!("sup {} => {:?}", &fname, result))
}
diff --git a/crates/libcollar/src/error.rs b/crates/libcollar/src/error.rs
index dfd55e9..42269e8 100644
--- a/crates/libcollar/src/error.rs
+++ b/crates/libcollar/src/error.rs
@@ -1,62 +1,65 @@
#[derive(thiserror::Error, Debug)]
pub enum Error {
//#[error("sys err")]
//SystemError(errno::Errno),
#[error("not a bridge")]
PathIsNotABridge,
#[error("invalid node type")]
InvalidNodeType(String, String),
#[error("bridge already exists")]
BridgeLinkExists(String, String),
#[error("utf8")]
InvalidUtf8(std::str::Utf8Error),
#[error("nul")]
NulError(String),
#[error("exists")]
Exists,
#[error("invalid file descriptor")]
InvalidDescriptor,
#[error("name too long")]
NameTooLong,
#[error("description too long")]
DescriptionTooLong,
#[error("interface not found")]
InterfaceNotFound,
#[error("out of memory")]
OutOfMemory,
#[error("operation not supported")]
NotSupported,
+ #[error(transparent)]
+ Store(#[from] store::Error),
+
#[error(transparent)]
Ifconfig(#[from] ifconfig::Error),
#[error(transparent)]
Netgraph(#[from] ng::Error),
#[error(transparent)]
TaskJoin(#[from] tokio::task::JoinError),
#[error(transparent)]
Io(#[from] std::io::Error),
#[error(transparent)]
Nul(#[from] std::ffi::NulError),
#[error(transparent)]
ParseNum(#[from] std::num::ParseIntError),
}
pub type Result<T, E = Error> = ::std::result::Result<T, E>;
diff --git a/crates/libcollar/src/libcollar.rs b/crates/libcollar/src/libcollar.rs
index ed39c62..4bd9f92 100644
--- a/crates/libcollar/src/libcollar.rs
+++ b/crates/libcollar/src/libcollar.rs
@@ -1,19 +1,21 @@
use crate::Result;
use crate::net;
pub struct State {
leash: net::Leash,
+ pub store: store::Store,
}
pub fn new() -> Result<State> {
Ok(State {
leash: net::Leash::new(),
+ store: store::open()?,
})
}
impl State {
pub fn leash(&self) -> &net::Leash {
&self.leash
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Jun 8, 5:52 AM (1 d, 2 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
47559
Default Alt Text
(3 KB)
Attached To
rCOLLAR collar
Event Timeline
Log In to Comment