net/udprelay{/endpoint}, all: move ServerEndpoint to independent pkg (#15934)

ServerEndpoint will be used within magicsock and potentially elsewhere,
which should be possible without needing to import the server
implementation itself.

Updates tailscale/corp#27502

Signed-off-by: Jordan Whited <jordan@tailscale.com>
This commit is contained in:
Jordan Whited
2025-05-09 11:29:36 -07:00
committed by GitHub
parent 7d6d2b4c50
commit 0841477743
7 changed files with 98 additions and 79 deletions
+5 -4
View File
@@ -17,6 +17,7 @@ import (
"go4.org/mem"
"tailscale.com/disco"
"tailscale.com/net/packet"
"tailscale.com/net/udprelay/endpoint"
"tailscale.com/tstime"
"tailscale.com/types/key"
)
@@ -259,7 +260,7 @@ func TestServerEndpointJSONUnmarshal(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var out ServerEndpoint
var out endpoint.ServerEndpoint
err := json.Unmarshal(tt.json, &out)
if tt.wantErr != (err != nil) {
t.Fatalf("wantErr: %v (err == nil): %v", tt.wantErr, err == nil)
@@ -274,11 +275,11 @@ func TestServerEndpointJSONUnmarshal(t *testing.T) {
func TestServerEndpointJSONMarshal(t *testing.T) {
tests := []struct {
name string
serverEndpoint ServerEndpoint
serverEndpoint endpoint.ServerEndpoint
}{
{
name: "valid roundtrip",
serverEndpoint: ServerEndpoint{
serverEndpoint: endpoint.ServerEndpoint{
ServerDisco: key.NewDisco().Public(),
LamportID: uint64(math.MaxUint64),
AddrPorts: []netip.AddrPort{netip.MustParseAddrPort("127.0.0.1:1"), netip.MustParseAddrPort("127.0.0.2:2")},
@@ -295,7 +296,7 @@ func TestServerEndpointJSONMarshal(t *testing.T) {
if err != nil {
t.Fatal(err)
}
var got ServerEndpoint
var got endpoint.ServerEndpoint
err = json.Unmarshal(b, &got)
if err != nil {
t.Fatal(err)