Skip to content
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
59 changes: 56 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Welcome to the **`Backhaul`** project! This project provides a high-performance
- [TCP Configuration](#tcp-configuration)
- [TCP Multiplexing Configuration](#tcp-multiplexing-configuration)
- [UDP Configuration](#udp-configuration)
- [QUIC Configuration](#quic-configuration)
- [WebSocket Configuration](#websocket-configuration)
- [Secure WebSocket Configuration](#secure-websocket-configuration)
- [WS Multiplexing Configuration](#ws-multiplexing-configuration)
Expand All @@ -36,7 +37,7 @@ This project offers a robust reverse tunneling solution to overcome NAT and fire
## Features

* **High Performance**: Optimized for handling massive concurrent connections efficiently.
* **Protocol Flexibility**: Supports TCP, WebSocket (WS), and Secure WebSocket (WSS) transports.
* **Protocol Flexibility**: Supports TCP, UDP, QUIC, WebSocket (WS), and Secure WebSocket (WSS) transports.
* **UDP over TCP**: Implements UDP traffic encapsulation and forwarding over a TCP connection for reliable delivery with built-in congestion control.
* **Multiplexing**: Enables multiple connections over a single transport with SMUX.
* **NAT & Firewall Bypass**: Overcomes restrictions with reverse tunneling.
Expand Down Expand Up @@ -84,7 +85,7 @@ To start using the solution, you'll need to configure both server and client com
```toml
[server]# Local, IRAN
bind_addr = "0.0.0.0:3080" # Address and port for the server to listen on (mandatory).
transport = "tcp" # Protocol to use ("tcp", "tcpmux", "ws", "wss", "wsmux", "wssmux". mandatory).
transport = "tcp" # Protocol to use ("tcp", "tcpmux", "ws", "wss", "wsmux", "wssmux", "udp", "quic". mandatory).
accept_udp = false # Enable transferring UDP connections over TCP transport. (optional, default: false)
token = "your_token" # Authentication token for secure communication (optional).
keepalive_period = 75 # Interval in seconds to send keep-alive packets.(optional, default: 75s)
Expand Down Expand Up @@ -134,7 +135,7 @@ To start using the solution, you'll need to configure both server and client com
[client] # Behind NAT, firewall-blocked
remote_addr = "0.0.0.0:3080" # Server address and port (mandatory).
edge_ip = "188.114.96.0" # Edge IP used for CDN connection, specifically for WebSocket-based transports.(Optional, default none)
transport = "tcp" # Protocol to use ("tcp", "tcpmux", "ws", "wss", "wsmux", "wssmux". mandatory).
transport = "tcp" # Protocol to use ("tcp", "tcpmux", "ws", "wss", "wsmux", "wssmux", "udp", "quic". mandatory).
token = "your_token" # Authentication token for secure communication (optional).
connection_pool = 8 # Number of pre-established connections.(optional, default: 8).
aggressive_pool = false # Enables aggressive connection pool management.(optional, default: false).
Expand Down Expand Up @@ -299,6 +300,58 @@ To start using the solution, you'll need to configure both server and client com

```

#### QUIC Configuration
* **Server**:

```toml
[server]
bind_addr = "0.0.0.0:443"
transport = "quic"
token = "your_token"
heartbeat = 40
channel_size = 2048
sniffer = false
web_port = 2060
sniffer_log = "/root/backhaul.json"
log_level = "info"
ports = ["80", "8080", "443=127.0.0.1:8443"]
tls_cert = "/path/to/cert.pem" # Optional: TLS certificate file
tls_key = "/path/to/key.pem" # Optional: TLS private key file
```

* **Client**:

```toml
[client]
remote_addr = "your-server.com:443"
transport = "quic"
token = "your_token"
connection_pool = 8
aggressive_pool = false
retry_interval = 3
dial_timeout = 10
sniffer = false
web_port = 2060
sniffer_log = "/root/backhaul.json"
log_level = "info"
```

**QUIC Features:**
- Built on QUIC protocol for improved performance and reliability
- Automatic connection multiplexing over a single QUIC connection
- TLS 1.3 encryption by default
- Low latency and fast connection establishment (0-RTT support)
- Better handling of network changes and mobility
- Efficient use of network resources
- If no TLS certificates are provided, self-signed certificates are generated automatically

**Notes:**
- QUIC requires UDP connectivity between client and server
- Default port is 443 (HTTPS) but you can use any port
- QUIC provides better performance than TCP in high-latency or lossy networks
- Ideal for scenarios with frequent network changes or mobile connections

```
#### WebSocket Configuration
* **Server**:

Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const (
WSMUX TransportType = "wsmux"
WSSMUX TransportType = "wssmux"
UDP TransportType = "udp"
QUIC TransportType = "quic"
)

// ServerConfig represents the configuration for the server.
Expand Down
7 changes: 7 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.23.1
require (
github.com/BurntSushi/toml v1.4.0
github.com/gorilla/websocket v1.5.3
github.com/quic-go/quic-go v0.54.0
github.com/shirou/gopsutil/v4 v4.24.8
github.com/sirupsen/logrus v1.9.3
github.com/xtaci/smux v1.5.27
Expand All @@ -18,5 +19,11 @@ require (
github.com/tklauser/go-sysconf v0.3.14 // indirect
github.com/tklauser/numcpus v0.8.0 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
go.uber.org/mock v0.5.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/tools v0.22.0 // indirect
)
14 changes: 14 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw=
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
github.com/quic-go/quic-go v0.54.0 h1:6s1YB9QotYI6Ospeiguknbp2Znb/jZYjZLRXn9kMQBg=
github.com/quic-go/quic-go v0.54.0/go.mod h1:e68ZEaCdyviluZmy44P6Iey98v/Wfz6HCjQEm+l8zTY=
github.com/shirou/gopsutil/v4 v4.24.8 h1:pVQjIenQkIhqO81mwTaXjTzOMT7d3TZkf43PlVFHENI=
github.com/shirou/gopsutil/v4 v4.24.8/go.mod h1:wE0OrJtj4dG+hYkxqDH3QiBICdKSf04/npcvLLc/oRg=
github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM=
Expand All @@ -36,11 +38,23 @@ github.com/xtaci/smux v1.5.27 h1:uIU1dpJQQWUCmGxXBgajLfc8cMMb13hCitj+HC5yC/Q=
github.com/xtaci/smux v1.5.27/go.mod h1:OMlQbT5vcgl2gb49mFkYo6SMf+zP3rcjcwQz7ZU7IGY=
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
go.uber.org/mock v0.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU=
go.uber.org/mock v0.5.0/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM=
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0=
golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA=
golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
15 changes: 15 additions & 0 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,21 @@ func (c *Client) Start() {
udpClient := transport.NewUDPClient(c.ctx, udpConfig, c.logger)
go udpClient.Start()

case config.QUIC:
quicConfig := &transport.QuicConfig{
RemoteAddr: c.config.RemoteAddr,
RetryInterval: time.Duration(c.config.RetryInterval) * time.Second,
DialTimeOut: time.Duration(c.config.DialTimeout) * time.Second,
ConnPoolSize: c.config.ConnectionPool,
Token: c.config.Token,
Sniffer: c.config.Sniffer,
WebPort: c.config.WebPort,
SnifferLog: c.config.SnifferLog,
AggressivePool: c.config.AggressivePool,
}
quicClient := transport.NewQUICClient(c.ctx, quicConfig, c.logger)
go quicClient.Start()

default:
c.logger.Fatal("invalid transport type: ", c.config.Transport)
}
Expand Down
Loading