-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from ourzora/relay-and-dht-improvements
Relay and dht improvements
- Loading branch information
Showing
7 changed files
with
198 additions
and
119 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,26 @@ | ||
use libp2p::multiaddr::Protocol; | ||
use libp2p::PeerId; | ||
|
||
pub trait MultiaddrExt { | ||
// get the last peer id from this address | ||
fn peer_id(&self) -> Option<PeerId>; | ||
|
||
fn is_relayed(&self) -> bool; | ||
} | ||
|
||
impl MultiaddrExt for libp2p::Multiaddr { | ||
fn peer_id(&self) -> Option<PeerId> { | ||
let mut last = None; | ||
self.iter().for_each(|component| { | ||
if let Protocol::P2p(key) = component { | ||
last = Some(key.clone()); | ||
} | ||
}); | ||
|
||
last | ||
} | ||
|
||
fn is_relayed(&self) -> bool { | ||
self.iter().any(|addr| matches!(addr, Protocol::P2pCircuit)) | ||
} | ||
} |
Oops, something went wrong.