Struct magic_wormhole::transit::RelayHint
source · pub struct RelayHint {
pub name: Option<String>,
pub tcp: HashSet<DirectHint>,
pub ws: HashSet<Url>,
}
Expand description
Hint describing a relay server
A server may be reachable at multiple locations. Any two must be relayable over that server, therefore a client may pick only one of these per hint.
All locations are URLs, but here they are already deconstructed and grouped by schema out of convenience.
Fields§
§name: Option<String>
Human readable name. The expectation is that when a server has multiple endpoints, the expectation is that the domain name is used as name
tcp: HashSet<DirectHint>
TCP endpoints of that relay
ws: HashSet<Url>
WebSockets endpoints of that relay
Implementations§
source§impl RelayHint
impl RelayHint
pub fn new( name: Option<String>, tcp: impl IntoIterator<Item = DirectHint>, ws: impl IntoIterator<Item = Url> ) -> Self
sourcepub fn from_urls(
name: Option<String>,
urls: impl IntoIterator<Item = Url>
) -> Result<Self, RelayHintParseError>
pub fn from_urls( name: Option<String>, urls: impl IntoIterator<Item = Url> ) -> Result<Self, RelayHintParseError>
Construct a relay hint from a list of multiple endpoints, and optionally a name.
Not all URLs are acceptable, therefore this method is fallible. Especially, TCP endpoints
must be encoded as tcp://hostname:port
. All URLs must be absolute, i.e. start with a /
.
Basic usage (default server):
use magic_wormhole::transit;
let hint =
transit::RelayHint::from_urls(None, [transit::DEFAULT_RELAY_SERVER.parse().unwrap()])
.unwrap();
Custom relay server from url with name:
use magic_wormhole::transit;
let hint = transit::RelayHint::from_urls(url.host_str().map(str::to_owned), [url]).unwrap();