node: Support DNS address types at the wire level
This commit is contained in:
parent
70e199dd09
commit
85b092872d
|
|
@ -85,7 +85,7 @@ impl netservices::Frame for Message {
|
||||||
pub enum AddressType {
|
pub enum AddressType {
|
||||||
Ipv4 = 1,
|
Ipv4 = 1,
|
||||||
Ipv6 = 2,
|
Ipv6 = 2,
|
||||||
Hostname = 3,
|
Dns = 3,
|
||||||
Onion = 4,
|
Onion = 4,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -100,7 +100,7 @@ impl From<&Address> for AddressType {
|
||||||
match a.host {
|
match a.host {
|
||||||
HostName::Ip(net::IpAddr::V4(_)) => AddressType::Ipv4,
|
HostName::Ip(net::IpAddr::V4(_)) => AddressType::Ipv4,
|
||||||
HostName::Ip(net::IpAddr::V6(_)) => AddressType::Ipv6,
|
HostName::Ip(net::IpAddr::V6(_)) => AddressType::Ipv6,
|
||||||
HostName::Dns(_) => AddressType::Hostname,
|
HostName::Dns(_) => AddressType::Dns,
|
||||||
HostName::Tor(_) => AddressType::Onion,
|
HostName::Tor(_) => AddressType::Onion,
|
||||||
_ => todo!(), // FIXME(cloudhead): Maxim will remove `non-exhaustive`
|
_ => todo!(), // FIXME(cloudhead): Maxim will remove `non-exhaustive`
|
||||||
}
|
}
|
||||||
|
|
@ -114,7 +114,7 @@ impl TryFrom<u8> for AddressType {
|
||||||
match other {
|
match other {
|
||||||
1 => Ok(AddressType::Ipv4),
|
1 => Ok(AddressType::Ipv4),
|
||||||
2 => Ok(AddressType::Ipv6),
|
2 => Ok(AddressType::Ipv6),
|
||||||
3 => Ok(AddressType::Hostname),
|
3 => Ok(AddressType::Dns),
|
||||||
4 => Ok(AddressType::Onion),
|
4 => Ok(AddressType::Onion),
|
||||||
_ => Err(other),
|
_ => Err(other),
|
||||||
}
|
}
|
||||||
|
|
@ -301,6 +301,10 @@ impl wire::Encode for Address {
|
||||||
n += u8::from(AddressType::Ipv6).encode(writer)?;
|
n += u8::from(AddressType::Ipv6).encode(writer)?;
|
||||||
n += ip.octets().encode(writer)?;
|
n += ip.octets().encode(writer)?;
|
||||||
}
|
}
|
||||||
|
HostName::Dns(ref dns) => {
|
||||||
|
n += u8::from(AddressType::Dns).encode(writer)?;
|
||||||
|
n += dns.encode(writer)?;
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
todo!();
|
todo!();
|
||||||
}
|
}
|
||||||
|
|
@ -327,8 +331,10 @@ impl wire::Decode for Address {
|
||||||
|
|
||||||
HostName::Ip(net::IpAddr::V6(ip))
|
HostName::Ip(net::IpAddr::V6(ip))
|
||||||
}
|
}
|
||||||
Ok(AddressType::Hostname) => {
|
Ok(AddressType::Dns) => {
|
||||||
todo!();
|
let dns: String = wire::Decode::decode(reader)?;
|
||||||
|
|
||||||
|
HostName::Dns(dns)
|
||||||
}
|
}
|
||||||
Ok(AddressType::Onion) => {
|
Ok(AddressType::Onion) => {
|
||||||
todo!();
|
todo!();
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ use crate::node::Address;
|
||||||
pub enum AddressType {
|
pub enum AddressType {
|
||||||
Ipv4 = 1,
|
Ipv4 = 1,
|
||||||
Ipv6 = 2,
|
Ipv6 = 2,
|
||||||
Hostname = 3,
|
Dns = 3,
|
||||||
Onion = 4,
|
Onion = 4,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -31,7 +31,7 @@ impl From<&Address> for AddressType {
|
||||||
match a.host {
|
match a.host {
|
||||||
HostName::Ip(net::IpAddr::V4(_)) => AddressType::Ipv4,
|
HostName::Ip(net::IpAddr::V4(_)) => AddressType::Ipv4,
|
||||||
HostName::Ip(net::IpAddr::V6(_)) => AddressType::Ipv6,
|
HostName::Ip(net::IpAddr::V6(_)) => AddressType::Ipv6,
|
||||||
HostName::Dns(_) => AddressType::Hostname,
|
HostName::Dns(_) => AddressType::Dns,
|
||||||
HostName::Tor(_) => AddressType::Onion,
|
HostName::Tor(_) => AddressType::Onion,
|
||||||
_ => todo!(), // FIXME(cloudhead): Maxim will remove `non-exhaustive`
|
_ => todo!(), // FIXME(cloudhead): Maxim will remove `non-exhaustive`
|
||||||
}
|
}
|
||||||
|
|
@ -45,7 +45,7 @@ impl TryFrom<u8> for AddressType {
|
||||||
match other {
|
match other {
|
||||||
1 => Ok(AddressType::Ipv4),
|
1 => Ok(AddressType::Ipv4),
|
||||||
2 => Ok(AddressType::Ipv6),
|
2 => Ok(AddressType::Ipv6),
|
||||||
3 => Ok(AddressType::Hostname),
|
3 => Ok(AddressType::Dns),
|
||||||
4 => Ok(AddressType::Onion),
|
4 => Ok(AddressType::Onion),
|
||||||
_ => Err(other),
|
_ => Err(other),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -342,7 +342,7 @@ impl TryFrom<&sql::Value> for AddressType {
|
||||||
sql::Value::String(s) => match s.as_str() {
|
sql::Value::String(s) => match s.as_str() {
|
||||||
"ipv4" => Ok(AddressType::Ipv4),
|
"ipv4" => Ok(AddressType::Ipv4),
|
||||||
"ipv6" => Ok(AddressType::Ipv6),
|
"ipv6" => Ok(AddressType::Ipv6),
|
||||||
"hostname" => Ok(AddressType::Hostname),
|
"hostname" => Ok(AddressType::Dns),
|
||||||
"onion" => Ok(AddressType::Onion),
|
"onion" => Ok(AddressType::Onion),
|
||||||
_ => Err(err),
|
_ => Err(err),
|
||||||
},
|
},
|
||||||
|
|
@ -356,7 +356,7 @@ impl sql::BindableWithIndex for AddressType {
|
||||||
match self {
|
match self {
|
||||||
Self::Ipv4 => "ipv4".bind(stmt, i),
|
Self::Ipv4 => "ipv4".bind(stmt, i),
|
||||||
Self::Ipv6 => "ipv6".bind(stmt, i),
|
Self::Ipv6 => "ipv6".bind(stmt, i),
|
||||||
Self::Hostname => "hostname".bind(stmt, i),
|
Self::Dns => "dns".bind(stmt, i),
|
||||||
Self::Onion => "onion".bind(stmt, i),
|
Self::Onion => "onion".bind(stmt, i),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ use crate::identity::{
|
||||||
project::Project,
|
project::Project,
|
||||||
Did,
|
Did,
|
||||||
};
|
};
|
||||||
|
use crate::node::address::AddressType;
|
||||||
use crate::node::{Address, Alias};
|
use crate::node::{Address, Alias};
|
||||||
use crate::storage;
|
use crate::storage;
|
||||||
use crate::storage::refs::{Refs, SignedRefs};
|
use crate::storage::refs::{Refs, SignedRefs};
|
||||||
|
|
@ -214,16 +215,38 @@ impl Arbitrary for Id {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Arbitrary for AddressType {
|
||||||
|
fn arbitrary(g: &mut qcheck::Gen) -> Self {
|
||||||
|
let t = *g.choose(&[1, 2, 3]).unwrap() as u8;
|
||||||
|
|
||||||
|
AddressType::try_from(t).unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Arbitrary for Address {
|
impl Arbitrary for Address {
|
||||||
fn arbitrary(g: &mut qcheck::Gen) -> Self {
|
fn arbitrary(g: &mut qcheck::Gen) -> Self {
|
||||||
let ip = if bool::arbitrary(g) {
|
let host = match AddressType::arbitrary(g) {
|
||||||
net::IpAddr::V4(net::Ipv4Addr::from(u32::arbitrary(g)))
|
AddressType::Ipv4 => cyphernet::addr::HostName::Ip(net::IpAddr::V4(
|
||||||
} else {
|
net::Ipv4Addr::from(u32::arbitrary(g)),
|
||||||
|
)),
|
||||||
|
AddressType::Ipv6 => {
|
||||||
let octets: [u8; 16] = Arbitrary::arbitrary(g);
|
let octets: [u8; 16] = Arbitrary::arbitrary(g);
|
||||||
net::IpAddr::V6(net::Ipv6Addr::from(octets))
|
cyphernet::addr::HostName::Ip(net::IpAddr::V6(net::Ipv6Addr::from(octets)))
|
||||||
|
}
|
||||||
|
AddressType::Dns => cyphernet::addr::HostName::Dns(
|
||||||
|
g.choose(&[
|
||||||
|
"seed.radicle.xyz",
|
||||||
|
"seed.radicle.garden",
|
||||||
|
"seed.radicle.cloudhead.io",
|
||||||
|
])
|
||||||
|
.unwrap()
|
||||||
|
.to_string(),
|
||||||
|
),
|
||||||
|
AddressType::Onion => todo!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
Address::from(cyphernet::addr::NetAddr {
|
Address::from(cyphernet::addr::NetAddr {
|
||||||
host: cyphernet::addr::HostName::Ip(ip),
|
host,
|
||||||
port: u16::arbitrary(g),
|
port: u16::arbitrary(g),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue