-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
8 changed files
with
281 additions
and
81 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//! Error variants used to unify different connection streams | ||
|
||
/// An error that can occur when reading an incoming request | ||
#[derive(Debug, thiserror::Error)] | ||
pub enum RequestError { | ||
#[error(transparent)] | ||
Axum(#[from] axum::Error), | ||
#[error(transparent)] | ||
Serde(#[from] serde_json::Error), | ||
#[error(transparent)] | ||
Io(#[from] std::io::Error), | ||
#[error("Disconnect")] | ||
Disconnect, | ||
} |
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,14 +1,53 @@ | ||
//! IPC handling | ||
|
||
use crate::PubSubRpcHandler; | ||
use anvil_rpc::{request::Request, response::Response}; | ||
use futures::stream::StreamExt; | ||
use parity_tokio_ipc::Endpoint; | ||
use tokio_serde::{formats::Json, Framed}; | ||
use tracing::{error, trace}; | ||
use crate::pubsub::PubSubConnection; | ||
|
||
/// An IPC connection for anvil | ||
pub struct IpcEndpoint<Handler: PubSubRpcHandler> { | ||
/// | ||
/// A Future that listens for incoming connections and spawns new connections | ||
pub struct IpcEndpoint<Handler> { | ||
/// the handler for the websocket connection | ||
handler: Handler, | ||
/// The endpoint we listen for incoming transactions | ||
endpoint: Endpoint, | ||
// TODO add shutdown | ||
} | ||
|
||
async fn on_connection() {} | ||
impl<Handler: PubSubRpcHandler> IpcEndpoint<Handler> { | ||
/// Creates a new endpoint with the given handler | ||
pub fn new(handler: Handler, endpoint: Endpoint) -> Self { | ||
Self { handler, endpoint } | ||
} | ||
|
||
/// Start listening for incoming connections | ||
pub async fn start(self) { | ||
let IpcEndpoint { handler, endpoint } = self; | ||
trace!(target: "ipc", endpoint=?endpoint.path(), "starting ipc server" ); | ||
|
||
let mut connections = match endpoint.incoming() { | ||
Ok(connections) => connections, | ||
Err(err) => { | ||
error!(target: "ipc", ?err, "Failed to create ipc listener"); | ||
return | ||
} | ||
}; | ||
|
||
while let Some(Ok(stream)) = connections.next().await { | ||
trace!(target: "ipc", "successful incoming IPC connection"); | ||
|
||
let framed: Framed<_, Request, Response, _> = | ||
Framed::new(stream, Json::<Request, Response>::default()); | ||
|
||
// TOOD need to convert the stream into a Sink+Stream | ||
|
||
// PubSubConnection::new(framed, handler.clone()).await | ||
|
||
} | ||
} | ||
} |
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
Oops, something went wrong.