mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-23 05:49:07 +02:00
Persist Network Serial to Store to avoid outdated netmap sent (#260)
Fix outdated update coming from management even when it is actually not outdated.
This commit is contained in:
@@ -22,34 +22,34 @@ type Network struct {
|
||||
Id string
|
||||
Net net.IPNet
|
||||
Dns string
|
||||
// serial is an ID that increments by 1 when any change to the network happened (e.g. new peer has been added).
|
||||
// Serial is an ID that increments by 1 when any change to the network happened (e.g. new peer has been added).
|
||||
// Used to synchronize state to the client apps.
|
||||
serial uint64
|
||||
Serial uint64
|
||||
|
||||
mu sync.Mutex `json:"-"`
|
||||
}
|
||||
|
||||
// NewNetwork creates a new Network initializing it with a serial=0
|
||||
// NewNetwork creates a new Network initializing it with a Serial=0
|
||||
func NewNetwork() *Network {
|
||||
return &Network{
|
||||
Id: xid.New().String(),
|
||||
Net: net.IPNet{IP: net.ParseIP("100.64.0.0"), Mask: net.IPMask{255, 192, 0, 0}},
|
||||
Dns: "",
|
||||
serial: 0}
|
||||
Serial: 0}
|
||||
}
|
||||
|
||||
// IncSerial increments serial by 1 reflecting that the network state has been changed
|
||||
// IncSerial increments Serial by 1 reflecting that the network state has been changed
|
||||
func (n *Network) IncSerial() {
|
||||
n.mu.Lock()
|
||||
defer n.mu.Unlock()
|
||||
n.serial = n.serial + 1
|
||||
n.Serial = n.Serial + 1
|
||||
}
|
||||
|
||||
// Serial returns the Network.serial of the network (latest state id)
|
||||
func (n *Network) Serial() uint64 {
|
||||
// CurrentSerial returns the Network.Serial of the network (latest state id)
|
||||
func (n *Network) CurrentSerial() uint64 {
|
||||
n.mu.Lock()
|
||||
defer n.mu.Unlock()
|
||||
return n.serial
|
||||
return n.Serial
|
||||
}
|
||||
|
||||
func (n *Network) Copy() *Network {
|
||||
@@ -57,7 +57,7 @@ func (n *Network) Copy() *Network {
|
||||
Id: n.Id,
|
||||
Net: n.Net,
|
||||
Dns: n.Dns,
|
||||
serial: n.serial,
|
||||
Serial: n.Serial,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user