-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Remove p2pservice networkcodec trait #2388
Open
acerone85
wants to merge
25
commits into
master
Choose a base branch
from
2368-remove-p2pservice-networkcodec-trait
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 21 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
b6f7353
Request/Response: remove NetworkCodec trait
acerone85 529d1d6
Dinstinguish between Format being used and Codec for requests and res…
acerone85 a4465d5
Move RequestResponse protocol definitions to dedicated module
acerone85 7b858c5
Decouple GossibSub and RequestResponse codecs
acerone85 f2cd720
Merge branch 'master' into 2368-remove-p2pservice-networkcodec-trait
acerone85 1aa98dc
Simplify DataFormat trait
acerone85 79b507d
Use Encode and Decode trait in favour of DataFormat
acerone85 ead761a
Rename codecs to message handlers
acerone85 ed29376
Format
acerone85 138716b
Encode trait function takes &self as argument
acerone85 58ffe67
Minor improvements
acerone85 c564941
Decode trait function takes &self as argument
acerone85 c5aa362
DataFormat is now Codec
acerone85 89b022c
Typo
acerone85 45bbd91
CHANGELOG
acerone85 caf4f00
Add issue to TODO
acerone85 a55f695
Rename lifetime
acerone85 fc2d71d
Formatting
acerone85 136e6b4
Placate Clippy
acerone85 5bd9e21
Merge branch 'master' into 2368-remove-p2pservice-networkcodec-trait
acerone85 029fbff
Fix test compilation
acerone85 39e1ed9
Merge branch 'master' into 2368-remove-p2pservice-networkcodec-trait
acerone85 05c50fd
Reference todo issue
acerone85 e9f1404
Avoid dereference
acerone85 b94c451
Todo: max_response_size should be u64
acerone85 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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,53 @@ | ||
use std::io; | ||
|
||
use fuel_core_types::fuel_tx::Transaction; | ||
|
||
use crate::gossipsub::messages::{ | ||
GossipTopicTag, | ||
GossipsubBroadcastRequest, | ||
GossipsubMessage, | ||
}; | ||
|
||
use super::{ | ||
Decode, | ||
Encode, | ||
Encoder, | ||
GossipsubCodec, | ||
}; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub struct GossipsubMessageHandler<Codec> { | ||
pub(crate) codec: Codec, | ||
} | ||
|
||
impl<Codec> GossipsubCodec for GossipsubMessageHandler<Codec> | ||
where | ||
Codec: Encode<Transaction, Error = io::Error> | ||
+ Decode<Transaction, Error = io::Error> | ||
+ Send, | ||
{ | ||
type RequestMessage = GossipsubBroadcastRequest; | ||
type ResponseMessage = GossipsubMessage; | ||
|
||
fn encode(&self, data: Self::RequestMessage) -> Result<Vec<u8>, io::Error> { | ||
match data { | ||
GossipsubBroadcastRequest::NewTx(tx) => { | ||
Ok(self.codec.encode(&*tx)?.as_bytes().into_owned()) | ||
} | ||
} | ||
} | ||
|
||
fn decode( | ||
&self, | ||
encoded_data: &[u8], | ||
gossipsub_tag: GossipTopicTag, | ||
) -> Result<Self::ResponseMessage, io::Error> { | ||
let decoded_response = match gossipsub_tag { | ||
GossipTopicTag::NewTx => { | ||
GossipsubMessage::NewTx(self.codec.decode(encoded_data)?) | ||
} | ||
}; | ||
|
||
Ok(decoded_response) | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: The dereference is redundant here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in e9f1404