-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
1,665 additions
and
397 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//! Make an HTTP request over to a Pkarr address using Reqwest | ||
use reqwest::Method; | ||
use tracing::Level; | ||
use tracing_subscriber; | ||
|
||
use clap::Parser; | ||
|
||
use pkarr::{Client, PublicKey}; | ||
|
||
#[derive(Parser)] | ||
#[command(author, version, about, long_about = None)] | ||
struct Cli { | ||
/// Url to GET from | ||
url: String, | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> anyhow::Result<()> { | ||
tracing_subscriber::fmt().with_max_level(Level::INFO).init(); | ||
|
||
let cli = Cli::parse(); | ||
let url = cli.url; | ||
|
||
let reqwest = if PublicKey::try_from(url.as_str()).is_err() { | ||
// If it is not a Pkarr domain, use normal Reqwest | ||
reqwest::Client::new() | ||
} else { | ||
let client = Client::builder().build()?; | ||
|
||
reqwest::ClientBuilder::from(client).build()? | ||
}; | ||
|
||
println!("GET {url}.."); | ||
let response = reqwest.request(Method::GET, &url).send().await?; | ||
|
||
let body = response.text().await?; | ||
|
||
println!("{body}"); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
//! Run an HTTP server listening on a Pkarr domain | ||
//! | ||
//! This server will _not_ be accessible from other networks | ||
//! unless the provided IP is public and the port number is forwarded. | ||
use tracing::Level; | ||
use tracing_subscriber; | ||
|
||
use axum::{routing::get, Router}; | ||
use axum_server::tls_rustls::RustlsConfig; | ||
|
||
use std::net::{SocketAddr, ToSocketAddrs}; | ||
use std::sync::Arc; | ||
|
||
use clap::Parser; | ||
|
||
use pkarr::{dns::rdata::SVCB, Client, Keypair, SignedPacket}; | ||
|
||
#[derive(Parser)] | ||
#[command(author, version, about, long_about = None)] | ||
struct Cli { | ||
/// IP address to listen on | ||
ip: String, | ||
/// Port number to listen no | ||
port: u16, | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> anyhow::Result<()> { | ||
tracing_subscriber::fmt().with_max_level(Level::INFO).init(); | ||
|
||
let cli = Cli::parse(); | ||
|
||
let addr = format!("{}:{}", cli.ip, cli.port) | ||
.to_socket_addrs()? | ||
.next() | ||
.ok_or(anyhow::anyhow!( | ||
"Could not convert IP and port to socket addresses" | ||
))?; | ||
|
||
let keypair = Keypair::random(); | ||
|
||
let client = Client::builder().build()?; | ||
|
||
// Run a server on Pkarr | ||
println!("Server listening on {addr}"); | ||
|
||
// You should republish this every time the socket address change | ||
// and once an hour otherwise. | ||
publish_server_pkarr(&client, &keypair, &addr).await; | ||
|
||
println!("Server running on https://{}", keypair.public_key()); | ||
|
||
let server = axum_server::bind_rustls( | ||
addr, | ||
RustlsConfig::from_config(Arc::new(keypair.to_rpk_rustls_server_config())), | ||
); | ||
|
||
let app = Router::new().route("/", get(|| async { "Hello, world!" })); | ||
server.serve(app.into_make_service()).await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn publish_server_pkarr(client: &Client, keypair: &Keypair, socket_addr: &SocketAddr) { | ||
let mut svcb = SVCB::new(0, ".".try_into().expect("infallible")); | ||
svcb.set_port(socket_addr.port()); | ||
|
||
let signed_packet = SignedPacket::builder() | ||
.https(".".try_into().unwrap(), svcb, 60 * 60) | ||
.address(".".try_into().unwrap(), socket_addr.ip(), 60 * 60) | ||
.sign(&keypair) | ||
.unwrap(); | ||
|
||
client.publish(&signed_packet).await.unwrap(); | ||
} |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
Oops, something went wrong.