mirror of
https://github.com/tim-beatham/smegmesh.git
synced 2025-06-20 19:57:49 +02:00
Merge pull request #30 from tim-beatham/29-only-ping-clients-who-have-updated-their-config
29-only-ping-clients-who-have-updated-their-config
This commit is contained in:
commit
f28ed8260d
@ -58,11 +58,30 @@ func (c *CrdtMeshManager) isPeer(nodeId string) bool {
|
|||||||
return nodeType.Str() == string(conf.PEER_ROLE)
|
return nodeType.Str() == string(conf.PEER_ROLE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isAlive: checks that the node's configuration has been updated
|
||||||
|
// since the rquired keep alive time
|
||||||
|
func (c *CrdtMeshManager) isAlive(nodeId string) bool {
|
||||||
|
node, err := c.doc.Path("nodes").Map().Get(nodeId)
|
||||||
|
|
||||||
|
if err != nil || node.Kind() != automerge.KindMap {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
timestamp, err := node.Map().Get("timestamp")
|
||||||
|
|
||||||
|
if err != nil || timestamp.Kind() != automerge.KindInt64 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
keepAliveTime := timestamp.Int64()
|
||||||
|
return (time.Now().Unix() - keepAliveTime) < int64(c.conf.DeadTime)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *CrdtMeshManager) GetPeers() []string {
|
func (c *CrdtMeshManager) GetPeers() []string {
|
||||||
keys, _ := c.doc.Path("nodes").Map().Keys()
|
keys, _ := c.doc.Path("nodes").Map().Keys()
|
||||||
|
|
||||||
keys = lib.Filter(keys, func(s string) bool {
|
keys = lib.Filter(keys, func(publicKey string) bool {
|
||||||
return c.isPeer(s)
|
return c.isPeer(publicKey) && c.isAlive(publicKey)
|
||||||
})
|
})
|
||||||
|
|
||||||
return keys
|
return keys
|
||||||
|
@ -64,8 +64,11 @@ type WgMeshConfiguration struct {
|
|||||||
KeepAliveTime int `yaml:"keepAliveTime"`
|
KeepAliveTime int `yaml:"keepAliveTime"`
|
||||||
// Timeout number of seconds before we consider the node as dead
|
// Timeout number of seconds before we consider the node as dead
|
||||||
Timeout int `yaml:"timeout"`
|
Timeout int `yaml:"timeout"`
|
||||||
// PruneTime number of seconds before we consider the 'node' as dead
|
// PruneTime number of seconds before we remove nodes that are likely to be dead
|
||||||
PruneTime int `yaml:"pruneTime"`
|
PruneTime int `yaml:"pruneTime"`
|
||||||
|
// DeadTime: number of seconds before we consider the node as dead and stop considering it
|
||||||
|
// when picking a random peer
|
||||||
|
DeadTime int `yaml:"deadTime"`
|
||||||
// Profile whether or not to include a http server that profiles the code
|
// Profile whether or not to include a http server that profiles the code
|
||||||
Profile bool `yaml:"profile"`
|
Profile bool `yaml:"profile"`
|
||||||
// StubWg whether or not to stub the WireGuard types
|
// StubWg whether or not to stub the WireGuard types
|
||||||
@ -145,9 +148,15 @@ func ValidateConfiguration(c *WgMeshConfiguration) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.PruneTime <= 1 {
|
if c.PruneTime < 1 {
|
||||||
return &WgMeshConfigurationError{
|
return &WgMeshConfigurationError{
|
||||||
msg: "Prune time cannot be <= 1",
|
msg: "Prune time cannot be < 1",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.DeadTime < 1 {
|
||||||
|
return &WgMeshConfigurationError{
|
||||||
|
msg: "Dead time cannot be < 1",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,6 +101,7 @@ type MeshProvider interface {
|
|||||||
// Prune: prunes all nodes that have not updated their timestamp in
|
// Prune: prunes all nodes that have not updated their timestamp in
|
||||||
// pruneAmount seconds
|
// pruneAmount seconds
|
||||||
Prune(pruneAmount int) error
|
Prune(pruneAmount int) error
|
||||||
|
// GetPeers: get a list of contactable peers
|
||||||
GetPeers() []string
|
GetPeers() []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user