#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub enum KnownRoute {
#[serde(rename = "iroh")]
Iroh,
#[serde(rename = "iroh-quic")]
IrohQuic,
#[serde(rename = "iroh-relay")]
IrohRelay,
#[serde(rename = "iroh-lan")]
IrohLan,
#[serde(rename = "ble")]
Ble,
#[serde(rename = "webrtc")]
WebRtc,
#[serde(rename = "moq")]
Moq,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum RouteFamily {
IrohPath,
IrohPhysical,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum RouteImplementation {
Core,
HostInstalled,
CarrierAdapter,
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,
}
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::Moq => "moq",
}
}
pub const fn default_rank(self) -> u8 {
match self {
Self::Iroh => 6,
Self::IrohQuic => 1,
Self::IrohRelay => 5,
Self::IrohLan => 0,
Self::Ble => 2,
Self::WebRtc => 3,
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: 6,
browser: true,
native: true,
},
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: 1,
browser: false,
native: true,
},
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: 5,
browser: true,
native: true,
},
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,
},
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,
},
Self::WebRtc => RouteDescriptor {
route: self,
id: "webrtc",
base_protocol: "iroh",
family: RouteFamily::IrohPhysical,
implementation: RouteImplementation::CarrierAdapter,
locality: RouteLocality::Mixed,
maturity: RouteMaturity::Stable,
default_rank: 3,
browser: true,
native: true,
},
Self::Moq => RouteDescriptor {
route: self,
id: "moq",
base_protocol: "iroh",
family: RouteFamily::IrohPhysical,
implementation: RouteImplementation::CarrierAdapter,
locality: RouteLocality::Relay,
maturity: RouteMaturity::Experimental,
default_rank: 4,
browser: true,
native: true,
},
}
}
pub const ALL_BY_DEFAULT_RANK: [Self; 7] = [
Self::IrohLan,
Self::IrohQuic,
Self::Ble,
Self::WebRtc,
Self::Moq,
Self::IrohRelay,
Self::Iroh,
];
pub const DEFAULT_PRIORITY: [Self; 5] = [
Self::IrohLan,
Self::IrohQuic,
Self::WebRtc,
Self::Moq,
Self::IrohRelay,
];
}
pub const KNOWN_ROUTE_DESCRIPTORS: [RouteDescriptor; 7] = [
KnownRoute::IrohLan.descriptor(),
KnownRoute::IrohQuic.descriptor(),
KnownRoute::Ble.descriptor(),
KnownRoute::WebRtc.descriptor(),
KnownRoute::Moq.descriptor(),
KnownRoute::IrohRelay.descriptor(),
KnownRoute::Iroh.descriptor(),
];
#[cfg(test)]
pub const TRANSPORT_REGISTRY_JSON: &str = r###"{
"schemaVersion": 2,
"routes": [
{
"id": "iroh",
"rustVariant": "Iroh",
"baseProtocol": "iroh",
"family": "iroh-path",
"implementation": "core",
"locality": "mixed",
"maturity": "stable",
"defaultRank": 6,
"browser": true,
"native": true
},
{
"id": "iroh-quic",
"rustVariant": "IrohQuic",
"baseProtocol": "iroh",
"family": "iroh-path",
"implementation": "path-label",
"locality": "direct-internet",
"maturity": "stable",
"defaultRank": 1,
"browser": false,
"native": true
},
{
"id": "iroh-relay",
"rustVariant": "IrohRelay",
"baseProtocol": "iroh",
"family": "iroh-path",
"implementation": "path-label",
"locality": "relay",
"maturity": "stable",
"defaultRank": 5,
"browser": true,
"native": true
},
{
"id": "iroh-lan",
"rustVariant": "IrohLan",
"baseProtocol": "iroh",
"family": "iroh-path",
"implementation": "path-label",
"locality": "nearby",
"maturity": "stable",
"defaultRank": 0,
"browser": false,
"native": true
},
{
"id": "ble",
"rustVariant": "Ble",
"baseProtocol": "iroh",
"family": "iroh-physical",
"implementation": "host-installed",
"locality": "nearby",
"maturity": "experimental",
"defaultRank": 2,
"browser": false,
"native": true
},
{
"id": "webrtc",
"rustVariant": "WebRtc",
"baseProtocol": "iroh",
"family": "iroh-physical",
"implementation": "carrier-adapter",
"locality": "mixed",
"maturity": "stable",
"defaultRank": 3,
"browser": true,
"native": true
},
{
"id": "moq",
"rustVariant": "Moq",
"baseProtocol": "iroh",
"family": "iroh-physical",
"implementation": "carrier-adapter",
"locality": "relay",
"maturity": "experimental",
"defaultRank": 4,
"browser": true,
"native": true
}
],
"defaultPriority": [
"iroh-lan",
"iroh-quic",
"webrtc",
"moq",
"iroh-relay"
],
"legacyPreferredRanks": {
"iroh": 80,
"iroh-quic": 30,
"iroh-relay": 70,
"iroh-lan": 10,
"ble": 25,
"webrtc": 40,
"moq": 50
},
"labels": [
{
"input": "iroh",
"normalized": "iroh",
"irohBase": true,
"directIroh": false,
"webRtc": false
},
{
"input": " IROH-QUIC ",
"normalized": "iroh-quic",
"irohBase": true,
"directIroh": true,
"webRtc": false
},
{
"input": "iroh-relay",
"normalized": "iroh-relay",
"irohBase": true,
"directIroh": false,
"webRtc": false
},
{
"input": "iroh-lan",
"normalized": "iroh-lan",
"irohBase": true,
"directIroh": true,
"webRtc": false
},
{
"input": "ble",
"normalized": "ble",
"irohBase": true,
"directIroh": true,
"webRtc": false
},
{
"input": "webrtc",
"normalized": "webrtc",
"irohBase": true,
"directIroh": false,
"webRtc": true
},
{
"input": "moq",
"normalized": "moq",
"irohBase": true,
"directIroh": false,
"webRtc": false
},
{
"input": "iroh-webrtc",
"normalized": null,
"irohBase": false,
"directIroh": false,
"webRtc": false
},
{
"input": "iroh-moq",
"normalized": null,
"irohBase": false,
"directIroh": false,
"webRtc": false
},
{
"input": "webrtc-lan",
"normalized": null,
"irohBase": false,
"directIroh": false,
"webRtc": false
},
{
"input": "webrtc-turn",
"normalized": null,
"irohBase": false,
"directIroh": false,
"webRtc": false
},
{
"input": "webtransport",
"normalized": null,
"irohBase": false,
"directIroh": false,
"webRtc": false
}
],
"rankRoutes": [
{
"configuredPriority": [
"webrtc",
"iroh-lan"
],
"candidates": [
" IROH-LAN ",
"unknown",
"webrtc",
"webrtc",
"moq"
],
"expected": [
"webrtc",
"iroh-lan",
"moq"
]
},
{
"configuredPriority": [],
"candidates": [
"iroh",
"moq",
"iroh-moq",
"webrtc",
"iroh-webrtc",
"ble",
"webrtc-lan",
"iroh-lan",
"iroh-quic",
"iroh-relay",
"webrtc-turn"
],
"expected": [
"iroh-lan",
"iroh-quic",
"webrtc",
"moq",
"iroh-relay",
"ble",
"iroh"
]
},
{
"configuredPriority": [
"MOQ",
"moq",
"webtransport",
"BLE"
],
"candidates": [
"webrtc-turn",
"ble",
"moq",
"IROH-RELAY",
"ble"
],
"expected": [
"moq",
"ble",
"iroh-relay"
]
}
]
}"###;