libqaul: refactoring external type fascade into separate crate

develop
Katharina Fey 4 years ago
parent bef845147d
commit 5e99de6ea0
Signed by: kookie
GPG Key ID: 90734A9E619C8A6C
  1. 1
      Cargo.lock
  2. 8
      libqaul/Cargo.toml
  3. 30
      libqaul/src/api/contacts.rs
  4. 6
      libqaul/src/api/users.rs
  5. 39
      libqaul/src/rpc.rs
  6. 9
      libqaul/types/Cargo.toml
  7. 87
      libqaul/types/schema/types.capnp
  8. 3
      libqaul/types/src/lib.rs
  9. 2
      netmods/netmod-udp/src/socket.rs
  10. 29
      notes.md

1
Cargo.lock generated

@ -1247,6 +1247,7 @@ name = "libqaul-types"
version = "0.1.0"
dependencies = [
"alexandria-tags",
"capnpc",
"ratman-identity",
"serde",
]

@ -37,8 +37,8 @@ serde_json = "1.0"
tempfile = "3.0"
[features]
default = ["generate-message", "testing"]
generate-message = []
testing = ["tempfile", "netmod-mem"]
default = ["generate-message", "testing", "rpc"] # TODO: remove rpc default?
ffi-java = ["jni"]
rpc = ["qrpc-sdk"]
generate-message = []
rpc = ["qrpc-sdk"]
testing = ["tempfile", "netmod-mem"]

@ -97,33 +97,3 @@ impl<'qaul> Contacts<'qaul> {
Ok(vec![])
}
}
// impl Qaul {
// /// Find a subset of contacts with some query
// pub fn contacts_query(
// &self,
// user: UserAuth,
// query: ContactQuery,
// ) -> QaulResult<Vec<UserProfile>> {
// let (ref my_id, ref token) = user.trusted()?;
// self.auth.verify_token(my_id, token)?;
// self.contacts
// .query(my_id, query)?
// .into_iter()
// .map(|ref id| self.users.get(id))
// .collect()
// }
// /// Enumerate all contacts known by a user
// pub fn contacts_get_all(&self, user: UserAuth) -> QaulResult<Vec<UserProfile>> {
// let (ref my_id, ref token) = user.trusted()?;
// self.auth.verify_token(my_id, token)?;
// self.contacts
// .get_all(my_id)?
// .into_iter()
// .map(|ref id| self.users.get(id))
// .collect()
// }
// }

@ -133,10 +133,4 @@ impl<'qaul> Users<'qaul> {
let (id, _) = self.q.auth.trusted(user)?;
self.q.users.modify(id, update).await
}
/// Validate that a `UserAuth` represents a currently logged in user
pub fn ok(&self, user: UserAuth) -> Result<()> {
self.q.auth.trusted(user)?;
Ok(())
}
}

@ -0,0 +1,39 @@
//! libqaul RPC compatibility adapter
//!
//! By default `libqaul` is only meant to be used by local Rust
//! clients. To allow third-party clients to also interact with a
//! running stack, you should use the qrpc bus. This module exposes
//! some utilities to bind libqaul functions to an rpc server.
//!
//! To write a service to use libqaul, include the client-lib
//! (libqaul-rpc) for type and API configuration.
use crate::QaulRef;
use qrpc_sdk::{default_socket_path, error::RpcResult, RpcSocket, Service};
use async_std::sync::Arc;
/// A pluggable RPC server that wraps around libqaul
///
/// Initialise this server with a fully initialised [`Qaul`] instance.
/// You will lose access to this type once you start the RPC server.
/// Currently there is no self-management interface available via
/// qrpc.
///
pub struct RpcServer {
inner: QaulRef,
socket: Arc<RpcSocket>,
}
impl RpcServer {
/// Wrapper around `new` with `default_socket_path()`
pub async fn start_default(inner: QaulRef) -> RpcResult<Self> {
let (addr, port) = default_socket_path();
Self::new(inner, addr, port).await
}
pub async fn new(inner: QaulRef, addr: &str, port: u16) -> RpcResult<Self> {
let socket = RpcSocket::connect(addr, port).await?;
let _self = Self { inner, socket };
Ok(_self)
}
}

@ -8,4 +8,11 @@ edition = "2018"
[dependencies]
ratman-identity = { version = "0.5", path = "../../ratman/identity", features = ["random"] }
serde = { version = "1.0", features = ["derive"] }
alexandria-tags = { path = "../../utils/alexandria-tags" }
alexandria-tags = { path = "../../utils/alexandria-tags" }
[build-dependencies]
capnpc = { version = "0.13", optional = true }
[features]
rpc = ["capnpc"]

@ -0,0 +1,87 @@
struct UserAuth {
id @0 :Text;
token @1 :Text;
}
struct ContactQuery {
union {
nick @0 :Text;
trust :group {
val @1 :Int8;
fuz @2 :Int8;
}
met @3 :Bool;
location @4 :Text;
notes @5 :Text;
}
}
struct Mode {
union {
flood @0 :Void;
std @1 :Text;
}
}
struct IdType {
union {
unique @0 :Void;
grouped @1 :Text;
}
}
struct SeviceId {
union {
# It's one of the most common passwords after all
god @0 :Void;
id @1 :Text;
}
}
struct Tag {
key @0 :Text;
val @1 :Data;
}
struct TagSet {
tags @0 :List(Tag);
}
struct MsgQuery {
id @0 :Text;
sender @1 :Text;
tags @2 :TagSet;
skip @3 :UInt;
}
struct MetadataMap {
name @0 :Text;
map @1 :List(Entry);
struct Entry {
key @0 :Text;
val @1 :Data;
}
}
struct SetDiff(Val) {
union {
set @0 :Val;
unset @0 :Val;
}
}
struct UserUpdate {
handle @0 :Text;
disp_name @1 :Text;
add_to_bio @2 :List(BioLine);
rm_fr_bio @3 :List(Text);
add_serv @4 :Text;
rm_serv @5 :Text;
avi_data @6 :SetDiff(Data);
struct BioLine {
key @0 :Text;
val @1 :Text;
}
}

@ -15,3 +15,6 @@ pub mod error;
pub mod messages;
pub mod services;
pub mod users;
#[cfg(feature = "rpc")]
pub mod rpc;

@ -147,6 +147,8 @@ fn test_init() {
});
}
// FIXME: broken test
#[ignore]
#[test]
fn test_single_unicast() {
task::block_on(async {

@ -0,0 +1,29 @@
# libqaul api scopes
* contacts
* modify(userauth, contact-id, lambda)
* get(userauth, contact-id)
* query(userauth, contact query)
* all(userauth)
* messages
* send(userauth, mode, id_type, into service, into tagset, payload (vec u8))
* subscribe(userauth, into service, into tagset)
* query(userauth, into service, msgquery)
* services
* register(service name, callback(service event))
* unregister(name)
* save(userauth, into service, metadata map, into tagset)
* delete(userauth, into service, into key)
* query(userauth, into service, into tagset)
* users
* list()
* list_remote() (???)
* is_authenticated(userauth)
* create(password)
* delete(userauth)
* change_pw(userauth, new password)
* login(user id, password)
* logout(userauth)
* get(user id)
* update(userauth, user update)
Loading…
Cancel
Save