Skip to content

Commit

Permalink
new signature
Browse files Browse the repository at this point in the history
  • Loading branch information
MayCXC authored Oct 23, 2024
1 parent c357e48 commit afda8ef
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions module.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func init() {
caddy.RegisterNetwork("tailscale", getTCPListener)
caddy.RegisterNetwork("tailscale+tls", getTLSListener)
caddy.RegisterNetwork("tailscale/udp", getUDPListener)
caddyhttp.RegisterNetworkHTTP3("tailscale/udp", "tailscale/udp")
caddyhttp.RegisterNetworkHTTP3("tailscale", "tailscale/udp")

// Caddy uses tscert to get certificates for Tailscale hostnames.
Expand All @@ -43,12 +44,18 @@ func init() {
hostinfo.SetApp("caddy")
}

func getTCPListener(c context.Context, _ string, addr string, _ net.ListenConfig) (any, error) {
func getTCPListener(c context.Context, network string, host string, portRange string, portOffset uint, _ net.ListenConfig) (any, error) {
ctx, ok := c.(caddy.Context)
if !ok {
return nil, fmt.Errorf("context is not a caddy.Context: %T", c)
}


na, err := caddy.JoinNetworkAddress(network, host, portRange)
if err != nil {
return nil, err
}

addr := na.JoinHostPort(portOffset)
network, host, port, err := caddy.SplitNetworkAddress(addr)
if err != nil {
return nil, err
Expand All @@ -65,12 +72,18 @@ func getTCPListener(c context.Context, _ string, addr string, _ net.ListenConfig
return s.Listen(network, ":"+port)
}

func getTLSListener(c context.Context, _ string, addr string, _ net.ListenConfig) (any, error) {
func getTLSListener(c context.Context, network string, host string, portRange string, portOffset uint, _ net.ListenConfig) (any, error) {
ctx, ok := c.(caddy.Context)
if !ok {
return nil, fmt.Errorf("context is not a caddy.Context: %T", c)
}

na, err := caddy.JoinNetworkAddress(network, host, portRange)
if err != nil {
return nil, err
}

addr := na.JoinHostPort(portOffset)
network, host, port, err := caddy.SplitNetworkAddress(addr)
if err != nil {
return nil, err
Expand Down Expand Up @@ -98,12 +111,18 @@ func getTLSListener(c context.Context, _ string, addr string, _ net.ListenConfig
return ln, nil
}

func getUDPListener(c context.Context, _ string, addr string, _ net.ListenConfig) (any, error) {
func getUDPListener(c context.Context, network string, host string, portRange string, portOffset uint, _ net.ListenConfig) (any, error) {
ctx, ok := c.(caddy.Context)
if !ok {
return nil, fmt.Errorf("context is not a caddy.Context: %T", c)
}

na, err := caddy.JoinNetworkAddress(network, host, portRange)
if err != nil {
return nil, err
}

addr := na.JoinHostPort(portOffset)
network, host, port, err := caddy.SplitNetworkAddress(addr)
if err != nil {
return nil, err
Expand Down

0 comments on commit afda8ef

Please sign in to comment.