-
Notifications
You must be signed in to change notification settings - Fork 159
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 Kademlia discovery #501
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2566837
wip kademlia impl
austinabell 4d074b5
Merge branch 'master' of github.com:ChainSafe/forest into austin/kad
austinabell 9e29770
Refactor RPC
austinabell 509da5f
Setup kademlia and refactor libp2p crate
austinabell 57ddc29
cleanup
austinabell 5b33646
Merge branch 'master' of github.com:ChainSafe/forest into austin/kad
austinabell 44b4641
Cleanup auxiliary things
austinabell 76ea847
Add interval timer for logging peer count
austinabell 128fb03
Merge branch 'master' into austin/kad
austinabell 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
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,37 +1,40 @@ | ||
// Copyright 2020 ChainSafe Systems | ||
// SPDX-License-Identifier: Apache-2.0, MIT | ||
|
||
use libp2p::gossipsub::Topic; | ||
use libp2p::Multiaddr; | ||
use serde::Deserialize; | ||
|
||
const DEFAULT_BOOTSTRAP: &[&str] = &[ | ||
"/dns4/bootstrap-0-sin.fil-test.net/tcp/1347/p2p/12D3KooWKNF7vNFEhnvB45E9mw2B5z6t419W3ziZPLdUDVnLLKGs", | ||
"/ip4/86.109.15.57/tcp/1347/p2p/12D3KooWKNF7vNFEhnvB45E9mw2B5z6t419W3ziZPLdUDVnLLKGs", | ||
"/dns4/bootstrap-0-dfw.fil-test.net/tcp/1347/p2p/12D3KooWECJTm7RUPyGfNbRwm6y2fK4wA7EB8rDJtWsq5AKi7iDr", | ||
"/ip4/139.178.84.45/tcp/1347/p2p/12D3KooWECJTm7RUPyGfNbRwm6y2fK4wA7EB8rDJtWsq5AKi7iDr", | ||
"/dns4/bootstrap-0-fra.fil-test.net/tcp/1347/p2p/12D3KooWC7MD6m7iNCuDsYtNr7xVtazihyVUizBbhmhEiyMAm9ym", | ||
"/ip4/136.144.49.17/tcp/1347/p2p/12D3KooWC7MD6m7iNCuDsYtNr7xVtazihyVUizBbhmhEiyMAm9ym", | ||
"/dns4/bootstrap-1-sin.fil-test.net/tcp/1347/p2p/12D3KooWD8eYqsKcEMFax6EbWN3rjA7qFsxCez2rmN8dWqkzgNaN", | ||
"/ip4/86.109.15.55/tcp/1347/p2p/12D3KooWD8eYqsKcEMFax6EbWN3rjA7qFsxCez2rmN8dWqkzgNaN", | ||
"/dns4/bootstrap-1-dfw.fil-test.net/tcp/1347/p2p/12D3KooWLB3RR8frLAmaK4ntHC2dwrAjyGzQgyUzWxAum1FxyyqD", | ||
"/ip4/139.178.84.41/tcp/1347/p2p/12D3KooWLB3RR8frLAmaK4ntHC2dwrAjyGzQgyUzWxAum1FxyyqD", | ||
"/dns4/bootstrap-1-fra.fil-test.net/tcp/1347/p2p/12D3KooWGPDJAw3HW4uVU3JEQBfFaZ1kdpg4HvvwRMVpUYbzhsLQ", | ||
"/ip4/136.144.49.131/tcp/1347/p2p/12D3KooWGPDJAw3HW4uVU3JEQBfFaZ1kdpg4HvvwRMVpUYbzhsLQ", | ||
]; | ||
|
||
#[derive(Debug, Deserialize)] | ||
#[serde(default)] | ||
pub struct Libp2pConfig { | ||
pub listening_multiaddr: String, | ||
pub bootstrap_peers: Vec<String>, | ||
#[serde(skip_deserializing)] // Always use default | ||
pub pubsub_topics: Vec<Topic>, | ||
} | ||
|
||
impl Libp2pConfig { | ||
/// Sets the pubsub topics to the network name provided | ||
pub fn set_network_name(&mut self, s: &str) { | ||
self.pubsub_topics = vec![ | ||
Topic::new(format!("/fil/blocks/{}", s)), | ||
Topic::new(format!("/fil/msgs/{}", s)), | ||
] | ||
} | ||
pub listening_multiaddr: Multiaddr, | ||
pub bootstrap_peers: Vec<Multiaddr>, | ||
} | ||
|
||
impl Default for Libp2pConfig { | ||
fn default() -> Self { | ||
Libp2pConfig { | ||
listening_multiaddr: "/ip4/0.0.0.0/tcp/0".to_owned(), | ||
pubsub_topics: vec![ | ||
Topic::new("/fil/blocks/interop".to_owned()), | ||
Topic::new("/fil/msgs/interop".to_owned()), | ||
], | ||
bootstrap_peers: vec![], | ||
let bootstrap_peers = DEFAULT_BOOTSTRAP | ||
.iter() | ||
.map(|node| node.parse().unwrap()) | ||
.collect(); | ||
Self { | ||
listening_multiaddr: "/ip4/0.0.0.0/tcp/0".parse().unwrap(), | ||
bootstrap_peers, | ||
} | ||
} | ||
} |
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.
If this can't find a peer, it will loop indefinitely, is it worth it to have a time out mechanism?
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.
Or maybe implement a try_get_peer() that takes in a timeout variable as well?
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.
Somewhat intentional, because it can't do anything else until it has a peer to sync with. The logic hasn't changed, I just put in a function because there was another place it should be used.
The logic is definitely a bit broken now after the logic had been refactored since this was setup, but I don't want to cause conflicts with the work Erlich is doing in a bit. This shouldn't be an issue once the syncing setup is improved, but maybe something to keep in mind @ec2
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.
But yeah, definitely agree a timeout is worthwhile to have, just probably after the setup is refactored (unless you guys think otherwise)
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.
That is totally fine to me!