This repository has been archived by the owner on Nov 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Avoid broadcasting transactions to peers that send them #3796
Merged
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e1ade5b
Maintaining a list of transactions propagated from other peers
704054e
Merge branch 'master' into tx-broadcast
e66157f
fixing test
aaf6da4
Returning persistent node id
19ca9ad
Prevent broadcasting transactions to peer that send them.
b5020d3
Fixing Light context API
1e86386
fixing tests
b56f12a
Merge branch 'master' into tx-broadcast
83d9bc1
Fixing test
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,13 +16,13 @@ | |
|
||
//! I/O and event context generalizations. | ||
|
||
use network::{NetworkContext, PeerId}; | ||
use network::{NetworkContext, PeerId, NodeId}; | ||
|
||
use super::{Announcement, LightProtocol, ReqId}; | ||
use super::error::Error; | ||
use request::Request; | ||
|
||
/// An I/O context which allows sending and receiving packets as well as | ||
/// An I/O context which allows sending and receiving packets as well as | ||
/// disconnecting peers. This is used as a generalization of the portions | ||
/// of a p2p network which the light protocol structure makes use of. | ||
pub trait IoContext { | ||
|
@@ -41,6 +41,9 @@ pub trait IoContext { | |
|
||
/// Get a peer's protocol version. | ||
fn protocol_version(&self, peer: PeerId) -> Option<u8>; | ||
|
||
/// Persistent peer id | ||
fn persistent_peer_id(&self, peer: PeerId) -> Option<NodeId>; | ||
} | ||
|
||
impl<'a> IoContext for NetworkContext<'a> { | ||
|
@@ -67,6 +70,10 @@ impl<'a> IoContext for NetworkContext<'a> { | |
fn protocol_version(&self, peer: PeerId) -> Option<u8> { | ||
self.protocol_version(self.subprotocol_name(), peer) | ||
} | ||
|
||
fn persistent_peer_id(&self, peer: PeerId) -> Option<NodeId> { | ||
self.session_info(peer).and_then(|info| info.id) | ||
} | ||
} | ||
|
||
/// Context for a protocol event. | ||
|
@@ -75,6 +82,9 @@ pub trait EventContext { | |
/// disconnected/connected peer. | ||
fn peer(&self) -> PeerId; | ||
|
||
/// Returns the relevant's peer persistent Id (aka NodeId). | ||
fn persistent_peer_id(&self) -> Option<NodeId>; | ||
|
||
/// Make a request from a peer. | ||
fn request_from(&self, peer: PeerId, request: Request) -> Result<ReqId, Error>; | ||
|
||
|
@@ -89,19 +99,26 @@ pub trait EventContext { | |
fn disable_peer(&self, peer: PeerId); | ||
} | ||
|
||
/// Concrete implementation of `EventContext` over the light protocol struct and | ||
/// Concrete implementation of `EventContext` over the light protocol struct and | ||
/// an io context. | ||
pub struct Ctx<'a> { | ||
/// Io context to enable immediate response to events. | ||
pub io: &'a IoContext, | ||
/// Protocol implementation. | ||
pub proto: &'a LightProtocol, | ||
/// Relevant peer for event. | ||
pub peer: PeerId, | ||
pub peer: PeerId, | ||
} | ||
|
||
impl<'a> EventContext for Ctx<'a> { | ||
fn peer(&self) -> PeerId { self.peer } | ||
|
||
fn peer(&self) -> PeerId { | ||
self.peer | ||
} | ||
|
||
fn persistent_peer_id(&self) -> Option<NodeId> { | ||
self.io.persistent_peer_id(self.peer) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indentation looks strange around this block. Does the file use spaces? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry, this is my mistake from earlier. Fixed in #3801 |
||
fn request_from(&self, peer: PeerId, request: Request) -> Result<ReqId, Error> { | ||
self.proto.request_from(self.io, &peer, request) | ||
} | ||
|
@@ -117,4 +134,4 @@ impl<'a> EventContext for Ctx<'a> { | |
fn disable_peer(&self, peer: PeerId) { | ||
self.io.disable_peer(peer); | ||
} | ||
} | ||
} |
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.
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.
would prefer for this to take arbitrary
&PeerId
ideally.