Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map transports not services #106

Merged
merged 33 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
978e555
Relax type constraints in lots of places
rklaehn Nov 1, 2024
80b5f63
map the channel wip
rklaehn Nov 1, 2024
6c83e44
associated types everywhere
rklaehn Nov 1, 2024
57b842f
It works!
rklaehn Nov 1, 2024
41e21eb
Even more conversion
rklaehn Nov 1, 2024
115753f
Remove map.rs and some arcs
rklaehn Nov 1, 2024
3a916c2
Make modularize example work
rklaehn Nov 2, 2024
791ebb4
Remove explicit debug impl where possible
rklaehn Nov 2, 2024
4994efc
Separate AcceptError type in ConnectionErrors
rklaehn Nov 3, 2024
e6f9a1a
cleanup
rklaehn Nov 3, 2024
6600b0d
clippy
rklaehn Nov 3, 2024
f999020
ignore smoke test that just hangs
rklaehn Nov 3, 2024
9e1a04b
Get rid of remaining XBiY
rklaehn Nov 3, 2024
66eeeb1
Make the boxed transport available by default.
rklaehn Nov 3, 2024
69edba3
Make boxed and combined available by default.
rklaehn Nov 3, 2024
ffaf803
Avoid using public PhantomData in UpdateSink
rklaehn Nov 4, 2024
c30ba6a
Drop ConnectionMapExt and just move map directly to Connection
rklaehn Nov 4, 2024
2455dcf
Merge branch 'main' into map-transports-not-services
rklaehn Nov 5, 2024
13b7ef0
Add ServiceChannel trait alias
rklaehn Nov 5, 2024
7bad06c
fix
rklaehn Nov 5, 2024
03f97ab
Provide utilities to transform RpcServerError<X>
rklaehn Nov 5, 2024
2070d65
rename all the things
rklaehn Nov 5, 2024
1396e92
complete renaming
rklaehn Nov 5, 2024
e42000a
Add BoxedConnectionTypes
rklaehn Nov 5, 2024
b0fe953
Add docs for ServerStreamTypes
rklaehn Nov 5, 2024
ccbc078
Rename ServerStreamTypes to ListnerTypes
rklaehn Nov 5, 2024
067ae4b
Make boxed first class
rklaehn Nov 5, 2024
d9637d1
Rename ListenerTypes to ChannelTypes and move it into server
rklaehn Nov 5, 2024
eb55692
remove all in-memory transports from default
rklaehn Nov 5, 2024
f10a4d6
remove all in-memory transports from default
rklaehn Nov 5, 2024
fa5e771
Naming bikeshedding (#111)
rklaehn Nov 5, 2024
1839b2b
rename connection to channel and remove service_connection
rklaehn Nov 5, 2024
16b7c49
increase version numbers
rklaehn Nov 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ tracing-subscriber = "0.3.16"
tempfile = "3.5.0"
proc-macro2 = "1.0.66"
futures-buffered = "0.2.4"
testresult = "0.4.1"
nested_enum_utils = "0.1.0"

[features]
hyper-transport = ["dep:flume", "dep:hyper", "dep:bincode", "dep:bytes", "dep:tokio-serde", "dep:tokio-util"]
quinn-transport = ["dep:flume", "dep:quinn", "dep:bincode", "dep:tokio-serde", "dep:tokio-util"]
flume-transport = ["dep:flume"]
combined-transport = []
macros = []
default = ["flume-transport"]

Expand Down
4 changes: 2 additions & 2 deletions examples/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ impl Fs {
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let fs = Fs;
let (server, client) = quic_rpc::transport::flume::service_connection::<IoService>(1);
let client = RpcClient::new(client);
let (server, client) = quic_rpc::transport::flume::connection(1);
let client = RpcClient::<IoService, _>::new(client);
let server = RpcServer::new(server);
let handle = tokio::task::spawn(async move {
for _ in 0..1 {
Expand Down
2 changes: 1 addition & 1 deletion examples/macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ create_store_dispatch!(Store, dispatch_store_request);

#[tokio::main]
async fn main() -> anyhow::Result<()> {
let (server, client) = flume::service_connection::<StoreService>(1);
let (server, client) = flume::connection(1);
let server_handle = tokio::task::spawn(async move {
let target = Store;
run_server_loop(StoreService, server, target, dispatch_store_request).await
Expand Down
135 changes: 59 additions & 76 deletions examples/modularize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
use anyhow::Result;
use futures_lite::StreamExt;
use futures_util::SinkExt;
use quic_rpc::{transport::flume, RpcClient, RpcServer, ServiceConnection, ServiceEndpoint};
use quic_rpc::{
client::BoxedServiceConnection, transport::flume, RpcClient, RpcServer, ServiceEndpoint,
};
use tracing::warn;

use app::AppService;
Expand All @@ -19,14 +21,14 @@ use app::AppService;
async fn main() -> Result<()> {
// Spawn an inmemory connection.
// Could use quic equally (all code in this example is generic over the transport)
let (server_conn, client_conn) = flume::service_connection::<AppService>(1);
let (server_conn, client_conn) = flume::connection(1);

// spawn the server
let handler = app::Handler::default();
tokio::task::spawn(run_server(server_conn, handler));

// run a client demo
client_demo(client_conn).await?;
client_demo(BoxedServiceConnection::<AppService>::new(client_conn)).await?;
rklaehn marked this conversation as resolved.
Show resolved Hide resolved

Ok(())
}
Expand All @@ -50,8 +52,8 @@ async fn run_server<C: ServiceEndpoint<AppService>>(server_conn: C, handler: app
}
}
}
pub async fn client_demo<C: ServiceConnection<AppService>>(conn: C) -> Result<()> {
let rpc_client = RpcClient::new(conn);
pub async fn client_demo(conn: BoxedServiceConnection<AppService>) -> Result<()> {
let rpc_client = RpcClient::<AppService>::new(conn);
let client = app::Client::new(rpc_client.clone());

// call a method from the top-level app client
Expand Down Expand Up @@ -99,15 +101,12 @@ mod app {
//!
//! It could also easily compose services from other crates or internal modules.

use super::iroh;
use anyhow::Result;
use derive_more::{From, TryInto};
use quic_rpc::{
message::RpcMsg, server::RpcChannel, RpcClient, Service, ServiceConnection, ServiceEndpoint,
};
use quic_rpc::{message::RpcMsg, server::RpcChannel, RpcClient, Service, ServiceEndpoint};
use serde::{Deserialize, Serialize};

use super::iroh;

#[derive(Debug, Serialize, Deserialize, From, TryInto)]
pub enum Request {
Iroh(iroh::Request),
Expand Down Expand Up @@ -156,10 +155,14 @@ mod app {
pub async fn handle_rpc_request<E: ServiceEndpoint<AppService>>(
self,
req: Request,
chan: RpcChannel<AppService, E, AppService>,
chan: RpcChannel<AppService, E>,
) -> Result<()> {
match req {
Request::Iroh(req) => self.iroh.handle_rpc_request(req, chan.map()).await?,
Request::Iroh(req) => {
self.iroh
.handle_rpc_request(req, chan.map().boxed())
.await?
}
Request::AppVersion(req) => chan.rpc(req, self, Self::on_version).await?,
};
Ok(())
Expand All @@ -171,20 +174,16 @@ mod app {
}

#[derive(Debug, Clone)]
pub struct Client<S: Service, C: ServiceConnection<S>> {
pub iroh: iroh::Client<S, C>,
client: RpcClient<AppService, C, S>,
pub struct Client {
pub iroh: iroh::Client,
client: RpcClient<AppService>,
}

impl<S, C> Client<S, C>
where
S: Service,
C: ServiceConnection<S>,
{
pub fn new(client: RpcClient<AppService, C, S>) -> Self {
impl Client {
pub fn new(client: RpcClient<AppService>) -> Self {
Self {
iroh: iroh::Client::new(client.clone().map()),
client,
client: client.clone(),
iroh: iroh::Client::new(client.map().boxed()),
}
}

Expand All @@ -202,7 +201,7 @@ mod iroh {

use anyhow::Result;
use derive_more::{From, TryInto};
use quic_rpc::{server::RpcChannel, RpcClient, Service, ServiceConnection, ServiceEndpoint};
use quic_rpc::{server::RpcChannel, RpcClient, Service};
use serde::{Deserialize, Serialize};

use super::{calc, clock};
Expand Down Expand Up @@ -233,38 +232,38 @@ mod iroh {
}

impl Handler {
pub async fn handle_rpc_request<S, E>(
pub async fn handle_rpc_request(
self,
req: Request,
chan: RpcChannel<IrohService, E, S>,
) -> Result<()>
where
S: Service,
E: ServiceEndpoint<S>,
{
chan: RpcChannel<IrohService>,
) -> Result<()> {
match req {
Request::Calc(req) => self.calc.handle_rpc_request(req, chan.map()).await?,
Request::Clock(req) => self.clock.handle_rpc_request(req, chan.map()).await?,
Request::Calc(req) => {
self.calc
.handle_rpc_request(req, chan.map().boxed())
.await?
}
Request::Clock(req) => {
self.clock
.handle_rpc_request(req, chan.map().boxed())
.await?
}
}
Ok(())
}
}

#[derive(Debug, Clone)]
pub struct Client<S, C> {
pub calc: calc::Client<S, C>,
pub clock: clock::Client<S, C>,
pub struct Client {
pub calc: calc::Client,
pub clock: clock::Client,
}

impl<S, C> Client<S, C>
where
S: Service,
C: ServiceConnection<S>,
{
pub fn new(client: RpcClient<IrohService, C, S>) -> Self {
impl Client {
pub fn new(client: RpcClient<IrohService>) -> Self {
Self {
calc: calc::Client::new(client.clone().map()),
clock: clock::Client::new(client.clone().map()),
calc: calc::Client::new(client.clone().map().boxed()),
clock: clock::Client::new(client.clone().map().boxed()),
}
}
}
Expand All @@ -280,7 +279,7 @@ mod calc {
use quic_rpc::{
message::{ClientStreaming, ClientStreamingMsg, Msg, RpcMsg},
server::RpcChannel,
RpcClient, Service, ServiceConnection, ServiceEndpoint,
RpcClient, Service,
};
use serde::{Deserialize, Serialize};
use std::fmt::Debug;
Expand Down Expand Up @@ -337,15 +336,11 @@ mod calc {
pub struct Handler;

impl Handler {
pub async fn handle_rpc_request<S, E>(
pub async fn handle_rpc_request(
self,
req: Request,
chan: RpcChannel<CalcService, E, S>,
) -> Result<()>
where
S: Service,
E: ServiceEndpoint<S>,
{
chan: RpcChannel<CalcService>,
) -> Result<()> {
match req {
Request::Add(req) => chan.rpc(req, self, Self::on_add).await?,
Request::Sum(req) => chan.client_streaming(req, self, Self::on_sum).await?,
Expand Down Expand Up @@ -373,16 +368,12 @@ mod calc {
}

#[derive(Debug, Clone)]
pub struct Client<S, C> {
client: RpcClient<CalcService, C, S>,
pub struct Client {
client: RpcClient<CalcService>,
}

impl<S, C> Client<S, C>
where
C: ServiceConnection<S>,
S: Service,
{
pub fn new(client: RpcClient<CalcService, C, S>) -> Self {
impl Client {
pub fn new(client: RpcClient<CalcService>) -> Self {
Self { client }
}
pub async fn add(&self, a: i64, b: i64) -> anyhow::Result<i64> {
Expand All @@ -403,7 +394,7 @@ mod clock {
use quic_rpc::{
message::{Msg, ServerStreaming, ServerStreamingMsg},
server::RpcChannel,
RpcClient, Service, ServiceConnection, ServiceEndpoint,
RpcClient, Service,
};
use serde::{Deserialize, Serialize};
use std::{
Expand Down Expand Up @@ -475,15 +466,11 @@ mod clock {
h
}

pub async fn handle_rpc_request<S, E>(
pub async fn handle_rpc_request(
self,
req: Request,
chan: RpcChannel<ClockService, E, S>,
) -> Result<()>
where
S: Service,
E: ServiceEndpoint<S>,
{
chan: RpcChannel<ClockService>,
) -> Result<()> {
match req {
Request::Tick(req) => chan.server_streaming(req, self, Self::on_tick).await?,
}
Expand Down Expand Up @@ -517,16 +504,12 @@ mod clock {
}

#[derive(Debug, Clone)]
pub struct Client<S, C> {
client: RpcClient<ClockService, C, S>,
pub struct Client {
client: RpcClient<ClockService>,
}

impl<S, C> Client<S, C>
where
C: ServiceConnection<S>,
S: Service,
{
pub fn new(client: RpcClient<ClockService, C, S>) -> Self {
impl Client {
pub fn new(client: RpcClient<ClockService>) -> Self {
Self { client }
}
pub async fn tick(&self) -> Result<BoxStream<Result<usize>>> {
Expand Down
4 changes: 2 additions & 2 deletions examples/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ async fn main() -> anyhow::Result<()> {
}
}

let (server, client) = flume::service_connection::<StoreService>(1);
let (server, client) = flume::connection(1);
let client = RpcClient::<StoreService, _>::new(client);
let server = RpcServer::<StoreService, _>::new(server);
let server_handle = tokio::task::spawn(server_future(server));
Expand Down Expand Up @@ -237,7 +237,7 @@ async fn _main_unsugared() -> anyhow::Result<()> {
type Req = u64;
type Res = String;
}
let (server, client) = flume::service_connection::<Service>(1);
let (server, client) = flume::connection::<u64, String>(1);
let to_string_service = tokio::spawn(async move {
let (mut send, mut recv) = server.accept().await?;
while let Some(item) = recv.next().await {
Expand Down
Loading
Loading