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

UDP proxy support added #53

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ rust-version = "1.81"

[dependencies]
anyhow = "1.0.75"
bytes = "1.10.0"
clap = { version = "4.4.10", features = ["derive"] }
hex = "0.4.3"
iroh = { version = "0.31", default-features = false }
Expand Down
52 changes: 47 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ use iroh::{
Endpoint, NodeAddr, SecretKey,
};
use std::{
io,
net::{SocketAddr, SocketAddrV4, SocketAddrV6, ToSocketAddrs},
str::FromStr,
io, net::{SocketAddr, SocketAddrV4, SocketAddrV6, ToSocketAddrs}, str::FromStr
};
use tokio::{
io::{AsyncRead, AsyncWrite, AsyncWriteExt},
select,
io::{AsyncRead, AsyncWrite, AsyncWriteExt}, select
};
use tokio_util::sync::CancellationToken;
mod udp;

/// Create a dumb pipe between two machines, using an iroh magicsocket.
///
Expand Down Expand Up @@ -54,6 +52,15 @@ pub enum Commands {
/// connecting to a TCP socket for which you have to specify the host and port.
ListenTcp(ListenTcpArgs),

/// Listen on a magicsocket and forward incoming connections to the specified
/// host and port. Every incoming bidi stream is forwarded to a new connection.
///
/// Will print a node ticket on stderr that can be used to connect.
///
/// As far as the magic socket is concerned, this is listening. But it is
/// connecting to a UDP socket for which you have to specify the host and port.
ListenUdp(ListenUdpArgs),

/// Connect to a magicsocket, open a bidi stream, and forward stdin/stdout.
///
/// A node ticket is required to connect.
Expand All @@ -67,6 +74,15 @@ pub enum Commands {
/// As far as the magic socket is concerned, this is connecting. But it is
/// listening on a TCP socket for which you have to specify the interface and port.
ConnectTcp(ConnectTcpArgs),

/// Connect to a magicsocket, open a bidi stream, and forward stdin/stdout
/// to it.
///
/// A node ticket is required to connect.
///
/// As far as the magic socket is concerned, this is connecting. But it is
/// listening on a UDP socket for which you have to specify the interface and port.
ConnectUdp(ConnectUdpArgs),
}

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -140,6 +156,15 @@ pub struct ListenTcpArgs {
pub common: CommonArgs,
}

#[derive(Parser, Debug)]
pub struct ListenUdpArgs {
#[clap(long)]
pub host: String,

#[clap(flatten)]
pub common: CommonArgs,
}

#[derive(Parser, Debug)]
pub struct ConnectTcpArgs {
/// The addresses to listen on for incoming tcp connections.
Expand All @@ -155,6 +180,21 @@ pub struct ConnectTcpArgs {
pub common: CommonArgs,
}

#[derive(Parser, Debug)]
pub struct ConnectUdpArgs {
/// The addresses to listen on for incoming udp connections.
///
/// To listen on all network interfaces, use 0.0.0.0:12345
#[clap(long)]
pub addr: String,

/// The node to connect to
pub ticket: NodeTicket,

#[clap(flatten)]
pub common: CommonArgs,
}

#[derive(Parser, Debug)]
pub struct ConnectArgs {
/// The node to connect to
Expand Down Expand Up @@ -540,8 +580,10 @@ async fn main() -> anyhow::Result<()> {
let res = match args.command {
Commands::Listen(args) => listen_stdio(args).await,
Commands::ListenTcp(args) => listen_tcp(args).await,
Commands::ListenUdp(args) => udp::listen_udp(args).await,
Commands::Connect(args) => connect_stdio(args).await,
Commands::ConnectTcp(args) => connect_tcp(args).await,
Commands::ConnectUdp(args) => udp::connect_udp(args).await,
};
match res {
Ok(()) => std::process::exit(0),
Expand Down
Loading