diff --git a/cmd/httpagent/main.go b/cmd/httpagent/main.go index 001f70e..da10485 100644 --- a/cmd/httpagent/main.go +++ b/cmd/httpagent/main.go @@ -1,32 +1,39 @@ package main import ( + "crypto/tls" "flag" - "log" + "os" - "git.xeserv.us/xena/route/lib/tunnel" + "git.xeserv.us/xena/route/lib/tun2" + "github.com/Xe/ln" ) var ( token = flag.String("token", "", "Service identifier token") - backend = flag.String("backend", "127.0.0.1:9090", "backend TCP/HTTP server") - serverAddr = flag.String("server", "127.0.0.1:9234", "frontend HTTP server") + domain = flag.String("domain", "", "Domain to ID as") + backend = flag.String("backend", "http://127.0.0.1:9090", "backend TCP/HTTP server") + serverAddr = flag.String("server", "127.0.0.1:9234", "frontend KCP server") ) func main() { flag.Parse() - cfg := &tunnel.ClientConfig{ - Identifier: *token, - LocalAddr: *backend, + cfg := &tun2.ClientConfig{ + TLSConfig: &tls.Config{}, + ConnType: "kcp", ServerAddr: *serverAddr, - Debug: true, + Token: *token, + Domain: *domain, + BackendURL: *backend, } - client, err := tunnel.NewClient(cfg) + client, _ := tun2.NewClient(cfg) + err := client.Connect() if err != nil { - log.Fatal(err) + ln.Error(err, ln.F{ + "action": "client_running", + }) + os.Exit(1) } - - client.Start() } diff --git a/lib/tun2/client.go b/lib/tun2/client.go index 54d110c..6f9eb37 100644 --- a/lib/tun2/client.go +++ b/lib/tun2/client.go @@ -38,6 +38,10 @@ func NewClient(cfg *ClientConfig) (*Client, error) { return c, nil } +func (c *Client) Connect() error { + return c.connect(c.cfg.ServerAddr) +} + func (c *Client) connect(serverAddr string) error { target, err := url.Parse(c.cfg.BackendURL) if err != nil {