use helper function for constructing state updates (#2410)
This helps preventing messages being sent with the wrong update type and payload combination, and it is shorter/neater. Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
parent
b92bd3d27e
commit
1f0110fe06
9 changed files with 56 additions and 107 deletions
|
@ -102,21 +102,41 @@ func (su *StateUpdate) Empty() bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func StateSelf(nodeID NodeID) StateUpdate {
|
||||
func UpdateFull() StateUpdate {
|
||||
return StateUpdate{
|
||||
Type: StateFullUpdate,
|
||||
}
|
||||
}
|
||||
|
||||
func UpdateSelf(nodeID NodeID) StateUpdate {
|
||||
return StateUpdate{
|
||||
Type: StateSelfUpdate,
|
||||
ChangeNodes: []NodeID{nodeID},
|
||||
}
|
||||
}
|
||||
|
||||
func StateUpdatePeerAdded(nodeIDs ...NodeID) StateUpdate {
|
||||
func UpdatePeerChanged(nodeIDs ...NodeID) StateUpdate {
|
||||
return StateUpdate{
|
||||
Type: StatePeerChanged,
|
||||
ChangeNodes: nodeIDs,
|
||||
}
|
||||
}
|
||||
|
||||
func StateUpdateExpire(nodeID NodeID, expiry time.Time) StateUpdate {
|
||||
func UpdatePeerPatch(changes ...*tailcfg.PeerChange) StateUpdate {
|
||||
return StateUpdate{
|
||||
Type: StatePeerChangedPatch,
|
||||
ChangePatches: changes,
|
||||
}
|
||||
}
|
||||
|
||||
func UpdatePeerRemoved(nodeIDs ...NodeID) StateUpdate {
|
||||
return StateUpdate{
|
||||
Type: StatePeerRemoved,
|
||||
Removed: nodeIDs,
|
||||
}
|
||||
}
|
||||
|
||||
func UpdateExpire(nodeID NodeID, expiry time.Time) StateUpdate {
|
||||
return StateUpdate{
|
||||
Type: StatePeerChangedPatch,
|
||||
ChangePatches: []*tailcfg.PeerChange{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue