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

Dev #5

Merged
merged 2 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 19 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Release

on:
push:
tags:
- v[0-9]+.*

jobs:
create-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- uses: katyo/publish-crates@v2
with:
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Rust
name: Build and Test

on:
push:
Expand Down
71 changes: 47 additions & 24 deletions Cargo.lock

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

15 changes: 11 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[package]
name = "jetstream"
version = "0.1.0"
version = "0.1.2"
edition = "2021"
description = "Jetstream is a RPC framework for Rust, based on the 9P protocol and QUIC."
license = "Apache-2.0"
license = "BSD-3-Clause"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
futures = "0.3.30"
p9_wire_format_derive = { path = "./third_party/p9_wire_format_derive", version = "0.2.3" }
p9 = { version = "0.2.3", path = "./third_party/rust-p9" }
jetstream_p9_wire_format_derive = { path = "./third_party/p9_wire_format_derive", version = "0.1.1" }
jetstream_p9 = { version = "0.1.1", path = "./third_party/rust-p9" }
tokio = { version = "1.35.1", features = ["full"] }
anyhow = "1.0.79"
async-trait = "0.1.77"
Expand Down Expand Up @@ -46,3 +46,10 @@ pkg-config = "0.3"
which = "6.0.0"

[dev-dependencies]

[workspace]

members = [
"third_party/rust-p9",
"third_party/p9_wire_format_derive",
]
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ Features:
- 0-RTT
- mTLS
- binary encoding

32 changes: 24 additions & 8 deletions src/async_wire_format.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use std::{
future::Future,
io::{self},
pin::Pin,
};

use p9::WireFormat;
use jetstream_p9::WireFormat;

use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};

Expand All @@ -18,12 +17,20 @@ pub trait AsyncWireFormat: std::marker::Sized {
) -> impl std::future::Future<Output = io::Result<Self>> + Send;
}

type Task = Pin<Box<dyn std::future::Future<Output = io::Result<()>> + Send>>;

/// Extension trait for asynchronous wire format encoding and decoding.
pub trait AsyncWireFormatExt
where
Self: WireFormat + Send,
{
/// Encodes the object asynchronously into the provided writer.
///
/// # Arguments
///
/// * `writer` - The writer to encode the object into.
///
/// # Returns
///
/// A future that resolves to an `io::Result<()>` indicating the success or failure of the encoding operation.
fn encode_async<W>(
self,
writer: W,
Expand All @@ -36,6 +43,15 @@ where
async { tokio::task::block_in_place(move || self.encode(&mut writer)) }
}

/// Decodes an object asynchronously from the provided reader.
///
/// # Arguments
///
/// * `reader` - The reader to decode the object from.
///
/// # Returns
///
/// A future that resolves to an `io::Result<Self>` indicating the success or failure of the decoding operation.
fn decode_async<R>(
reader: R,
) -> impl Future<Output = io::Result<Self>> + Send
Expand All @@ -48,14 +64,15 @@ where
}
}

/// Implements the `AsyncWireFormatExt` trait for types that implement the `WireFormat` trait and can be sent across threads.
impl<T: WireFormat + Send> AsyncWireFormatExt for T {}

// tests
mod tests {
use std::{pin::Pin, thread::ThreadId, time::Duration};
use std::{pin::Pin, time::Duration};

#[allow(unused_imports)]
use p9::*;
use jetstream_p9::*;
#[allow(unused_imports)]
use std::io::Cursor;

Expand All @@ -66,15 +83,14 @@ mod tests {
struct BlockingIO<T: Sized + Unpin> {
delay: Duration,
inner: T,
read_thread_id: Option<ThreadId>,
}

impl BlockingIO<tokio::io::DuplexStream> {
#[allow(dead_code)]
fn new(delay: Duration, inner: tokio::io::DuplexStream) -> Self {
Self {
delay,
inner: inner,
read_thread_id: None,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub use p9::protocol;
pub use jetstream_p9::protocol;

pub mod async_wire_format;
pub mod log;
Expand Down
2 changes: 0 additions & 2 deletions src/log.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::{io::Write, ops::Add, path::PathBuf};



use slog::{slog_o, Drain, Logger};

use termcolor::{BufferWriter, Color, ColorChoice, ColorSpec, WriteColor};
Expand Down
2 changes: 1 addition & 1 deletion src/server/ninep_2000_l.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::io;

use p9::*;
use jetstream_p9::*;

/// 9p
#[async_trait::async_trait]
Expand Down
32 changes: 31 additions & 1 deletion src/server/proxy.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{net::SocketAddr, path::Path};

use anyhow::Ok;
use p9::{Rframe, Tframe};
use jetstream_p9::{Rframe, Tframe};
use s2n_quic::{
client::{Client, Connect},
provider::tls,
Expand All @@ -12,6 +12,7 @@ use slog_scope::{debug, error};
use crate::async_wire_format::AsyncWireFormatExt;

#[derive(Debug, Clone)]
/// Represents a DialQuic struct.
pub struct DialQuic {
host: String,
port: u16,
Expand All @@ -22,6 +23,20 @@ pub struct DialQuic {
}

impl DialQuic {
/// Creates a new instance of `DialQuic`.
///
/// # Arguments
///
/// * `host` - The host to connect to.
/// * `port` - The port to connect to.
/// * `cert` - The path to the client certificate file.
/// * `key` - The path to the client private key file.
/// * `ca_cert` - The path to the CA certificate file.
/// * `hostname` - The hostname for the TLS handshake.
///
/// # Returns
///
/// A new instance of `DialQuic`.
pub fn new(
host: String,
port: u16,
Expand All @@ -41,6 +56,21 @@ impl DialQuic {
}
}

/// Establishes a QUIC connection with the specified server.
///
/// This function dials a QUIC connection using the provided certificates and keys.
/// It creates a TLS client with the given CA certificate, client certificate, and client key.
/// The connection is established with the specified server address and hostname.
/// The connection is configured to keep alive and not time out due to inactivity.
///
/// # Arguments
///
/// - `self`: The `DialQuic` instance.
///
/// # Returns
///
/// Returns a `Result` containing the established `s2n_quic::Connection` if successful,
/// or an `anyhow::Error` if an error occurs during the connection establishment.
impl DialQuic {
async fn dial(self) -> anyhow::Result<s2n_quic::Connection> {
let ca_cert = self.ca_cert.to_str().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/server/server_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod tests {
},
service::ninepecho::{self, EchoService},
};
use p9::{Rframe, Tframe, Tmessage, Tversion};
use jetstream_p9::{Rframe, Tframe, Tmessage, Tversion};
use s2n_quic::{provider::tls, Server};
use slog_scope::debug;
use std::{
Expand Down
12 changes: 4 additions & 8 deletions src/server/ufs.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
use std::{
collections::{btree_map},
path::{PathBuf},
};

use p9::{server::Server, Rframe, Tframe};
use std::{collections::btree_map, path::PathBuf};

use jetstream_p9::{server::Server, Rframe, Tframe};

use crate::{service::JetStreamService, service::Message};

Expand Down Expand Up @@ -64,12 +60,12 @@ impl Message for Rframe {}
impl JetStreamService<Tframe, Rframe> for Handler {
fn call(
&mut self,
req: p9::Tframe,
req: Tframe,
) -> std::pin::Pin<
Box<
dyn futures::prelude::Future<
Output = Result<
p9::Rframe,
Rframe,
Box<dyn std::error::Error + Send + Sync>,
>,
> + Send,
Expand Down
2 changes: 1 addition & 1 deletion src/server/x509_fs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::io;

use p9::messages::*;
use jetstream_p9::messages::*;

use crate::server::ninep_2000_l::NineP200L;

Expand Down
Loading
Loading