Crates.io | relayport-rs |
lib.rs | relayport-rs |
version | 0.5.0 |
source | src |
created_at | 2023-11-30 19:14:42.010063 |
updated_at | 2023-12-12 12:05:16.685648 |
description | Fast and easy abstraction for proxying TCPand UDP ports. |
homepage | |
repository | https://github.com/mtelahun/relayport-rs |
max_upload_size | |
id | 1054386 |
size | 66,601 |
Fast and easy abstraction for proxying TCP and UDP ports.
This library simplifies the creation of asynchronous TCP/UDP proxies from rust applications. The only limit on the number of proxies are the resources available on the system on which it is run. This library depends on tokio for its runtime.
To use this library in your own package add the following to your Cargo.toml:
[dependencies]
relayport_rs = "0.5.0"
A simple program to proxy web traffic to a server might look like this:
use std::error::Error;
use relayport_rs::command::RelayCommand;
use relayport_rs::RelayPortError;
use relayport_rs::RelayTcpSocket;
use tokio::sync::broadcast;
#[tokio::main]
pub async fn main() -> Result<(), RelayPortError> {
// The relay expects a broadcast channel on which to listen for shutdown commands
let (tx, rx) = broadcast::channel(16);
// build a relay with a listener TCP socket
let relay = RelaySocket::build()
.set_so_reuseaddr(true)
.set_tcp_nodelay(true)
.bind("127.0.0.1:8080")?
.listen()?;
// this will never return unless it encounters an error
relay
.run("127.0.0.1:80", &rx)
.await
}
This example proxies DNS ports, which use UDP:
use std::error::Error;
use relayport_rs::command::RelayCommand;
use relayport_rs::RelayPortError;
use relayport_rs::RelayUdpSocket;
use tokio::sync::broadcast;
#[tokio::main]
pub async fn main() -> Result<(), RelayPortError> {
// The relay expects a broadcast channel on which to listen for shutdown commands
let (tx, rx) = broadcast::channel(16);
// build a relay with a UDP socket
let udp_relay = RelayUdpSocket::build()
.set_so_reuseaddr(true)
.bind("127.0.0.1:10080")
.await?;
// this will never return unless it encounters an error
udp_relay
.run("1.1.1.1:53", &rx)
.await
.expect("failed to start relay");
}
https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
To insure it was installed correctly type the following commands and make sure you get a successful output:
rustc --version
cargo --version