route/cmd/route-httpagent/main.go

47 lines
1.2 KiB
Go

package main
import (
"context"
"crypto/tls"
"flag"
"time"
"git.xeserv.us/xena/route/internal/tun2"
"github.com/Xe/ln"
"github.com/facebookgo/flagenv"
_ "github.com/joho/godotenv"
)
var (
token = flag.String("token", "", "authentication token used to authenticate with routed")
domain = flag.String("domain", "", "domain to use when authenticating with routed")
backend = flag.String("backend", "http://127.0.0.1:9090", "backend TCP/HTTP server route-httpagent should relay traffic to/from")
serverAddr = flag.String("server", "127.0.0.1:9234", "the address that routed is listening on for backend connections")
connMethod = flag.String("method", "tcp", "the connection method used to talk to routed (MUST be either 'tcp' or 'kcp')")
)
func main() {
flagenv.Parse()
flag.Parse()
cfg := &tun2.ClientConfig{
TLSConfig: &tls.Config{},
ConnType: *connMethod,
ServerAddr: *serverAddr,
Token: *token,
Domain: *domain,
BackendURL: *backend,
}
client, _ := tun2.NewClient(cfg)
for {
err := client.Connect(context.Background())
if err != nil {
ln.Error(context.Background(), err, ln.Action("client connection failed"))
}
time.Sleep(2 * time.Second)
}
}