@ -4104,6 +4104,11 @@ var (
metricUDPLifetimeCycleCompleteAt10sCliff = newUDPLifetimeCounter ( "magicsock_udp_lifetime_cycle_complete_at_10s_cliff" )
metricUDPLifetimeCycleCompleteAt30sCliff = newUDPLifetimeCounter ( "magicsock_udp_lifetime_cycle_complete_at_30s_cliff" )
metricUDPLifetimeCycleCompleteAt60sCliff = newUDPLifetimeCounter ( "magicsock_udp_lifetime_cycle_complete_at_60s_cliff" )
// TSMP disco key exchange
metricTSMPDiscoKeyAdvertisementReceived = clientmetric . NewCounter ( "magicsock_tsmp_disco_key_advertisement_received" )
metricTSMPDiscoKeyAdvertisementApplied = clientmetric . NewCounter ( "magicsock_tsmp_disco_key_advertisement_applied" )
metricTSMPDiscoKeyAdvertisementUnchanged = clientmetric . NewCounter ( "magicsock_tsmp_disco_key_advertisement_unchanged" )
)
// newUDPLifetimeCounter returns a new *clientmetric.Metric with the provided
@ -4264,3 +4269,40 @@ func (c *Conn) PeerRelays() set.Set[netip.Addr] {
}
return servers
}
// HandleDiscoKeyAdvertisement processes a TSMP disco key update.
// The update may be solicited (in response to a request) or unsolicited.
// node is the Tailscale tailcfg.NodeView of the peer that sent the update.
func ( c * Conn ) HandleDiscoKeyAdvertisement ( node tailcfg . NodeView , update packet . TSMPDiscoKeyAdvertisement ) {
discoKey := update . Key
c . logf ( "magicsock: received disco key update %v from %v" , discoKey . ShortString ( ) , node . StableID ( ) )
metricTSMPDiscoKeyAdvertisementReceived . Add ( 1 )
c . mu . Lock ( )
defer c . mu . Unlock ( )
nodeKey := node . Key ( )
ep , ok := c . peerMap . endpointForNodeKey ( nodeKey )
if ! ok {
c . logf ( "magicsock: endpoint not found for node %v" , nodeKey . ShortString ( ) )
return
}
oldDiscoKey := key . DiscoPublic { }
if epDisco := ep . disco . Load ( ) ; epDisco != nil {
oldDiscoKey = epDisco . key
}
// If the key did not change, count it and return.
if oldDiscoKey . Compare ( discoKey ) == 0 {
metricTSMPDiscoKeyAdvertisementUnchanged . Add ( 1 )
return
}
c . discoInfoForKnownPeerLocked ( discoKey )
ep . disco . Store ( & endpointDisco {
key : discoKey ,
short : discoKey . ShortString ( ) ,
} )
c . peerMap . upsertEndpoint ( ep , oldDiscoKey )
c . logf ( "magicsock: updated disco key for peer %v to %v" , nodeKey . ShortString ( ) , discoKey . ShortString ( ) )
metricTSMPDiscoKeyAdvertisementApplied . Add ( 1 )
}