Skip to content

Commit

Permalink
add self node updates
Browse files Browse the repository at this point in the history
Signed-off-by: Kristoffer Dalby <[email protected]>
  • Loading branch information
kradalby committed Mar 6, 2024
1 parent db69083 commit f6b66f2
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions hscontrol/mapper/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,14 @@ func (m *Mapper) PeerChangedResponse(
resp.PeersChangedPatch = patches
}

// Add the node itself, it might have changed, and particularly
// if there are no patches or changes, this is a self update.
tailnode, err := tailNode(node, mapRequest.Version, pol, m.cfg)
if err != nil {
return nil, err
}
resp.Node = tailnode

return m.marshalMapResponse(mapRequest, &resp, node, mapRequest.Compress, messages...)
}

Expand Down Expand Up @@ -381,7 +389,7 @@ func (m *Mapper) marshalMapResponse(
switch {
case resp.Peers != nil && len(resp.Peers) > 0:
responseType = "full"
case isSelfUpdate(messages...):
case resp.Peers == nil && resp.PeersChanged == nil && resp.PeersChangedPatch == nil && resp.DERPMap == nil && !resp.KeepAlive:
responseType = "self"
case resp.PeersChanged != nil && len(resp.PeersChanged) > 0:
responseType = "changed"
Expand Down Expand Up @@ -592,13 +600,3 @@ func appendPeerChanges(

return nil
}

func isSelfUpdate(messages ...string) bool {
for _, message := range messages {
if strings.Contains(message, types.SelfUpdateIdentifier) {
return true
}
}

return false
}

0 comments on commit f6b66f2

Please sign in to comment.