-
Notifications
You must be signed in to change notification settings - Fork 38
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
Implement constructor, initial bootstrap, and tests, for PropagationNetwork
.
#41
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
c7e4ef2
refactor: use `tokio::broadcast` for message queue
f2koi 20329f4
feat: add default constructor for `Behaviour`
f2koi 0cd133e
feat: setup constructor for `PropagationNetwork`
f2koi 814d27b
feat: add methods to get peers and listeners
f2koi d81293c
docs: remove redundant argument
f2koi 19dc0dd
test: make all tests asynchronous
f2koi f79bd37
test: add unit tests for initial bootstrap
f2koi bf7bcab
refactor: derive `Debug` for network events
f2koi 4ea1ffc
feat: implement initial bootstrap
f2koi 62d3189
test: activate tests for initial bootstrap
f2koi f4d7fd5
feat: add network configuration interface
f2koi 4838485
test: add unit tests for initial bootstrap
f2koi da0426e
feat: retry initial bootstrap if failed
f2koi 955ad28
test: assign possibly available ports when testing
f2koi 512c28e
test: activate tests for initial bootstrap
f2koi 61c13a8
refactor: split constructor
f2koi 6631a69
refactor: split background task
junha1 5e813cd
docs: restyle comments and error messages
f2koi b5a6d48
refactor: reduce port range
f2koi ef79b88
refactor: change location of test helpers
f2koi cb1bdde
refactor: implement `Default` trait
f2koi 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
use std::{ | ||
default::Default, | ||
net::{Ipv4Addr, SocketAddrV4}, | ||
time::Duration, | ||
}; | ||
|
||
use libp2p::{multiaddr::Protocol, Multiaddr}; | ||
|
||
/// A set of configurations of [`PropagationNetwork`]. | ||
/// | ||
/// To customize it, call `default` and chain the methods named like `with_<fieldname>`. | ||
pub struct PropagationNetworkConfig { | ||
/// The addresses to listen on to handle incoming connection requests. | ||
pub(crate) listen_address: Multiaddr, | ||
/// The timeout parameter for listener creation. | ||
pub(crate) listener_creation_timeout: Duration, | ||
/// The timeout parameter for initial bootstrap. | ||
pub(crate) initial_bootstrap_timeout: Duration, | ||
/// The interval for the guaranteed lock aquisition for swarm. | ||
/// | ||
/// It is the maximal delay until the [`PropagationNetwork`] aquires | ||
/// all of the resources needed to serve a job assigned from its public interface. | ||
pub(crate) lock_release_interval: Duration, | ||
/// The interval for the regular peer discovery routine. | ||
pub(crate) peer_discovery_interval: Duration, | ||
/// The capacity for the message queue that passes messages from other nodes | ||
/// to its simperby node. | ||
pub(crate) message_queue_capacity: usize, | ||
} | ||
|
||
impl Default for PropagationNetworkConfig { | ||
fn default() -> Self { | ||
Self { | ||
listen_address: Self::convert_socketaddr_to_multiaddr(SocketAddrV4::new( | ||
Ipv4Addr::new(0, 0, 0, 0), | ||
0, | ||
)), | ||
listener_creation_timeout: Duration::from_millis(1000), | ||
initial_bootstrap_timeout: Duration::from_millis(3000), | ||
lock_release_interval: Duration::from_millis(30), | ||
peer_discovery_interval: Duration::from_millis(10000), | ||
message_queue_capacity: 100, | ||
} | ||
} | ||
} | ||
|
||
impl PropagationNetworkConfig { | ||
pub fn with_listen_address(&mut self, listen_address: SocketAddrV4) -> &mut Self { | ||
self.listen_address = Self::convert_socketaddr_to_multiaddr(listen_address); | ||
self | ||
} | ||
|
||
pub fn with_listener_creation_timeout( | ||
&mut self, | ||
listener_creation_timeout: Duration, | ||
) -> &mut Self { | ||
self.listener_creation_timeout = listener_creation_timeout; | ||
self | ||
} | ||
|
||
pub fn with_initial_bootstrap_timeout( | ||
&mut self, | ||
initial_bootstrap_timeout: Duration, | ||
) -> &mut Self { | ||
self.initial_bootstrap_timeout = initial_bootstrap_timeout; | ||
self | ||
} | ||
|
||
pub fn with_peer_discovery_interval(&mut self, peer_discovery_interval: Duration) -> &mut Self { | ||
self.peer_discovery_interval = peer_discovery_interval; | ||
self | ||
} | ||
|
||
pub fn with_message_queue_capacity(&mut self, message_queue_capacity: usize) -> &mut Self { | ||
self.message_queue_capacity = message_queue_capacity; | ||
self | ||
} | ||
|
||
fn convert_socketaddr_to_multiaddr(socket_addr: SocketAddrV4) -> Multiaddr { | ||
Multiaddr::from_iter([ | ||
Protocol::Ip4(*socket_addr.ip()), | ||
Protocol::Tcp(socket_addr.port()), | ||
]) | ||
} | ||
} |
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.
It is common to refer struct fields with
The
in the doc comments.(e.g.,
The addresses to ..
)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.
Applied it to all structs.