Commit 576b18e6 authored by Katharina Fey's avatar Katharina Fey

rpc-layer: implementing simple broker connection listening

parent f540d579
......@@ -1652,9 +1652,9 @@ dependencies = [
"netmod-tcp",
"netmod-udp",
"pnet",
"qrpc-sdk",
"ratman",
"ratman-configure",
"rpc-broker",
"tracing",
"tracing-subscriber",
]
......
......@@ -12,7 +12,7 @@ netmod-tcp = { path = "../../netmods/netmod-tcp" }
netmod-udp = { path = "../../netmods/netmod-udp" }
ratman = { path = "../../ratman" }
ratman-configure = { path = "../../ratman/configure" }
qrpc-sdk = { path = "../../rpc-layer/qrpc-sdk" }
rpc-broker = { path = "../../rpc-layer/rpc-broker" }
async-std = { version = "=1.5", features = ["attributes"] }
clap = { version = "2.0", features = ["wrap_help", "color"] }
......
......@@ -7,10 +7,11 @@ mod log;
mod state;
mod upnp;
use std::time::Duration;
use async_std::{task, future, task::Poll};
use state::State;
use async_std::{future, task, task::Poll};
use rpc_broker::Broker;
use std::time::Duration;
use tracing::error;
pub(crate) fn elog<S: Into<String>>(msg: S, code: u16) -> ! {
......@@ -18,14 +19,12 @@ pub(crate) fn elog<S: Into<String>>(msg: S, code: u16) -> ! {
std::process::exit(code.into());
}
use qrpc_sdk::{RpcSocket, };
#[async_std::main]
async fn main() {
log::parse_log_level();
let b = Broker::new();
// let app = cfg::cli();
// let cfg = cfg::match_fold(app);
// let _state = State::new(&cfg).await;
......@@ -37,7 +36,8 @@ async fn main() {
// }
// }
// let _ = future::timeout(Duration::from_secs(10), async {
// let _: () = future::poll_fn(|_| Poll::Pending).await;
// }).await;
let _ = future::timeout(Duration::from_secs(10), async {
let _: () = future::poll_fn(|_| Poll::Pending).await;
})
.await;
}
......@@ -81,10 +81,11 @@ pub mod rpc {
pub use crate::carrier_capnp::{carrier, register, unregister, upgrade};
}
mod service;
pub mod builders;
pub mod errors;
mod service;
mod socket;
pub mod socket;
pub use service::Service;
pub use socket::{default_socket_path, RpcSocket};
......@@ -7,7 +7,7 @@ use crate::{
};
use async_std::{future, sync::Arc, task};
use capnp::traits::FromPointerReader;
use socket2::{Domain, SockAddr, Socket, Type};
use socket2::{Domain, Type};
use std::{
future::Future,
io::Result,
......@@ -17,6 +17,8 @@ use std::{
time::Duration,
};
pub use socket2::{SockAddr, Socket};
/// Get the location the qrpc socket _should_ be by default
///
/// This default can be overridden, though! It's safer to make this
......
//! An extensible rpc message broker for the libqaul ecosystem.
use qrpc_sdk::{default_socket_path, RpcSocket};
use qrpc_sdk::{
default_socket_path,
socket::{SockAddr, Socket},
RpcSocket,
};
use std::{path::PathBuf, sync::Arc};
use tracing::info;
/// Hold the main broker state
pub struct Broker {
......@@ -9,11 +14,17 @@ pub struct Broker {
}
impl Broker {
pub fn new<P: Into<PathBuf>>(path: Option<P>) -> Self {
let path = path.map(|p| p.into()).unwrap_or(default_socket_path());
let sock = RpcSocket::new(path).unwrap();
pub fn new() -> Self {
let sock = RpcSocket::create(default_socket_path(), |socket, addr| {
Self::handle_connection(socket, addr);
})
.unwrap();
Self { sock }
}
fn handle_connection(sock: Socket, addr: SockAddr) {
info!("Receiving connection from {:?}", addr);
}
}
// #[test]
......
......@@ -20,5 +20,9 @@ async fn main() {
"A simple service that says hello to everybody on the network.",
);
let sock = RpcSocket::new(default_socket_path()).unwrap();
serv.register(sock).await.unwrap();
let sock2 = RpcSocket::new(default_socket_path()).unwrap();
let sock3 = RpcSocket::new(default_socket_path()).unwrap();
// serv.register(sock).await.unwrap();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment