0.1.0 |
|
---|
#23 在 #multicast
48KB
630 行
MPROXY:多播网络调度器和代理
在网络中传输文件和原始套接字数据。包括客户端、代理、反向代理和服务器应用程序,以及库API。使用UDP多播作为中间路由,提供完整的网络堆栈,实现可扩展的流复用和聚合馈送。
- 在网络中传输任意数据
- 完整的网络堆栈
- 同时向/从多个端点发送、代理、反向代理和接收
- 通过多播IP路由进行流复用和聚合
- 主机名解析
- 快速
- 500+ Mbps 读取/传输/写入速度(UDP)
- 最小化
- 编译的二进制文件 ~350KB
- 小型内存占用
- 无状态:线程之间没有共享资源。线程间的通信通过UDP多播路由
兼容性
- UDP
- TCP(通过
proxy
或reverse_proxy
) - TLS(通过
proxy
部分支持客户端TLS。需要启用tls
特性) - IPv4
- IPv6
- Unix/Linux/Mac
- Windows
安装二进制文件
cargo install mproxy-client
cargo install mproxy-proxy
cargo install mproxy-reverseproxy
cargo install mproxy-server
将MPROXY作为库使用
在Cargo.toml中包含
[dependencies]
mproxy-client = "0.1.0"
mproxy-proxy = "0.1.0"
mproxy-reverseproxy = "0.1.0"
mproxy-server = "0.1.0"
命令行界面
客户端
MPROXY: UDP Client
Stream local data to logging servers via UDP
USAGE:
mproxy-client [FLAGS] [OPTIONS] ...
OPTIONS:
--path [FILE_DESCRIPTOR] Filepath, descriptor, or handle. Use "-" for stdin
--server-addr [HOSTNAME:PORT] Downstream UDP server address. May be repeated
FLAGS:
-h, --help Prints help information
-t, --tee Copy input to stdout
EXAMPLE:
mproxy-client --path /dev/random --server-addr '127.0.0.1:9920' --server-addr '[::1]:9921'
mproxy-client --path - --server-addr '224.0.0.1:9922' --server-addr '[ff02::1]:9923' --tee >> logfile.log
代理
MPROXY: Proxy
Forward TCP, UDP, or Multicast endpoints to a downstream UDP socket address.
USAGE:
mproxy-proxy [FLAGS] [OPTIONS]
OPTIONS:
--udp-listen-addr [HOSTNAME:PORT] UDP listening socket address. May be repeated
--udp-downstream-addr [HOSTNAME:PORT] UDP downstream socket address. May be repeated
--tcp-connect-addr [HOSTNAME:PORT] Connect to TCP host, forwarding stream. May be repeated
FLAGS:
-h, --help Prints help information
-t, --tee Copy input to stdout
EXAMPLE:
mproxy-proxy --udp-listen-addr '0.0.0.0:9920' \
--udp-downstream-addr '[::1]:9921' \
--udp-downstream-addr 'localhost:9922' \
--tcp-connect-addr 'localhost:9925' \
--tee
反向代理
MPROXY: Reverse-proxy
Forward upstream TCP and/or UDP endpoints to downstream listeners.
Messages are routed via UDP multicast to downstream sender threads.
Spawns one thread per listener.
USAGE:
mproxy-reverseproxy [FLAGS] [OPTIONS]
OPTIONS:
--udp-listen-addr [HOSTNAME:PORT] Spawn a UDP socket listener, and forward to --multicast-addr
--tcp_listen_addr [HOSTNAME:PORT] Reverse-proxy accepting TCP connections and forwarding to --multicast-addr
--multicast-addr [MULTICAST_IP:PORT] Defaults to '[ff02::1]:9918'
--tcp-output-addr [HOSTNAME:PORT] Forward packets from --multicast-addr to TCP downstream
--udp_output_addr [HOSTNAME:PORT] Forward packets from --multicast-addr to UDP downstream
FLAGS:
-h, --help Prints help information
-t, --tee Print UDP input to stdout
EXAMPLE:
reverse_proxy --udp-listen-addr '0.0.0.0:9920' --tcp-output-addr '[::1]:9921' --multicast-addr '224.0.0.1:9922'
服务器
MPROXY: UDP Server
Listen for incoming UDP messages and log to file.
USAGE:
mproxy-server [FLAGS] [OPTIONS] ...
OPTIONS:
--path [FILE_DESCRIPTOR] Filepath, descriptor, or handle.
--listen-addr [SOCKET_ADDR] Upstream UDP listening address. May be repeated
FLAGS:
-h, --help Prints help information
-t, --tee Copy input to stdout
EXAMPLE:
mproxy-server --path logfile.log --listen-addr '127.0.0.1:9920' --listen-addr '[::1]:9921'
动机
- 完整的、但基本的分布式网络框架,例如用于遥测或传感器数据
- 零配置、简单操作和部署
- 利用UDP协议的优势
- 能够合并来自多个源的数据流
- 流复用和重新分配
- UDP多播使无状态、可扩展的反向代理成为可能
- 优先考虑跨兼容性、简单性、安全性和性能
替代方案
依赖项
~0.4–29MB
~435K SLoC