-
-
Notifications
You must be signed in to change notification settings - Fork 563
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rust): add
UDP
support to nodes and multiaddr. refactor multiaddr
- Loading branch information
1 parent
d1124b2
commit 6aa2b30
Showing
46 changed files
with
1,016 additions
and
537 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
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
61 changes: 61 additions & 0 deletions
61
implementations/rust/ockam/ockam_api/src/multiaddr_resolver/local_resolver.rs
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,61 @@ | ||
use crate::multiaddr_resolver::invalid_multiaddr_error; | ||
use ockam_core::errcode::{Kind, Origin}; | ||
use ockam_core::{Address, Error, Result, Route, LOCAL}; | ||
use ockam_multiaddr::proto::{DnsAddr, Ip4, Ip6, Node, Secure, Service, Worker}; | ||
use ockam_multiaddr::{MultiAddr, Protocol}; | ||
|
||
pub struct LocalMultiaddrResolver {} | ||
|
||
impl LocalMultiaddrResolver { | ||
/// Try to convert a local multi-address to an Ockam route. | ||
pub fn resolve(ma: &MultiAddr) -> Result<Route> { | ||
let mut rb = Route::new(); | ||
for p in ma.iter() { | ||
match p.code() { | ||
// Only hops that are directly translated to existing workers are allowed here | ||
Worker::CODE => { | ||
let local = p | ||
.cast::<Worker>() | ||
.ok_or_else(|| invalid_multiaddr_error(ma))?; | ||
rb = rb.append(Address::new_with_string(LOCAL, &*local)) | ||
} | ||
Service::CODE => { | ||
let local = p | ||
.cast::<Service>() | ||
.ok_or_else(|| invalid_multiaddr_error(ma))?; | ||
rb = rb.append(Address::new_with_string(LOCAL, &*local)) | ||
} | ||
Secure::CODE => { | ||
let local = p | ||
.cast::<Secure>() | ||
.ok_or_else(|| invalid_multiaddr_error(ma))?; | ||
rb = rb.append(Address::new_with_string(LOCAL, &*local)) | ||
} | ||
|
||
Node::CODE => { | ||
return Err(Error::new( | ||
Origin::Api, | ||
Kind::Invalid, | ||
"unexpected code: node. clean_multiaddr should have been called", | ||
)); | ||
} | ||
|
||
code @ (Ip4::CODE | Ip6::CODE | DnsAddr::CODE) => { | ||
return Err(Error::new( | ||
Origin::Api, | ||
Kind::Invalid, | ||
format!( | ||
"unexpected code: {code}. The address must be a local address {ma}" | ||
), | ||
)); | ||
} | ||
|
||
_ => { | ||
return Err(invalid_multiaddr_error(ma)); | ||
} | ||
} | ||
} | ||
|
||
Ok(rb.into()) | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
implementations/rust/ockam/ockam_api/src/multiaddr_resolver/mod.rs
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,28 @@ | ||
mod local_resolver; | ||
mod remote_resolver; | ||
mod reverse_local_converter; | ||
mod transport_route_resolver; | ||
|
||
pub use local_resolver::*; | ||
use ockam_core::errcode::{Kind, Origin}; | ||
use ockam_core::Error; | ||
use ockam_multiaddr::MultiAddr; | ||
pub use remote_resolver::*; | ||
pub use reverse_local_converter::*; | ||
pub use transport_route_resolver::*; | ||
|
||
fn invalid_multiaddr_error(ma: &MultiAddr) -> Error { | ||
Error::new( | ||
Origin::Api, | ||
Kind::Misuse, | ||
format!("Invalid multiaddr {}", ma), | ||
) | ||
} | ||
|
||
fn multiple_transport_hops_error(ma: &MultiAddr) -> Error { | ||
Error::new( | ||
Origin::Api, | ||
Kind::Unsupported, | ||
format!("Only one hop is allowed in a multiaddr. Multiaddr={}", ma), | ||
) | ||
} |
Oops, something went wrong.