-
Notifications
You must be signed in to change notification settings - Fork 9
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
10 changed files
with
349 additions
and
171 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
pub mod builders; | ||
pub mod protocol; | ||
pub mod request; | ||
pub mod response; |
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,59 @@ | ||
use std::collections::HashMap; | ||
|
||
use serde_bytes::ByteBuf; | ||
use serde_json::json; | ||
|
||
use crate::{ | ||
core::error::Error, | ||
protocol::{ | ||
api::Response as ZeroNetResponse, | ||
builders::{response::*, *}, | ||
Protocol, | ||
}, | ||
}; | ||
|
||
#[async_trait::async_trait] | ||
impl<'a> ZeroNetResponse for Protocol<'a> { | ||
async fn handshake(&mut self, id: usize) -> Result<bool, Error> { | ||
let builder = handshake(); | ||
self.0.respond(id, json!(builder.1)).await?; | ||
Ok(true) | ||
} | ||
|
||
async fn ping(&mut self, id: usize) -> Result<bool, Error> { | ||
self.0.respond(id, json!({"body":"Pong!"})).await?; | ||
Ok(true) | ||
} | ||
|
||
async fn get_file(&mut self, id: usize, body: ByteBuf) -> Result<bool, Error> { | ||
let builder = get_file(body, 0, 0); | ||
self.0.respond(id, json!(builder.1)).await?; | ||
Ok(true) | ||
} | ||
|
||
async fn stream_file(&mut self, id: usize, stream_bytes: usize) -> Result<bool, Error> { | ||
let builder = stream_file(stream_bytes); | ||
self.0.respond(id, json!(builder.1)).await?; | ||
Ok(true) | ||
} | ||
async fn list_modified( | ||
&mut self, | ||
id: usize, | ||
modified_files: HashMap<String, usize>, | ||
) -> Result<bool, Error> { | ||
let builder = list_modified(modified_files); | ||
self.0.respond(id, json!(builder.1)).await?; | ||
Ok(true) | ||
} | ||
|
||
async fn pex( | ||
&mut self, | ||
id: usize, | ||
peers: Vec<ByteBuf>, | ||
peers_onion: Vec<ByteBuf>, | ||
) -> Result<bool, Error> { | ||
let builder = pex(peers, peers_onion); | ||
self.0.respond(id, json!(builder.1)).await?; | ||
Ok(true) | ||
} | ||
} |
Oops, something went wrong.