Commit 6eccc17d authored by Kaiden Fey's avatar Kaiden Fey Committed by Katharina Fey

qrpc-sdk: changing the way that capnproto types are used

We won't be using the actual RPC implementation for now.  The system
looks too complicated and does too many things we don't really want it
to do.  The qrpc-sdk can abstract a lot of the ugliness away from the
end-user, and ultimately we just want to pass messages along to the
other side to call some functions.

The only thing the receiving end will have to do is gracefully accept
when fields are missing (and use default values if at all possible),
or report back to a client that it's too old.
parent 04e8ee7d
@0x97aa1eae99a0bced; # this was generated by capnp id
interface RpcBroker {
struct Service {
# Names follow reverse FQD specification: net.qaul.example
name @0 :Text;
# Versions are up to services to interpret. A simple
# incrementing number is fine, but feel free to encode semver
# into this field.
version @1 :Int16;
# A description of the service shown to end-users. Make it something concise
description @2 :Text;
}
struct Service {
# Names follow reverse FQD specification: net.qaul.example
name @0 :Text;
# Versions are up to services to interpret. A simple
# incrementing number is fine, but feel free to encode semver
# into this field.
version @1 :Int16;
# A description of the service shown to end-users. Make it something concise
description @2 :Text;
}
# Register this service with the broker and return a unique
# hash-id that users can verify the authenticity of this service.
registerService @0 (s :Service) -> (hash_id :Text);
# Unregister this service from the broker
unregisterService @1 (hash_id :Text) -> (success :Bool);
struct Register {
service @0 :Service;
respHashId @1 :Text;
}
# Upgrade this service in-place
upgradeService @2 (s :Service, hash_id :Text) -> (success :Bool);
struct Unregister {
hashId @0 :Text;
resp @1 :Bool;
}
struct Upgrade {
service @0 :Service;
hashId @1 :Text;
resp @2 :Bool;
}
......@@ -51,7 +51,7 @@ impl<'s, T: FromPointerReader<'s>> MsgReader<'s, T> {
///
/// ```
/// # use qrpc_sdk::io::Result;
/// use qrpc_sdk::{io::MsgReader, rpc::service};
/// use qrpc_sdk::{io::MsgReader, types::service};
///
/// # fn run_code() -> Result<()> {
/// # let buf = vec![];
......
......@@ -10,15 +10,7 @@
//! In order to interact with a running qrpc-broker instance your
//! service needs to register itself and it's capabilities. This
//! mechanism is handled by this sdk.
//!
//! If you want other third-party services to be able to depend on
//! your service you may want to split it into two parts: one part
//! contains the service logic, the other type and RPC interface
//! information. This way a third-party service can include your
//! services' type library (usually called `<service name>-rpc`), and
//! gain access to all public RPC functions.
//!
//! If this is not a requirement for you, don't worry about it.
pub mod io;
......@@ -32,13 +24,26 @@ pub(crate) mod carrier_capnp {
include!(concat!(env!("OUT_DIR"), "/schema/carrier_capnp.rs"));
}
/// Contains concrete RPC types and APIs
/// Basic qrpc trasmission types
///
/// This interface is exposed to let other parts of the qrpc ecosystem
/// parse and generate these types. When using this library directly,
/// try to avoid using them. Use the main type interface documented
/// in the root of the crate instead.
pub mod types {
pub use crate::carrier_capnp::service;
}
/// Unterlying RPC message types
///
/// As with the data types used by this crate, try to avoid using them
/// directly. Instead use the main API of the crate which invoces
/// these types internally
pub mod rpc {
use crate::carrier_capnp::rpc_broker as rpc;
pub use rpc::service;
pub use crate::carrier_capnp::{register, unregister, upgrade};
}
/// A service representation on the qrpc system
pub struct Service {
name: String,
......
//! # qaul rpc-broker
//!
//! An extensible rpc message broker for the libqaul ecosystem.
mod parser;
mod socket;
pub use parser::UtilReader;
/// Hold the main broker state
pub struct Broker {
}
pub struct Broker {}
// #[test]
// fn make_it_just_work_please() {
// use capnp::{message::Builder, serialize_packed};
// use qrpc_sdk::types::rpc_broker::service;
// let mut msg = Builder::new_default();
// let mut service = msg.init_root::<service::Builder>();
// let d = "This is a test service to see how the RPC layer works";
// service.set_name("net.qaul.test-service");
// service.set_version(1);
// service.set_description(d.clone());
// let mut buffer = vec![];
// serialize_packed::write_message(&mut buffer, &msg).unwrap();
// //// Now test our de-serialisation logic
// let reader = UtilReader::new(buffer).unwrap();
// let parsed: service::Reader = reader.get_root().unwrap();
// assert_eq!(parsed.get_name().unwrap(), "net.qaul.test-service");
// assert_eq!(parsed.get_description().unwrap(), d);
// assert_eq!(parsed.get_version(), 1);
// }
/*
/*
Stuff I need
service -> service
......
//! Wrapper module to read and write to and from an RPC socket
//!
use crate::UtilReader;
use async_std::{sync::Arc, task};
use byteorder::{BigEndian, ByteOrder};
use socket2::{Domain, SockAddr, Socket, Type};
......@@ -10,6 +12,8 @@ use std::{
sync::atomic::{AtomicBool, Ordering},
};
use qrpc_sdk::types::rpc_broker::service;
pub(crate) struct RpcSocket {
inner: Socket,
run: AtomicBool,
......@@ -51,10 +55,11 @@ impl RpcSocket {
None => continue,
};
let buf = vec![0, len];
if self.inner.recv(&mut buf).is_err() && continue {}
let mut buf = vec![0; len];
if self.inner.recv(buf.as_mut_slice()).is_err() && continue {}
let msg = UtilReader::new(buf).unwrap();
let root: service::Reader = msg.get_root().unwrap();
}
}
}
......@@ -63,5 +68,5 @@ impl RpcSocket {
fn read_length(sock: &Socket) -> Option<usize> {
let mut len_buf = [0; 8];
sock.recv(&mut len_buf).ok()?;
BigEndian::read_u64(&len_buf)
Some(BigEndian::read_u64(&len_buf) as usize)
}
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