#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum KnownRoute {
Iroh,
IrohQuic,
IrohRelay,
IrohLan,
Ble,
WebRtc,
WebRtcLan,
WebRtcTurn,
Moq,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum RouteFamily {
IrohPath,
IrohPhysical,
OptionalRoute,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum RouteImplementation {
Core,
HostInstalled,
RouteAdapter,
PathLabel,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum RouteLocality {
Nearby,
DirectInternet,
Relay,
Mixed,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum RouteMaturity {
Stable,
Experimental,
Unsupported,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize)]
#[serde(rename_all = "camelCase")]
pub struct RouteDescriptor {
#[serde(skip)]
pub route: KnownRoute,
pub id: &'static str,
pub base_protocol: &'static str,
pub family: RouteFamily,
pub implementation: RouteImplementation,
pub locality: RouteLocality,
pub maturity: RouteMaturity,
pub default_rank: u8,
pub browser: bool,
pub native: bool,
pub independently_instantiable: bool,
}
impl KnownRoute {
pub const fn as_str(self) -> &'static str {
match self {
Self::Iroh => "iroh",
Self::IrohQuic => "iroh-quic",
Self::IrohRelay => "iroh-relay",
Self::IrohLan => "iroh-lan",
Self::Ble => "ble",
Self::WebRtc => "webrtc",
Self::WebRtcLan => "webrtc-lan",
Self::WebRtcTurn => "webrtc-turn",
Self::Moq => "moq",
}
}
pub const fn default_rank(self) -> u8 {
match self {
Self::Iroh => 5,
Self::IrohQuic => 6,
Self::IrohRelay => 7,
Self::IrohLan => 0,
Self::Ble => 2,
Self::WebRtc => 3,
Self::WebRtcLan => 1,
Self::WebRtcTurn => 8,
Self::Moq => 4,
}
}
pub const fn descriptor(self) -> RouteDescriptor {
match self {
Self::Iroh => RouteDescriptor {
route: self,
id: "iroh",
base_protocol: "iroh",
family: RouteFamily::IrohPath,
implementation: RouteImplementation::Core,
locality: RouteLocality::Mixed,
maturity: RouteMaturity::Stable,
default_rank: 5,
browser: true,
native: true,
independently_instantiable: false,
},
Self::IrohQuic => RouteDescriptor {
route: self,
id: "iroh-quic",
base_protocol: "iroh",
family: RouteFamily::IrohPath,
implementation: RouteImplementation::PathLabel,
locality: RouteLocality::DirectInternet,
maturity: RouteMaturity::Stable,
default_rank: 6,
browser: false,
native: true,
independently_instantiable: false,
},
Self::IrohRelay => RouteDescriptor {
route: self,
id: "iroh-relay",
base_protocol: "iroh",
family: RouteFamily::IrohPath,
implementation: RouteImplementation::PathLabel,
locality: RouteLocality::Relay,
maturity: RouteMaturity::Stable,
default_rank: 7,
browser: true,
native: true,
independently_instantiable: false,
},
Self::IrohLan => RouteDescriptor {
route: self,
id: "iroh-lan",
base_protocol: "iroh",
family: RouteFamily::IrohPath,
implementation: RouteImplementation::PathLabel,
locality: RouteLocality::Nearby,
maturity: RouteMaturity::Stable,
default_rank: 0,
browser: false,
native: true,
independently_instantiable: false,
},
Self::Ble => RouteDescriptor {
route: self,
id: "ble",
base_protocol: "iroh",
family: RouteFamily::IrohPhysical,
implementation: RouteImplementation::HostInstalled,
locality: RouteLocality::Nearby,
maturity: RouteMaturity::Experimental,
default_rank: 2,
browser: false,
native: true,
independently_instantiable: false,
},
Self::WebRtc => RouteDescriptor {
route: self,
id: "webrtc",
base_protocol: "webrtc",
family: RouteFamily::OptionalRoute,
implementation: RouteImplementation::RouteAdapter,
locality: RouteLocality::Mixed,
maturity: RouteMaturity::Stable,
default_rank: 3,
browser: true,
native: true,
independently_instantiable: true,
},
Self::WebRtcLan => RouteDescriptor {
route: self,
id: "webrtc-lan",
base_protocol: "webrtc",
family: RouteFamily::OptionalRoute,
implementation: RouteImplementation::PathLabel,
locality: RouteLocality::Nearby,
maturity: RouteMaturity::Stable,
default_rank: 1,
browser: true,
native: true,
independently_instantiable: false,
},
Self::WebRtcTurn => RouteDescriptor {
route: self,
id: "webrtc-turn",
base_protocol: "webrtc",
family: RouteFamily::OptionalRoute,
implementation: RouteImplementation::PathLabel,
locality: RouteLocality::Relay,
maturity: RouteMaturity::Stable,
default_rank: 8,
browser: true,
native: true,
independently_instantiable: false,
},
Self::Moq => RouteDescriptor {
route: self,
id: "moq",
base_protocol: "moq",
family: RouteFamily::OptionalRoute,
implementation: RouteImplementation::RouteAdapter,
locality: RouteLocality::Relay,
maturity: RouteMaturity::Experimental,
default_rank: 4,
browser: true,
native: true,
independently_instantiable: true,
},
}
}
pub const ALL_BY_DEFAULT_RANK: [Self; 9] = [
Self::IrohLan,
Self::WebRtcLan,
Self::Ble,
Self::WebRtc,
Self::Moq,
Self::Iroh,
Self::IrohQuic,
Self::IrohRelay,
Self::WebRtcTurn,
];
pub const DEFAULT_PRIORITY: [Self; 6] = [
Self::IrohLan,
Self::WebRtcLan,
Self::Ble,
Self::WebRtc,
Self::Moq,
Self::Iroh,
];
}
pub const KNOWN_ROUTE_DESCRIPTORS: [RouteDescriptor; 9] = [
KnownRoute::IrohLan.descriptor(),
KnownRoute::WebRtcLan.descriptor(),
KnownRoute::Ble.descriptor(),
KnownRoute::WebRtc.descriptor(),
KnownRoute::Moq.descriptor(),
KnownRoute::Iroh.descriptor(),
KnownRoute::IrohQuic.descriptor(),
KnownRoute::IrohRelay.descriptor(),
KnownRoute::WebRtcTurn.descriptor(),
];
#[cfg(test)]
pub const TRANSPORT_REGISTRY_JSON: &str = r###"{
"schemaVersion": 1,
"routes": [
{
"id": "iroh",
"rustVariant": "Iroh",
"baseProtocol": "iroh",
"family": "iroh-path",
"implementation": "core",
"locality": "mixed",
"maturity": "stable",
"defaultRank": 5,
"legacyPreferredRank": 80,
"browser": true,
"native": true,
"independentlyInstantiable": false
},
{
"id": "iroh-quic",
"rustVariant": "IrohQuic",
"baseProtocol": "iroh",
"family": "iroh-path",
"implementation": "path-label",
"locality": "direct-internet",
"maturity": "stable",
"defaultRank": 6,
"legacyPreferredRank": 30,
"browser": false,
"native": true,
"independentlyInstantiable": false
},
{
"id": "iroh-relay",
"rustVariant": "IrohRelay",
"baseProtocol": "iroh",
"family": "iroh-path",
"implementation": "path-label",
"locality": "relay",
"maturity": "stable",
"defaultRank": 7,
"legacyPreferredRank": 70,
"browser": true,
"native": true,
"independentlyInstantiable": false
},
{
"id": "iroh-lan",
"rustVariant": "IrohLan",
"baseProtocol": "iroh",
"family": "iroh-path",
"implementation": "path-label",
"locality": "nearby",
"maturity": "stable",
"defaultRank": 0,
"legacyPreferredRank": 10,
"browser": false,
"native": true,
"independentlyInstantiable": false
},
{
"id": "ble",
"rustVariant": "Ble",
"baseProtocol": "iroh",
"family": "iroh-physical",
"implementation": "host-installed",
"locality": "nearby",
"maturity": "experimental",
"defaultRank": 2,
"legacyPreferredRank": 25,
"browser": false,
"native": true,
"independentlyInstantiable": false
},
{
"id": "webrtc",
"rustVariant": "WebRtc",
"baseProtocol": "webrtc",
"family": "optional-route",
"implementation": "route-adapter",
"locality": "mixed",
"maturity": "stable",
"defaultRank": 3,
"legacyPreferredRank": 40,
"browser": true,
"native": true,
"independentlyInstantiable": true
},
{
"id": "webrtc-lan",
"rustVariant": "WebRtcLan",
"baseProtocol": "webrtc",
"family": "optional-route",
"implementation": "path-label",
"locality": "nearby",
"maturity": "stable",
"defaultRank": 1,
"legacyPreferredRank": 20,
"browser": true,
"native": true,
"independentlyInstantiable": false
},
{
"id": "webrtc-turn",
"rustVariant": "WebRtcTurn",
"baseProtocol": "webrtc",
"family": "optional-route",
"implementation": "path-label",
"locality": "relay",
"maturity": "stable",
"defaultRank": 8,
"legacyPreferredRank": 60,
"browser": true,
"native": true,
"independentlyInstantiable": false
},
{
"id": "moq",
"rustVariant": "Moq",
"baseProtocol": "moq",
"family": "optional-route",
"implementation": "route-adapter",
"locality": "relay",
"maturity": "experimental",
"defaultRank": 4,
"legacyPreferredRank": 50,
"browser": true,
"native": true,
"independentlyInstantiable": true
}
],
"defaultPriority": [
"iroh-lan",
"webrtc-lan",
"ble",
"webrtc",
"moq",
"iroh"
],
"labels": [
{
"input": "iroh",
"normalized": "iroh",
"irohBase": true,
"directIroh": false,
"optional": false,
"webRtc": false,
"independent": false
},
{
"input": " IROH-QUIC ",
"normalized": "iroh-quic",
"irohBase": true,
"directIroh": true,
"optional": false,
"webRtc": false,
"independent": false
},
{
"input": "iroh-relay",
"normalized": "iroh-relay",
"irohBase": true,
"directIroh": false,
"optional": false,
"webRtc": false,
"independent": false
},
{
"input": "iroh-lan",
"normalized": "iroh-lan",
"irohBase": true,
"directIroh": true,
"optional": false,
"webRtc": false,
"independent": false
},
{
"input": "ble",
"normalized": "ble",
"irohBase": true,
"directIroh": true,
"optional": false,
"webRtc": false,
"independent": false
},
{
"input": "webrtc",
"normalized": "webrtc",
"irohBase": false,
"directIroh": false,
"optional": true,
"webRtc": true,
"independent": true
},
{
"input": "webrtc-lan",
"normalized": "webrtc-lan",
"irohBase": false,
"directIroh": false,
"optional": true,
"webRtc": true,
"independent": false
},
{
"input": "webrtc-turn",
"normalized": "webrtc-turn",
"irohBase": false,
"directIroh": false,
"optional": true,
"webRtc": true,
"independent": false
},
{
"input": "moq",
"normalized": "moq",
"irohBase": false,
"directIroh": false,
"optional": true,
"webRtc": false,
"independent": true
},
{
"input": "webtransport",
"normalized": null,
"irohBase": false,
"directIroh": false,
"optional": false,
"webRtc": false,
"independent": false
}
],
"sendOrder": [
{
"activeTransport": "webrtc",
"irohTransport": "iroh-quic",
"order": "optionalTransportsFirst"
},
{
"activeTransport": "moq",
"irohTransport": "iroh-lan",
"order": "optionalTransportsFirst"
},
{
"activeTransport": "iroh-quic",
"irohTransport": "iroh-quic",
"order": "irohFirstAllowOptionalFallback"
},
{
"activeTransport": "iroh-relay",
"irohTransport": "iroh-relay",
"order": "irohFirstAllowOptionalFallback"
},
{
"activeTransport": null,
"irohTransport": null,
"order": "irohFirstAllowOptionalFallback"
}
],
"rankRoutes": [
{
"configuredPriority": [
"webrtc",
"iroh-lan"
],
"candidates": [
" IROH-LAN ",
"unknown",
"webrtc",
"webrtc",
"moq"
],
"expected": [
"webrtc",
"iroh-lan",
"moq"
]
},
{
"configuredPriority": [],
"candidates": [
"iroh",
"moq",
"webrtc",
"ble",
"webrtc-lan",
"iroh-lan",
"iroh-quic",
"iroh-relay",
"webrtc-turn"
],
"expected": [
"iroh-lan",
"webrtc-lan",
"ble",
"webrtc",
"moq",
"iroh",
"iroh-quic",
"iroh-relay",
"webrtc-turn"
]
},
{
"configuredPriority": [
"MOQ",
"moq",
"webtransport",
"BLE"
],
"candidates": [
"webrtc-turn",
"ble",
"moq",
"IROH-RELAY",
"ble"
],
"expected": [
"moq",
"ble",
"iroh-relay",
"webrtc-turn"
]
}
]
}"###;