-
Notifications
You must be signed in to change notification settings - Fork 132
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 #2210 from input-output-hk/jormungandr-lib-to_sock…
…etaddr implement to_socketaddr in jormungandr-lib
- Loading branch information
Showing
12 changed files
with
79 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ extern crate quickcheck; | |
|
||
pub mod crypto; | ||
pub mod interfaces; | ||
pub mod multiaddr; | ||
pub mod time; |
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,24 @@ | ||
use multiaddr::{AddrComponent, Multiaddr}; | ||
use std::net::{SocketAddr, SocketAddrV4, SocketAddrV6}; | ||
|
||
pub fn multiaddr_to_socket_addr(addr: &Multiaddr) -> Option<SocketAddr> { | ||
let mut components = addr.iter(); | ||
|
||
match components.next()? { | ||
AddrComponent::IP4(ipv4) => { | ||
if let AddrComponent::TCP(port) = components.next()? { | ||
Some(SocketAddr::V4(SocketAddrV4::new(ipv4, port))) | ||
} else { | ||
None | ||
} | ||
} | ||
AddrComponent::IP6(ipv6) => { | ||
if let AddrComponent::TCP(port) = components.next()? { | ||
Some(SocketAddr::V6(SocketAddrV6::new(ipv6, port, 0, 0))) | ||
} else { | ||
None | ||
} | ||
} | ||
_ => None, | ||
} | ||
} |
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
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