Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] funky dns testing in progress #3115

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
355 changes: 195 additions & 160 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions iroh-dns-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ http = "1.0.0"
humantime-serde = "1.1.1"
iroh-metrics = { version = "0.30.0" }
lru = "0.12.3"
pkarr = { version = "2.2.0", features = [ "async", "relay", "dht"], default-features = false }
# pkarr = { version = "2.2.0", features = [ "async", "relay", "dht"], default-features = false }
pkarr = { path = "../../pkarr/pkarr", default-features = false, features = [
"async",
"relay",
"dht",
] }
rcgen = "0.13"
redb = "2.0.0"
regex = "1.10.3"
Expand Down Expand Up @@ -62,7 +67,10 @@ criterion = "0.5.1"
hickory-resolver = "=0.25.0-alpha.4"
iroh = { path = "../iroh" }
iroh-test = { path = "../iroh-test" }
pkarr = { version = "2.2.0", features = ["rand"] }
# pkarr = { version = "2.2.0", features = ["rand"] }
pkarr = { path = "../../pkarr/pkarr", default-features = false, features = [
"rand",
] }
rand = "0.8"
rand_chacha = "0.3.1"
testresult = "0.4.1"
Expand Down
15 changes: 14 additions & 1 deletion iroh-dns-server/src/http/pkarr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,28 @@ pub async fn put(
Path(key): Path<String>,
body: Bytes,
) -> Result<impl IntoResponse, AppError> {
tracing::debug!("pkarr put");
let key = pkarr::PublicKey::try_from(key.as_str())
.map_err(|e| AppError::new(StatusCode::BAD_REQUEST, Some(format!("invalid key: {e}"))))?;
tracing::debug!("pkarr put 1");
let label = &key.to_z32()[..10];
let signed_packet = pkarr::SignedPacket::from_relay_payload(&key, &body).map_err(|e| {
tracing::debug!("pkarr put 2");
// let empty = Bytes::new();
tracing::debug!("Received key: {:?}", key);
let y = &body;
println!("Reference body: {:?}", y);
tracing::debug!("pkarr put 2.5");
// let signed_packet_r = pkarr::SignedPacket::from_relay_payload(&key, &empty); // this works
let signed_packet_r = pkarr::SignedPacket::from_relay_payload(key, &body); // this segfaults

tracing::debug!("pkarr put 3");
let signed_packet = signed_packet_r.map_err(|e| {
AppError::new(
StatusCode::BAD_REQUEST,
Some(format!("invalid body payload: {e}")),
)
})?;
tracing::debug!("pkarr put 4");

let updated = state
.store
Expand Down
224 changes: 112 additions & 112 deletions iroh-dns-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,118 +44,118 @@ mod tests {
ZoneStore,
};

#[tokio::test]
async fn pkarr_publish_dns_resolve() -> Result<()> {
iroh_test::logging::setup_multithreaded();
let (server, nameserver, http_url) = Server::spawn_for_tests().await?;
let pkarr_relay_url = {
let mut url = http_url.clone();
url.set_path("/pkarr");
url
};
let signed_packet = {
use pkarr::dns;
let keypair = pkarr::Keypair::random();
let mut packet = dns::Packet::new_reply(0);
// record at root
packet.answers.push(dns::ResourceRecord::new(
dns::Name::new("").unwrap(),
dns::CLASS::IN,
30,
dns::rdata::RData::TXT("hi0".try_into()?),
));
// record at level one
packet.answers.push(dns::ResourceRecord::new(
dns::Name::new("_hello").unwrap(),
dns::CLASS::IN,
30,
dns::rdata::RData::TXT("hi1".try_into()?),
));
// record at level two
packet.answers.push(dns::ResourceRecord::new(
dns::Name::new("_hello.world").unwrap(),
dns::CLASS::IN,
30,
dns::rdata::RData::TXT("hi2".try_into()?),
));
// multiple records for same name
packet.answers.push(dns::ResourceRecord::new(
dns::Name::new("multiple").unwrap(),
dns::CLASS::IN,
30,
dns::rdata::RData::TXT("hi3".try_into()?),
));
packet.answers.push(dns::ResourceRecord::new(
dns::Name::new("multiple").unwrap(),
dns::CLASS::IN,
30,
dns::rdata::RData::TXT("hi4".try_into()?),
));
// record of type A
packet.answers.push(dns::ResourceRecord::new(
dns::Name::new("").unwrap(),
dns::CLASS::IN,
30,
dns::rdata::RData::A(Ipv4Addr::LOCALHOST.into()),
));
// record of type AAAA
packet.answers.push(dns::ResourceRecord::new(
dns::Name::new("foo.bar.baz").unwrap(),
dns::CLASS::IN,
30,
dns::rdata::RData::AAAA(Ipv6Addr::LOCALHOST.into()),
));
SignedPacket::from_packet(&keypair, &packet)?
};
let pkarr_client = pkarr::PkarrRelayClient::new(pkarr::RelaySettings {
relays: vec![pkarr_relay_url.to_string()],
..Default::default()
})?;
pkarr_client.as_async().publish(&signed_packet).await?;

use hickory_server::proto::rr::Name;
let pubkey = signed_packet.public_key().to_z32();
let resolver = test_resolver(nameserver);

// resolve root record
let name = Name::from_utf8(format!("{pubkey}."))?;
let res = resolver.txt_lookup(name).await?;
let records = res.iter().map(|t| t.to_string()).collect::<Vec<_>>();
assert_eq!(records, vec!["hi0".to_string()]);

// resolve level one record
let name = Name::from_utf8(format!("_hello.{pubkey}."))?;
let res = resolver.txt_lookup(name).await?;
let records = res.iter().map(|t| t.to_string()).collect::<Vec<_>>();
assert_eq!(records, vec!["hi1".to_string()]);

// resolve level two record
let name = Name::from_utf8(format!("_hello.world.{pubkey}."))?;
let res = resolver.txt_lookup(name).await?;
let records = res.iter().map(|t| t.to_string()).collect::<Vec<_>>();
assert_eq!(records, vec!["hi2".to_string()]);

// resolve multiple records for same name
let name = Name::from_utf8(format!("multiple.{pubkey}."))?;
let res = resolver.txt_lookup(name).await?;
let records = res.iter().map(|t| t.to_string()).collect::<Vec<_>>();
assert_eq!(records, vec!["hi3".to_string(), "hi4".to_string()]);

// resolve A record
let name = Name::from_utf8(format!("{pubkey}."))?;
let res = resolver.ipv4_lookup(name).await?;
let records = res.iter().map(|t| t.0).collect::<Vec<_>>();
assert_eq!(records, vec![Ipv4Addr::LOCALHOST]);

// resolve AAAA record
let name = Name::from_utf8(format!("foo.bar.baz.{pubkey}."))?;
let res = resolver.ipv6_lookup(name).await?;
let records = res.iter().map(|t| t.0).collect::<Vec<_>>();
assert_eq!(records, vec![Ipv6Addr::LOCALHOST]);

server.shutdown().await?;
Ok(())
}
// #[tokio::test]
// async fn pkarr_publish_dns_resolve() -> Result<()> {
// iroh_test::logging::setup_multithreaded();
// let (server, nameserver, http_url) = Server::spawn_for_tests().await?;
// let pkarr_relay_url = {
// let mut url = http_url.clone();
// url.set_path("/pkarr");
// url
// };
// let signed_packet = {
// use pkarr::dns;
// let keypair = pkarr::Keypair::random();
// let mut packet = dns::Packet::new_reply(0);
// // record at root
// packet.answers.push(dns::ResourceRecord::new(
// dns::Name::new("").unwrap(),
// dns::CLASS::IN,
// 30,
// dns::rdata::RData::TXT("hi0".try_into()?),
// ));
// // record at level one
// packet.answers.push(dns::ResourceRecord::new(
// dns::Name::new("_hello").unwrap(),
// dns::CLASS::IN,
// 30,
// dns::rdata::RData::TXT("hi1".try_into()?),
// ));
// // record at level two
// packet.answers.push(dns::ResourceRecord::new(
// dns::Name::new("_hello.world").unwrap(),
// dns::CLASS::IN,
// 30,
// dns::rdata::RData::TXT("hi2".try_into()?),
// ));
// // multiple records for same name
// packet.answers.push(dns::ResourceRecord::new(
// dns::Name::new("multiple").unwrap(),
// dns::CLASS::IN,
// 30,
// dns::rdata::RData::TXT("hi3".try_into()?),
// ));
// packet.answers.push(dns::ResourceRecord::new(
// dns::Name::new("multiple").unwrap(),
// dns::CLASS::IN,
// 30,
// dns::rdata::RData::TXT("hi4".try_into()?),
// ));
// // record of type A
// packet.answers.push(dns::ResourceRecord::new(
// dns::Name::new("").unwrap(),
// dns::CLASS::IN,
// 30,
// dns::rdata::RData::A(Ipv4Addr::LOCALHOST.into()),
// ));
// // record of type AAAA
// packet.answers.push(dns::ResourceRecord::new(
// dns::Name::new("foo.bar.baz").unwrap(),
// dns::CLASS::IN,
// 30,
// dns::rdata::RData::AAAA(Ipv6Addr::LOCALHOST.into()),
// ));
// SignedPacket::from_packet(&keypair, &packet)?
// };
// let pkarr_client = pkarr::PkarrRelayClient::new(pkarr::RelaySettings {
// relays: vec![pkarr_relay_url.to_string()],
// ..Default::default()
// })?;
// pkarr_client.as_async().publish(&signed_packet).await?;

// use hickory_server::proto::rr::Name;
// let pubkey = signed_packet.public_key().to_z32();
// let resolver = test_resolver(nameserver);

// // resolve root record
// let name = Name::from_utf8(format!("{pubkey}."))?;
// let res = resolver.txt_lookup(name).await?;
// let records = res.iter().map(|t| t.to_string()).collect::<Vec<_>>();
// assert_eq!(records, vec!["hi0".to_string()]);

// // resolve level one record
// let name = Name::from_utf8(format!("_hello.{pubkey}."))?;
// let res = resolver.txt_lookup(name).await?;
// let records = res.iter().map(|t| t.to_string()).collect::<Vec<_>>();
// assert_eq!(records, vec!["hi1".to_string()]);

// // resolve level two record
// let name = Name::from_utf8(format!("_hello.world.{pubkey}."))?;
// let res = resolver.txt_lookup(name).await?;
// let records = res.iter().map(|t| t.to_string()).collect::<Vec<_>>();
// assert_eq!(records, vec!["hi2".to_string()]);

// // resolve multiple records for same name
// let name = Name::from_utf8(format!("multiple.{pubkey}."))?;
// let res = resolver.txt_lookup(name).await?;
// let records = res.iter().map(|t| t.to_string()).collect::<Vec<_>>();
// assert_eq!(records, vec!["hi3".to_string(), "hi4".to_string()]);

// // resolve A record
// let name = Name::from_utf8(format!("{pubkey}."))?;
// let res = resolver.ipv4_lookup(name).await?;
// let records = res.iter().map(|t| t.0).collect::<Vec<_>>();
// assert_eq!(records, vec![Ipv4Addr::LOCALHOST]);

// // resolve AAAA record
// let name = Name::from_utf8(format!("foo.bar.baz.{pubkey}."))?;
// let res = resolver.ipv6_lookup(name).await?;
// let records = res.iter().map(|t| t.0).collect::<Vec<_>>();
// assert_eq!(records, vec![Ipv6Addr::LOCALHOST]);

// server.shutdown().await?;
// Ok(())
// }

#[tokio::test]
async fn integration_smoke() -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion iroh-dns-server/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl ZoneStore {
debug!("DHT resolve {}", key.to_z32());
let packet_opt = pkarr.as_ref().clone().as_async().resolve(&key).await?;
if let Some(packet) = packet_opt {
debug!("DHT resolve successful {:?}", packet.packet());
debug!("DHT resolve successful {:?}", packet.message());
return self
.cache
.lock()
Expand Down
6 changes: 3 additions & 3 deletions iroh-dns-server/src/store/signed_packets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ impl Actor {
} else {
false
};
let value = packet.as_bytes();
tables.signed_packets.insert(key.as_bytes(), &value[..])?;
// let value = packet.as_bytes();
tables.signed_packets.insert(key.as_bytes(), &packet.to_vec()[..])?;
tables.update_time.insert(&packet.timestamp().to_be_bytes(), key.as_bytes())?;
if replaced {
inc!(Metrics, store_packets_updated);
Expand Down Expand Up @@ -316,7 +316,7 @@ fn get_packet(
let Some(row) = table.get(key.as_ref())? else {
return Ok(None);
};
let packet = SignedPacket::from_bytes(&row.value().to_vec().into())?;
let packet = SignedPacket::from_bytes(&row.value().to_vec()[..])?;
Ok(Some(packet))
}

Expand Down
2 changes: 1 addition & 1 deletion iroh-dns-server/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl AsRef<[u8; 32]> for PublicKeyBytes {
}

pub fn signed_packet_to_hickory_message(signed_packet: &SignedPacket) -> Result<Message> {
let encoded = signed_packet.encoded_packet();
let encoded = signed_packet.encoded_message();
let message = Message::from_bytes(&encoded)?;
Ok(message)
}
Expand Down
7 changes: 6 additions & 1 deletion iroh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ futures-sink = "0.3"
futures-util = "0.3"
governor = "0.7.0"
hickory-resolver = { version = "=0.25.0-alpha.4" }
hickory-proto = { version = "=0.24.2" }
http = "1"
http-body-util = "0.1.0"
hyper = { version = "1", features = ["server", "client", "http1"] }
Expand All @@ -50,7 +51,11 @@ iroh-relay = { version = "0.30", path = "../iroh-relay", default-features = fals
netdev = "0.31.0"
netwatch = { version = "0.2.0" }
pin-project = "1"
pkarr = { version = "2", default-features = false, features = [
# pkarr = { version = "2", default-features = false, features = [
# "async",
# "relay",
# ] }
pkarr = { path = "../../pkarr/pkarr", default-features = false, features = [
"async",
"relay",
] }
Expand Down
4 changes: 1 addition & 3 deletions iroh/examples/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ async fn main() -> Result<()> {
setup_logging();
let args = Cli::parse();

let pkarr_relay_url = "https://10.0.0.71:8443/pkarr"
.parse()
.expect("url is valid");
let pkarr_relay_url = "http://10.0.0.71:8080/pkarr".parse().expect("url is valid");

let pkarr_discovery_closure = move |secret_key: &SecretKey| {
let pkarr_d = PkarrPublisher::new(secret_key.clone(), pkarr_relay_url);
Expand Down
2 changes: 1 addition & 1 deletion iroh/src/discovery/pkarr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ impl PkarrRelayClient {
}

let payload = response.bytes().await?;
Ok(SignedPacket::from_relay_payload(&public_key, &payload)?)
Ok(SignedPacket::from_relay_payload(public_key, &payload)?)
}

/// Publishes a [`SignedPacket`].
Expand Down
Loading
Loading