Skip to content

Commit

Permalink
ctl: fix some bugs Docs (or detailed usage help) needed #96
Browse files Browse the repository at this point in the history
  • Loading branch information
Ehco1996 committed Apr 16, 2022
1 parent e9e4ea6 commit a9b4ecc
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 33 deletions.
24 changes: 10 additions & 14 deletions cmd/ehco/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

var LocalAddr string
var ListenType string
var RemoteAddr string
var TCPRemoteAddr string
var UDPRemoteAddr string
var TransportType string
var ConfigPath string
Expand Down Expand Up @@ -64,61 +64,53 @@ func createCliAPP() *cli.App {
&cli.StringFlag{
Name: "l,local",
Usage: "监听地址,例如 0.0.0.0:1234",
EnvVars: []string{"EHCO_LOCAL_ADDR"},

This comment has been minimized.

Copy link
@Gkirito

Gkirito Apr 20, 2022

Contributor

为什么要移除EnvVars呀,docker-compose file中使用environment放入环境变量,运行的时候直接错误了,因为获取不到EHCO_LOCAL_ADDR

This comment has been minimized.

Copy link
@Ehco1996

Ehco1996 Apr 20, 2022

Author Owner

嗷嗷的确。可以提个 pr 修一下

This comment has been minimized.

Copy link
@Ehco1996

Ehco1996 Apr 20, 2022

Author Owner

顺手就删了...

This comment has been minimized.

Copy link
@Gkirito

Gkirito Apr 20, 2022

Contributor

嗷嗷的确。可以提个 pr 修一下

可以的,跑了台机器,突然报错,查的我怀疑人生👾

This comment has been minimized.

Copy link
@Ehco1996

Ehco1996 Apr 20, 2022

Author Owner

所以生产环境要用release 版本的 tag, (一直用 master 可能随时 GG

This comment has been minimized.

Copy link
@Gkirito

Gkirito Apr 20, 2022

Contributor

所以生产环境要用release 版本的 tag, (一直用 master 可能随时 GG

我切回了tag v1.1.1,似乎还有问题:standard_init_linux.go:228: exec user process caused: exec format error
暂时还没看是哪边造成的,但是v1.1.1是4个月前的的image,我在v1.1.1之后的代码和这次commit之前有跑过,没啥问题

This comment has been minimized.

Copy link
@Ehco1996

Ehco1996 Apr 20, 2022

Author Owner

这个应该是 build 镜像的问题,你是在 arm 上跑的么

This comment has been minimized.

Copy link
@Gkirito

Gkirito Apr 20, 2022

Contributor

只要第一次跑没问题就没啥事hhh,毕竟目前docker的imagePullPolicy是ifPresent

This comment has been minimized.

Copy link
@Gkirito

Gkirito Apr 20, 2022

Contributor

这个应该是 build 镜像的问题,你是在 arm 上跑的么

不是吧,我跑了台轻量阿里云

This comment has been minimized.

Copy link
@Gkirito

Gkirito Apr 20, 2022

Contributor

嗷嗷的确。可以提个 pr 修一下

#100

Destination: &LocalAddr,
Required: true,
},
&cli.StringFlag{
Name: "lt,listen_type",
Value: "raw",
Usage: "监听类型,可选项有 raw,ws,wss,mwss",
EnvVars: []string{"EHCO_LISTEN_TYPE"},
Destination: &ListenType,
Required: false,
},
&cli.StringFlag{
Name: "r,remote",
Usage: "TCP 转发地址,例如 0.0.0.0:5201,通过 ws 隧道转发时应为 ws://0.0.0.0:2443",
EnvVars: []string{"EHCO_REMOTE_ADDR"},
Destination: &RemoteAddr,
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",
Usage: "传输类型,可选选有 raw,ws,wss,mwss",
EnvVars: []string{"EHCO_TRANSPORT_TYPE"},
Destination: &TransportType,
Required: false,
},
&cli.StringFlag{
Name: "c,config",
Usage: "配置文件地址",
Usage: "配置文件地址,支持文件类型或 http api",
Destination: &ConfigPath,
},
&cli.IntFlag{
Name: "web_port",
Usage: "prometheus web expoter 的监听端口",
EnvVars: []string{"EHCO_WEB_PORT"},
Value: 0,
Destination: &WebPort,
},
&cli.BoolFlag{
Name: "enable_ping",
Usage: "是否打开 ping metrics",
EnvVars: []string{"EHCO_ENABLE_PING"},
Value: true,
Destination: &EnablePing,
},
&cli.StringFlag{
Name: "web_token",
Usage: "访问web的token,如果访问不带着正确的token,会直接reset连接",
EnvVars: []string{"EHCO_WEB_TOKEN"},
Usage: "如果访问webui时不带着正确的token,会直接reset连接",
Destination: &WebToken,
},
}
Expand Down Expand Up @@ -164,11 +156,13 @@ func loadConfig() (cfg *config.Config, err error) {
{
Listen: LocalAddr,
ListenType: ListenType,
TCPRemotes: []string{RemoteAddr},
TransportType: TransportType,
},
},
}
if TCPRemoteAddr != "" {
cfg.RelayConfigs[0].TCPRemotes = []string{TCPRemoteAddr}
}
if UDPRemoteAddr != "" {
cfg.RelayConfigs[0].UDPRemotes = []string{UDPRemoteAddr}
}
Expand Down Expand Up @@ -337,5 +331,7 @@ func main() {
// register start command
app.Action = start
// main thread start
logger.Fatal(app.Run(os.Args))
if err := app.Run(os.Args); err != nil {
logger.Fatal(err)
}
}
17 changes: 15 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/http"
Expand Down Expand Up @@ -41,8 +42,20 @@ func (r *RelayConfig) Validate() error {
return fmt.Errorf("invalid listen:%s", r.Listen)
}

if len(r.TCPRemotes) == 0 {
return fmt.Errorf("invalid remote:%s", r.TCPRemotes)
for _, addr := range r.TCPRemotes {
if addr == "" {
return fmt.Errorf("invalid tcp remote addr:%s", addr)
}
}

for _, addr := range r.UDPRemotes {
if addr == "" {
return fmt.Errorf("invalid udp remote addr:%s", addr)
}
}

if len(r.TCPRemotes) == 0 && len(r.UDPRemotes) == 0 {
return errors.New("both tcp and udp remotes are empty")
}
return nil
}
Expand Down
37 changes: 20 additions & 17 deletions internal/relay/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,26 @@ func (r *Relay) ListenAndServe() error {
})

errCh := make(chan error)
switch r.ListenType {
case constant.Listen_RAW:
go func() {
errCh <- r.RunLocalTCPServer()
}()
case constant.Listen_WS:
go func() {
errCh <- r.RunLocalWSServer()
}()
case constant.Listen_WSS:
go func() {
errCh <- r.RunLocalWSSServer()
}()
case constant.Listen_MWSS:
go func() {
errCh <- r.RunLocalMWSSServer()
}()

if len(r.cfg.TCPRemotes) > 0 {
switch r.ListenType {
case constant.Listen_RAW:
go func() {
errCh <- r.RunLocalTCPServer()
}()
case constant.Listen_WS:
go func() {
errCh <- r.RunLocalWSServer()
}()
case constant.Listen_WSS:
go func() {
errCh <- r.RunLocalWSSServer()
}()
case constant.Listen_MWSS:
go func() {
errCh <- r.RunLocalMWSSServer()
}()
}
}

if len(r.cfg.UDPRemotes) > 0 {
Expand Down

0 comments on commit a9b4ecc

Please sign in to comment.