-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use
NetworkAddresses
to represent regular_addrs and onion_addrs
Signed-off-by: Eval EXEC <[email protected]>
- Loading branch information
Showing
3 changed files
with
43 additions
and
2 deletions.
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use p2p::multiaddr::{MultiAddr, Protocol}; | ||
|
||
pub struct NetworkAddresses { | ||
pub regular_addresses: Vec<MultiAddr>, | ||
|
||
// onion addresses can't be solved by multiaddr_to_socketaddr or socketaddr_to_multiaddr | ||
pub onion_addresses: Vec<MultiAddr>, | ||
} | ||
|
||
// convert Vec<MultiAddr> to NetworkAddresses | ||
impl From<Vec<MultiAddr>> for NetworkAddresses { | ||
fn from(addresses: Vec<MultiAddr>) -> Self { | ||
let mut regular_addresses = Vec::new(); | ||
let mut onion_addresses = Vec::new(); | ||
for address in addresses { | ||
if address | ||
.iter() | ||
.any(|proto| matches!(proto, Protocol::Onion(_))) | ||
{ | ||
onion_addresses.push(address); | ||
} else { | ||
regular_addresses.push(address); | ||
} | ||
} | ||
NetworkAddresses { | ||
regular_addresses, | ||
onion_addresses, | ||
} | ||
} | ||
} | ||
|
||
// convert NetworkAddresses to Vec<MultiAddr> | ||
impl From<NetworkAddresses> for Vec<MultiAddr> { | ||
fn from(addresses: NetworkAddresses) -> Self { | ||
let mut result = addresses.regular_addresses; | ||
result.extend(addresses.onion_addresses); | ||
result | ||
} | ||
} |
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