Skip to content

Commit

Permalink
feat: support relay udp (Ehco1996#361)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ehco1996 authored Aug 16, 2024
1 parent 33207dc commit 2f2331a
Show file tree
Hide file tree
Showing 38 changed files with 835 additions and 1,348 deletions.
36 changes: 0 additions & 36 deletions examples/block.json

This file was deleted.

15 changes: 0 additions & 15 deletions examples/cf-ws.json

This file was deleted.

62 changes: 16 additions & 46 deletions examples/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,71 +9,41 @@
"listen_type": "raw",
"transport_type": "raw",
"label": "relay1",
"tcp_remotes": ["0.0.0.0:5201"],
"udp_remotes": ["0.0.0.0:5201"]
"tcp_remotes": [
"0.0.0.0:5201"
]
},
{
"listen": "127.0.0.1:1235",
"listen_type": "raw",
"transport_type": "ws",
"tcp_remotes": ["ws://0.0.0.0:2443"],
"udp_remotes": ["0.0.0.0:5201"]
"tcp_remotes": [
"ws://0.0.0.0:2443"
]
},
{
"listen": "127.0.0.1:1236",
"listen_type": "raw",
"transport_type": "wss",
"tcp_remotes": ["wss://0.0.0.0:3443"],
"udp_remotes": ["0.0.0.0:5201"]
},
{
"listen": "127.0.0.1:1237",
"listen_type": "raw",
"transport_type": "mwss",
"tcp_remotes": ["wss://0.0.0.0:4443"],
"udp_remotes": ["0.0.0.0:5201"]
},
{
"listen": "127.0.0.1:1238",
"listen_type": "raw",
"transport_type": "mtcp",
"tcp_remotes": ["0.0.0.0:4444"],
"udp_remotes": ["0.0.0.0:5201"]
"tcp_remotes": [
"wss://0.0.0.0:3443"
]
},
{
"listen": "127.0.0.1:2443",
"listen_type": "ws",
"transport_type": "raw",
"tcp_remotes": ["0.0.0.0:5201"],
"udp_remotes": []
"tcp_remotes": [
"0.0.0.0:5201"
]
},
{
"listen": "127.0.0.1:3443",
"listen_type": "wss",
"transport_type": "raw",
"tcp_remotes": ["0.0.0.0:5201"],
"udp_remotes": []
},
{
"listen": "127.0.0.1:4443",
"listen_type": "mwss",
"transport_type": "raw",
"tcp_remotes": ["0.0.0.0:5201"],
"udp_remotes": []
},
{
"listen": "127.0.0.1:4444",
"listen_type": "mtcp",
"transport_type": "raw",
"tcp_remotes": ["0.0.0.0:5201"],
"udp_remotes": []
},
{
"label": "ping_test",
"listen": "127.0.0.1:8888",
"listen_type": "raw",
"transport_type": "raw",
"tcp_remotes": ["8.8.8.8:5201", "google.com:5201"]
"tcp_remotes": [
"0.0.0.0:5201"
]
}
]
}
}
23 changes: 0 additions & 23 deletions examples/mptcp.json

This file was deleted.

24 changes: 0 additions & 24 deletions examples/mws.json

This file was deleted.

14 changes: 0 additions & 14 deletions examples/speed_limit.json

This file was deleted.

20 changes: 0 additions & 20 deletions examples/sub.json

This file was deleted.

16 changes: 0 additions & 16 deletions examples/web.json

This file was deleted.

29 changes: 0 additions & 29 deletions examples/with_ping.json

This file was deleted.

24 changes: 0 additions & 24 deletions examples/ws_config.json

This file was deleted.

14 changes: 0 additions & 14 deletions internal/cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/Ehco1996/ehco/internal/metrics"
"github.com/Ehco1996/ehco/internal/relay"
"github.com/Ehco1996/ehco/internal/relay/conf"
"github.com/Ehco1996/ehco/internal/tls"
"github.com/Ehco1996/ehco/internal/web"
"github.com/Ehco1996/ehco/pkg/buffer"
"github.com/Ehco1996/ehco/pkg/log"
Expand Down Expand Up @@ -42,24 +41,11 @@ func loadConfig() (cfg *config.Config, err error) {
if TCPRemoteAddr != "" {
cfg.RelayConfigs[0].TCPRemotes = []string{TCPRemoteAddr}
}
if UDPRemoteAddr != "" {
cfg.RelayConfigs[0].UDPRemotes = []string{UDPRemoteAddr}
}
if err := cfg.Adjust(); err != nil {
return nil, err
}
}

// init tls when need
for _, cfg := range cfg.RelayConfigs {
if cfg.ListenType == constant.RelayTypeWSS || cfg.ListenType == constant.RelayTypeMWSS ||
cfg.TransportType == constant.RelayTypeWSS || cfg.TransportType == constant.RelayTypeMWSS {
if err := tls.InitTlsCfg(); err != nil {
return nil, err
}
break
}
}
return cfg, nil
}

Expand Down
9 changes: 1 addition & 8 deletions internal/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ var (
LocalAddr string
ListenType constant.RelayType
TCPRemoteAddr string
UDPRemoteAddr string
TransportType constant.RelayType
ConfigPath string
WebPort int
Expand Down Expand Up @@ -39,16 +38,10 @@ var RootFlags = []cli.Flag{
},
&cli.StringFlag{
Name: "r,remote",
Usage: "TCP 转发地址,例如 0.0.0.0:5201,通过 ws 隧道转发时应为 ws://0.0.0.0:2443",
Usage: "转发地址,例如 0.0.0.0:5201,通过 ws 隧道转发时应为 ws://0.0.0.0:2443",
EnvVars: []string{"EHCO_REMOTE_ADDR"},
Destination: &TCPRemoteAddr,
},
&cli.StringFlag{
Name: "ur,udp_remote",
Usage: "UDP 转发地址,例如 0.0.0.0:1234",
EnvVars: []string{"EHCO_UDP_REMOTE_ADDR"},
Destination: &UDPRemoteAddr,
},
&cli.StringFlag{
Name: "tt,transport_type",
Value: "raw",
Expand Down
3 changes: 2 additions & 1 deletion internal/cmgr/cmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const (
ConnectionTypeClosed = "closed"
)

// connection manager interface
// connection manager interface/
// TODO support closed connection
type Cmgr interface {
ListConnections(connType string, page, pageSize int) []conn.RelayConn

Expand Down
14 changes: 12 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (
"strings"
"time"

myhttp "github.com/Ehco1996/ehco/pkg/http"

"github.com/Ehco1996/ehco/internal/constant"
"github.com/Ehco1996/ehco/internal/relay/conf"
"github.com/Ehco1996/ehco/internal/tls"
myhttp "github.com/Ehco1996/ehco/pkg/http"
"github.com/Ehco1996/ehco/pkg/sub"
xConf "github.com/xtls/xray-core/infra/conf"
"go.uber.org/zap"
Expand Down Expand Up @@ -121,6 +122,15 @@ func (c *Config) Adjust() error {
}
labelMap[r.Label] = struct{}{}
}
// init tls when need
for _, r := range c.RelayConfigs {
if r.ListenType == constant.RelayTypeWSS {
if err := tls.InitTlsCfg(); err != nil {
return err
}
break
}
}
return nil
}

Expand Down
Loading

0 comments on commit 2f2331a

Please sign in to comment.