forked from spacedriveapp/spacedrive
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip: rspc over p2p * wip * rspc over P2P * Cleanup + error handling * slight cleanup * Using Hyper for HTTP streaming + websockets
- Loading branch information
1 parent
f7a7b00
commit aa0b4ab
Showing
16 changed files
with
258 additions
and
18 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
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 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 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 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,6 +1,8 @@ | ||
pub mod ping; | ||
pub mod request_file; | ||
pub mod rspc; | ||
pub mod spacedrop; | ||
|
||
pub use request_file::request_file; | ||
pub use rspc::remote_rspc; | ||
pub use spacedrop::spacedrop; |
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,53 @@ | ||
use std::{error::Error, sync::Arc}; | ||
|
||
use axum::{body::Body, http, Router}; | ||
use hyper::{server::conn::Http, Response}; | ||
use sd_p2p2::{RemoteIdentity, UnicastStream, P2P}; | ||
use tokio::io::AsyncWriteExt; | ||
use tracing::debug; | ||
|
||
use crate::p2p::Header; | ||
|
||
/// Transfer an rspc query to a remote node. | ||
#[allow(unused)] | ||
pub async fn remote_rspc( | ||
p2p: Arc<P2P>, | ||
identity: RemoteIdentity, | ||
request: http::Request<axum::body::Body>, | ||
) -> Result<Response<Body>, Box<dyn Error>> { | ||
let peer = p2p | ||
.peers() | ||
.get(&identity) | ||
.ok_or("Peer not found, has it been discovered?")? | ||
.clone(); | ||
let mut stream = peer.new_stream().await?; | ||
|
||
stream.write_all(&Header::Http.to_bytes()).await?; | ||
|
||
let (mut sender, conn) = hyper::client::conn::handshake(stream).await?; | ||
tokio::task::spawn(async move { | ||
if let Err(err) = conn.await { | ||
println!("Connection error: {:?}", err); | ||
} | ||
}); | ||
|
||
sender.send_request(request).await.map_err(Into::into) | ||
} | ||
|
||
pub(crate) async fn receiver( | ||
stream: UnicastStream, | ||
service: &mut Router, | ||
) -> Result<(), Box<dyn Error>> { | ||
debug!( | ||
"Received http request from peer '{}'", | ||
stream.remote_identity(), | ||
); | ||
|
||
Http::new() | ||
.http1_only(true) | ||
.http1_keep_alive(true) | ||
.serve_connection(stream, service) | ||
.with_upgrades() | ||
.await | ||
.map_err(Into::into) | ||
} |
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 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.