mirror of
https://github.com/Drop-OSS/libtailscale.git
synced 2026-01-30 20:55:18 +01:00
updates tailscale/tailscale#13937 Builds a TailscaleKit.framework which wraps libtailscale.a in an actor, providing IncomingConnection, Listener, and OutgoingConnection types which are more usable in pure async Swift code. The method signatures are intended to be similar in form to NWConnection. We also provide an extension to URLSession so you can make URL requests via the user-space proxy. Adds a static library mirroring much of the test control utilities in go, minus the dependency on testing, so that we can export the signatures and link it to tests that cannot run in go. Added functionality to get both the local interface IPs as well as the remote IP of incoming connections accepted by a listener. Fixed a bug in the log writer so we append a newline. This also updates to the latest go toolchain and tailscale version. Signed-off-by: Jonathan Nobels <jonathan@tailscale.com>
80 lines
1.6 KiB
Go
80 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/tailscale/libtailscale/tsnetctest"
|
|
)
|
|
|
|
func TestConn(t *testing.T) {
|
|
tsnetctest.RunTestConn(t)
|
|
|
|
// RunTestConn cleans up after itself, so there shouldn't be
|
|
// anything left in the global maps.
|
|
|
|
servers.mu.Lock()
|
|
rem := len(servers.m)
|
|
servers.mu.Unlock()
|
|
|
|
if rem > 0 {
|
|
t.Fatalf("want no remaining tsnet objects, got %d", rem)
|
|
}
|
|
|
|
var remConns, remLns int
|
|
|
|
for i := 0; i < 50; i++ {
|
|
conns.mu.Lock()
|
|
remConns = len(conns.m)
|
|
conns.mu.Unlock()
|
|
|
|
listeners.mu.Lock()
|
|
remLns = len(listeners.m)
|
|
listeners.mu.Unlock()
|
|
|
|
if remConns == 0 && remLns == 0 {
|
|
break
|
|
}
|
|
|
|
// We are waiting for cleanup goroutines to finish.
|
|
//
|
|
// libtailscale closes one side of a socketpair and
|
|
// then Go responds to the other side being unreadable
|
|
// by closing the connections and listeners.
|
|
//
|
|
// This is inherently asynchronous.
|
|
// Without ditching the standard close(2) and having our
|
|
// own close functions.
|
|
//
|
|
// So we spin for a while
|
|
time.Sleep(100 * time.Millisecond)
|
|
}
|
|
|
|
if remConns > 0 {
|
|
t.Errorf("want no remaining tsnet_conn objects, got %d", remConns)
|
|
}
|
|
|
|
if remLns > 0 {
|
|
t.Errorf("want no remaining tsnet_listener objects, got %d", remLns)
|
|
}
|
|
}
|
|
|
|
func TestExtractIP(t *testing.T) {
|
|
ipv4 := "1.23.33.4:12343"
|
|
ipv6 := "[1::2234::34fc::44]:56576"
|
|
|
|
got4 := extractIP(ipv4)
|
|
got6 := extractIP(ipv6)
|
|
|
|
want4 := "1.23.33.4"
|
|
want6 := "[1::2234::34fc::44]"
|
|
|
|
if got4 != want4 {
|
|
t.Errorf("ipv4 port stripping failed")
|
|
}
|
|
|
|
if got6 != want6 {
|
|
t.Errorf("ipv6 port stripping failed %s != %s", got6, want6)
|
|
}
|
|
}
|