summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2018-01-25 14:24:41 +0100
committerJustus Winter <justus@sequoia-pgp.org>2018-01-25 18:01:16 +0100
commit9d174f4152c509a7b8d2c6ac18d26d2b3401265c (patch)
treeeba9af36fd7af9404a63d77022ca5a1056646177
parentc016b29c530614445d102d824e8f2adb5cc57708 (diff)
net: Attach Context to Descriptor.
- Now that the Context is Send + Clone, we can attach a clone to the Descriptor and pass it to the server thread.
-rw-r--r--net/src/ipc.rs19
-rw-r--r--store/src/backend/mod.rs2
2 files changed, 12 insertions, 9 deletions
diff --git a/net/src/ipc.rs b/net/src/ipc.rs
index a4e84d81..31cd16d6 100644
--- a/net/src/ipc.rs
+++ b/net/src/ipc.rs
@@ -82,9 +82,8 @@ pub type HandlerFactory = fn(descriptor: Descriptor,
/// A descriptor is used to connect to a service.
#[derive(Clone)]
pub struct Descriptor {
- ipc_policy: core::IPCPolicy,
- pub home: PathBuf,
- pub rendezvous: PathBuf,
+ ctx: core::Context,
+ rendezvous: PathBuf,
executable: PathBuf,
factory: HandlerFactory,
}
@@ -98,14 +97,18 @@ impl Descriptor {
executable: PathBuf, factory: HandlerFactory)
-> Self {
Descriptor {
- home: ctx.home().into(),
- ipc_policy: *ctx.ipc_policy(),
+ ctx: ctx.clone(),
rendezvous: rendezvous,
executable: executable,
factory: factory,
}
}
+ /// Returns the context.
+ pub fn context(&self) -> &core::Context {
+ &self.ctx
+ }
+
/// Connect to a descriptor, starting the server if necessary.
pub fn connect(&self, handle: &tokio_core::reactor::Handle) -> io::Result<RpcSystem<Side>> {
let do_connect =
@@ -159,7 +162,7 @@ impl Descriptor {
let cookie = Cookie::new()?;
for external in [true, false].iter() {
// Implement the IPC pocicy.
- if self.ipc_policy == core::IPCPolicy::Internal && *external {
+ if *self.ctx.ipc_policy() == core::IPCPolicy::Internal && *external {
// Do not try to fork.
continue;
}
@@ -167,7 +170,7 @@ impl Descriptor {
let addr = match self.start(*external) {
Ok(a) => a,
Err(e) => if *external {
- if self.ipc_policy == core::IPCPolicy::External {
+ if *self.ctx.ipc_policy() == core::IPCPolicy::External {
// Fail!
return Err(e);
}
@@ -236,7 +239,7 @@ impl Descriptor {
Command::new(&self.executable.clone().into_os_string())
.arg("--home")
- .arg(self.home.to_string_lossy().into_owned())
+ .arg(self.ctx.home().to_string_lossy().into_owned())
// l will be closed here if the exec fails.
.stdin(unsafe { Stdio::from_raw_fd(fd) })
.spawn()?;
diff --git a/store/src/backend/mod.rs b/store/src/backend/mod.rs
index 10afe15a..d4f8ca3f 100644
--- a/store/src/backend/mod.rs
+++ b/store/src/backend/mod.rs
@@ -94,7 +94,7 @@ struct NodeServer {
impl NodeServer {
fn new(descriptor: ipc::Descriptor, handle: Handle) -> Result<Self> {
- let mut db_path = descriptor.home.clone();
+ let mut db_path = descriptor.context().home().to_path_buf();
db_path.push("keystore.sqlite");
let c = Connection::open(db_path)?;