Add update version targeting and fix dns prober

This commit is contained in:
ospab 2026-06-19 17:31:43 +03:00
parent 916a21eeec
commit 87694c6218
3 changed files with 48 additions and 8 deletions

View File

@ -99,18 +99,27 @@ const PUBLIC_DNS_SERVERS: &[(&str, &str)] = &[
]; ];
pub async fn run_prober() { pub async fn run_prober() {
println!("Starting DNS resolver prober to find the fastest server for DNS Transport..."); println!("Enter your OSTP DNS Tunnel domain (e.g., tunnel.example.com):");
let mut target_domain = String::new();
std::io::stdin().read_line(&mut target_domain).unwrap();
let target_domain = target_domain.trim();
if target_domain.is_empty() {
println!("Domain cannot be empty. Exiting prober.");
return;
}
println!("\nStarting DNS resolver prober for domain: {}", target_domain);
println!("{:<15} | {:<15} | {:<10}", "Name", "IP Address", "Latency"); println!("{:<15} | {:<15} | {:<10}", "Name", "IP Address", "Latency");
println!("{:-<15}-+-{:-<15}-+-{:-<10}", "", "", ""); println!("{:-<15}-+-{:-<15}-+-{:-<10}", "", "", "");
let mut best_server = "8.8.8.8"; let mut best_server = "8.8.8.8";
let mut best_latency = Duration::from_secs(10); let mut best_latency = Duration::from_secs(10);
// We send a random TXT query to test DNS resolution time // Send a real OSTP ping packet encoded as a domain
let payload = b"PING";
let encoded_domain = ostp_core::dns::encode_payload_to_domain(payload, target_domain);
let mut rng = rand::thread_rng(); let mut rng = rand::thread_rng();
let id: u16 = rng.gen();
let packet = DnsPacket::new_query(id, "example.com", DnsRecordType::TXT);
let payload = packet.encode();
for (name, ip) in PUBLIC_DNS_SERVERS { for (name, ip) in PUBLIC_DNS_SERVERS {
let sock = match tokio::net::UdpSocket::bind("0.0.0.0:0").await { let sock = match tokio::net::UdpSocket::bind("0.0.0.0:0").await {
@ -122,8 +131,12 @@ pub async fn run_prober() {
continue; continue;
} }
let id: u16 = rng.gen();
let packet = DnsPacket::new_query(id, &encoded_domain, DnsRecordType::TXT);
let payload_bytes = packet.encode();
let start = Instant::now(); let start = Instant::now();
if sock.send(&payload).await.is_ok() { if sock.send(&payload_bytes).await.is_ok() {
let mut buf = [0u8; 512]; let mut buf = [0u8; 512];
match tokio::time::timeout(Duration::from_secs(2), sock.recv(&mut buf)).await { match tokio::time::timeout(Duration::from_secs(2), sock.recv(&mut buf)).await {
Ok(Ok(_)) => { Ok(Ok(_)) => {

View File

@ -55,6 +55,10 @@ struct Args {
#[arg(long, help_heading = "Common Commands")] #[arg(long, help_heading = "Common Commands")]
update: bool, update: bool,
/// Specify a target version for the update command (e.g., -v 0.2.98)
#[arg(short = 'v', long = "version", help_heading = "Common Commands")]
target_version: Option<String>,
/// Import a share link (ostp://...) into the configuration file and exit /// Import a share link (ostp://...) into the configuration file and exit
#[arg(long, help_heading = "Client Commands")] #[arg(long, help_heading = "Client Commands")]
import: Option<String>, import: Option<String>,

View File

@ -85,10 +85,33 @@ esac
echo "Platform: linux/$ARCH" echo "Platform: linux/$ARCH"
# ── Parse arguments ────────────────────────────────────────────────────
TARGET_VERSION=""
while [[ $# -gt 0 ]]; do
case $1 in
-v|--version)
TARGET_VERSION="$2"
shift 2
;;
*)
shift
;;
esac
done
# ── Download binary ────────────────────────────────────────────────── # ── Download binary ──────────────────────────────────────────────────
if [ -n "$TARGET_VERSION" ]; then
LATEST_RELEASE="$TARGET_VERSION"
# Ensure it starts with 'v' if it's supposed to
if [[ ! "$LATEST_RELEASE" =~ ^v ]]; then
LATEST_RELEASE="v$LATEST_RELEASE"
fi
echo "Fetching requested release $LATEST_RELEASE..."
else
echo "Fetching latest release..." echo "Fetching latest release..."
LATEST_RELEASE=$(curl -s "https://api.github.com/repos/${GITHUB_REPO}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') LATEST_RELEASE=$(curl -s "https://api.github.com/repos/${GITHUB_REPO}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
fi
if [ -z "$LATEST_RELEASE" ] || [[ "$LATEST_RELEASE" == *"null"* ]]; then if [ -z "$LATEST_RELEASE" ] || [[ "$LATEST_RELEASE" == *"null"* ]]; then
echo "[notice] Could not determine latest release automatically." echo "[notice] Could not determine latest release automatically."