mirror of
https://github.com/tailscale/tailscale.git
synced 2025-05-26 01:08:30 +00:00

relayManager will eventually be responsible for handling the allocation and handshaking of UDP relay server endpoints. relay servers are endpoint-independent, and Conn must already maintain handshake state for all endpoints. This justifies a new data structure to fill these roles. Updates tailscale/corp#27502 Signed-off-by: Jordan Whited <jordan@tailscale.com>
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package magicsock
|
|
|
|
import (
|
|
"net/netip"
|
|
"sync"
|
|
|
|
"tailscale.com/disco"
|
|
"tailscale.com/types/key"
|
|
)
|
|
|
|
// relayManager manages allocation and handshaking of
|
|
// [tailscale.com/net/udprelay.Server] endpoints. The zero value is ready for
|
|
// use.
|
|
type relayManager struct {
|
|
mu sync.Mutex // guards the following fields
|
|
discoInfoByServerDisco map[key.DiscoPublic]*discoInfo
|
|
}
|
|
|
|
func (h *relayManager) initLocked() {
|
|
if h.discoInfoByServerDisco != nil {
|
|
return
|
|
}
|
|
h.discoInfoByServerDisco = make(map[key.DiscoPublic]*discoInfo)
|
|
}
|
|
|
|
// discoInfo returns a [*discoInfo] for 'serverDisco' if there is an
|
|
// active/ongoing handshake with it, otherwise it returns nil, false.
|
|
func (h *relayManager) discoInfo(serverDisco key.DiscoPublic) (_ *discoInfo, ok bool) {
|
|
h.mu.Lock()
|
|
defer h.mu.Unlock()
|
|
h.initLocked()
|
|
di, ok := h.discoInfoByServerDisco[serverDisco]
|
|
return di, ok
|
|
}
|
|
|
|
func (h *relayManager) handleCallMeMaybeVia(dm *disco.CallMeMaybeVia) {
|
|
h.mu.Lock()
|
|
defer h.mu.Unlock()
|
|
h.initLocked()
|
|
// TODO(jwhited): implement
|
|
}
|
|
|
|
func (h *relayManager) handleBindUDPRelayEndpointChallenge(dm *disco.BindUDPRelayEndpointChallenge, di *discoInfo, src netip.AddrPort, vni uint32) {
|
|
h.mu.Lock()
|
|
defer h.mu.Unlock()
|
|
h.initLocked()
|
|
// TODO(jwhited): implement
|
|
}
|