feat(tunnel): log public tunnel url
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -3,6 +3,7 @@ package tunnel
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@@ -58,14 +59,31 @@ func NewClientTunnel(cfg *config.ClientConfig, forwarder Forwarder) (*Tunnel, er
|
|||||||
|
|
||||||
return &Tunnel{
|
return &Tunnel{
|
||||||
name: cfg.TunnelName,
|
name: cfg.TunnelName,
|
||||||
|
publicURL: publicTunnelURL(serverURL, cfg.TunnelName),
|
||||||
wsConn: serverConn,
|
wsConn: serverConn,
|
||||||
streams: maps.New[string, Stream](),
|
streams: maps.New[string, Stream](),
|
||||||
forwarder: forwarder,
|
forwarder: forwarder,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func publicTunnelURL(serverURL *url.URL, tunnelName string) string {
|
||||||
|
// Build Public Tunnel URL
|
||||||
|
host := serverURL.Hostname()
|
||||||
|
if host == "" {
|
||||||
|
host = serverURL.Host
|
||||||
|
}
|
||||||
|
|
||||||
|
publicHost := tunnelName + "." + host
|
||||||
|
if port := serverURL.Port(); port != "" {
|
||||||
|
publicHost = net.JoinHostPort(publicHost, port)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (&url.URL{Scheme: serverURL.Scheme, Host: publicHost}).String()
|
||||||
|
}
|
||||||
|
|
||||||
type Tunnel struct {
|
type Tunnel struct {
|
||||||
name string
|
name string
|
||||||
|
publicURL string
|
||||||
wsConn *websocket.Conn
|
wsConn *websocket.Conn
|
||||||
streams *maps.Map[string, Stream]
|
streams *maps.Map[string, Stream]
|
||||||
forwarder Forwarder
|
forwarder Forwarder
|
||||||
@@ -75,6 +93,9 @@ type Tunnel struct {
|
|||||||
|
|
||||||
func (t *Tunnel) Start(ctx context.Context) {
|
func (t *Tunnel) Start(ctx context.Context) {
|
||||||
log.Infof("initiated tunnel %q with %s", t.name, t.wsConn.RemoteAddr().String())
|
log.Infof("initiated tunnel %q with %s", t.name, t.wsConn.RemoteAddr().String())
|
||||||
|
if t.publicURL != "" {
|
||||||
|
log.Infof("tunnel available at %s", t.publicURL)
|
||||||
|
}
|
||||||
defer log.Infof("closed tunnel %q with %s", t.name, t.wsConn.RemoteAddr().String())
|
defer log.Infof("closed tunnel %q with %s", t.name, t.wsConn.RemoteAddr().String())
|
||||||
|
|
||||||
// Start Message Receiver
|
// Start Message Receiver
|
||||||
|
|||||||
Reference in New Issue
Block a user