-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
295 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,7 @@ | ||
use std::sync::Arc; | ||
//! In this file we define network abstractions, which can be implemented | ||
//! for any network protocol. | ||
use async_trait::async_trait; | ||
|
||
use crate::{error::Result, message::Message}; | ||
|
||
pub mod fallible; | ||
pub mod flow; | ||
pub mod protocols; | ||
pub mod sticky; | ||
|
||
#[async_trait] | ||
pub trait Connection: Send + Sync { | ||
/// Receive a single message from the connection. | ||
/// | ||
/// # Errors | ||
/// Errors if we either fail to receive the message. This usually means a connection problem. | ||
async fn recv_message(&self) -> Result<Message>; | ||
|
||
/// Send a single message over the connection. | ||
/// | ||
/// # Errors | ||
/// Errors if we fail to deliver the message. This usually means a connection problem. | ||
async fn send_message(&self, message: Arc<Message>) -> Result<()>; | ||
|
||
/// Connect to a remote address, returning an instance of `Self`. | ||
/// | ||
/// # Errors | ||
/// Errors if we fail to connect or if we fail to bind to the interface we want. | ||
async fn connect(remote_endpoint: String) -> Result<Self> | ||
where | ||
Self: Sized; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
//! This module defines connections, listeners, and their implementations. | ||
use std::{net::SocketAddr, sync::Arc}; | ||
|
||
use async_trait::async_trait; | ||
|
||
use crate::{error::Result, message::Message}; | ||
pub mod quic; | ||
pub mod tcp; | ||
|
||
/// Assert that we are at _least_ running on a 64-bit system | ||
/// TODO: find out if there is a better way than the `u64` cast | ||
const _: [(); 0 - (!(usize::BITS >= u64::BITS)) as usize] = []; | ||
|
||
|
||
pub trait Protocol: Send + Sync { | ||
type Connection: Connection; | ||
type Listener: Listener<Self::Connection>; | ||
} | ||
|
||
#[async_trait] | ||
pub trait Connection: Send + Sync { | ||
/// Receive a single message from the connection. | ||
/// | ||
/// # Errors | ||
/// Errors if we either fail to receive the message. This usually means a connection problem. | ||
async fn recv_message(&self) -> Result<Message>; | ||
|
||
/// Send a single message over the connection. | ||
/// | ||
/// # Errors | ||
/// Errors if we fail to deliver the message. This usually means a connection problem. | ||
async fn send_message(&self, message: Arc<Message>) -> Result<()>; | ||
|
||
/// Connect to a remote address, returning an instance of `Self`. | ||
/// | ||
/// # Errors | ||
/// Errors if we fail to connect or if we fail to bind to the interface we want. | ||
async fn connect(remote_endpoint: String) -> Result<Self> | ||
where | ||
Self: Sized; | ||
} | ||
|
||
#[async_trait] | ||
pub trait Listener<ConnectionType: Connection>: Send + Sync { | ||
/// Bind to the local address, returning an instance of `Self`. | ||
/// | ||
/// # Errors | ||
/// If we fail to bind to the given socket address | ||
async fn bind( | ||
bind_address: SocketAddr, | ||
maybe_tls_cert_path: Option<String>, | ||
maybe_tls_key_path: Option<String>, | ||
) -> Result<Self> | ||
where | ||
Self: Sized; | ||
|
||
/// Accept a connection from the local, bound socket. | ||
/// Returns a connection or an error if we encountered one. | ||
/// | ||
/// # Errors | ||
/// If we fail to accept a connection | ||
async fn accept(&self) -> Result<ConnectionType>; | ||
} |
Oops, something went wrong.