@ -408,10 +408,9 @@ type updateStats struct {
// removeUnwantedDiscoUpdates goes over the patchified updates and reject items
// removeUnwantedDiscoUpdates goes over the patchified updates and reject items
// where the node is offline and has last been seen before the recorded last seen.
// where the node is offline and has last been seen before the recorded last seen.
func ( ms * mapSession ) removeUnwantedDiscoUpdates ( resp * tailcfg . MapResponse ) {
func ( ms * mapSession ) removeUnwantedDiscoUpdates ( resp * tailcfg . MapResponse ) {
existingMap := ms . netmap ( )
ms . peersMu . RLock ( )
if existingMap == nil {
defer ms . peersMu . RUnlock ( )
return
}
acceptedDiscoUpdates := resp . PeersChangedPatch [ : 0 ]
acceptedDiscoUpdates := resp . PeersChangedPatch [ : 0 ]
for _ , change := range resp . PeersChangedPatch {
for _ , change := range resp . PeersChangedPatch {
@ -430,14 +429,13 @@ func (ms *mapSession) removeUnwantedDiscoUpdates(resp *tailcfg.MapResponse) {
continue
continue
}
}
peerIdx := existingMap . PeerIndexByNodeID ( change . NodeID )
existingNode , ok := ms . peers [ change . NodeID ]
// Accept if:
// Accept if:
// - Cannot find the peer, don't have enough data
// - Cannot find the peer, don't have enough data
if peerIdx < 0 {
if ! ok {
acceptedDiscoUpdates = append ( acceptedDiscoUpdates , change )
acceptedDiscoUpdates = append ( acceptedDiscoUpdates , change )
continue
continue
}
}
existingNode := existingMap . Peers [ peerIdx ]
// Accept if:
// Accept if:
// - lastSeen moved forward in time.
// - lastSeen moved forward in time.
@ -456,13 +454,12 @@ func (ms *mapSession) removeUnwantedDiscoUpdates(resp *tailcfg.MapResponse) {
// local netmap has a newer key learned via TSMP, overwrite the update with the
// local netmap has a newer key learned via TSMP, overwrite the update with the
// key from TSMP.
// key from TSMP.
func ( ms * mapSession ) removeUnwantedDiscoUpdatesFromFullNetmapUpdate ( resp * tailcfg . MapResponse ) {
func ( ms * mapSession ) removeUnwantedDiscoUpdatesFromFullNetmapUpdate ( resp * tailcfg . MapResponse ) {
ms . peersMu . RLock ( )
defer ms . peersMu . RUnlock ( )
if len ( resp . Peers ) == 0 {
if len ( resp . Peers ) == 0 {
return
return
}
}
existingMap := ms . netmap ( )
if existingMap == nil {
return
}
for _ , peer := range resp . Peers {
for _ , peer := range resp . Peers {
if peer . DiscoKey . IsZero ( ) {
if peer . DiscoKey . IsZero ( ) {
continue
continue
@ -470,14 +467,13 @@ func (ms *mapSession) removeUnwantedDiscoUpdatesFromFullNetmapUpdate(resp *tailc
// Accept if:
// Accept if:
// - peer is new
// - peer is new
peerIdx := existingMap . PeerIndexByNodeID ( peer . ID )
existingNode , ok := ms . peers [ peer . ID ]
if peerIdx < 0 {
if ! ok {
continue
continue
}
}
// Accept if:
// Accept if:
// - disco key has not changed
// - disco key has not changed
existingNode := existingMap . Peers [ peerIdx ]
if existingNode . DiscoKey ( ) == peer . DiscoKey {
if existingNode . DiscoKey ( ) == peer . DiscoKey {
continue
continue
}
}