mirror of https://github.com/tailscale/tailscale/
wgengine/magicsock: shape relayManager and CallMeMaybeVia handling (#15864)
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>pull/15866/head
parent
761aea3036
commit
fd63123849
@ -0,0 +1,51 @@
|
||||
// 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
|
||||
}
|
||||
Loading…
Reference in New Issue