add fallback for addresses
This commit is contained in:
parent
521af9429a
commit
8b75fb1b04
@ -25,6 +25,12 @@ As root:
|
|||||||
go get -v -u github.com/FreifunkBremen/yanic
|
go get -v -u github.com/FreifunkBremen/yanic
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### allow to ping
|
||||||
|
only needed if config has `nodes.ping_count` > 0
|
||||||
|
```sh
|
||||||
|
sudo setcap cap_net_raw=+ep /opt/go/bin/yanic
|
||||||
|
```
|
||||||
|
|
||||||
#### Work with other databases
|
#### Work with other databases
|
||||||
If you like to use another database solution than influxdb, Pull Requests are
|
If you like to use another database solution than influxdb, Pull Requests are
|
||||||
welcome. Just fork this project and create another subpackage within the folder
|
welcome. Just fork this project and create another subpackage within the folder
|
||||||
|
@ -26,6 +26,12 @@ As root:
|
|||||||
go get -v -u github.com/FreifunkBremen/yanic
|
go get -v -u github.com/FreifunkBremen/yanic
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### allow to ping
|
||||||
|
only needed if config has `nodes.ping_count` > 0
|
||||||
|
```sh
|
||||||
|
sudo setcap cap_net_raw=+ep /opt/go/bin/yanic
|
||||||
|
```
|
||||||
|
|
||||||
### Install
|
### Install
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
@ -13,7 +13,7 @@ type Node struct {
|
|||||||
Firstseen jsontime.Time `json:"firstseen"`
|
Firstseen jsontime.Time `json:"firstseen"`
|
||||||
Lastseen jsontime.Time `json:"lastseen"`
|
Lastseen jsontime.Time `json:"lastseen"`
|
||||||
Online bool `json:"online"`
|
Online bool `json:"online"`
|
||||||
NoRespondd bool `json:"-"`
|
NoRespondd bool `json:"no_respondd"`
|
||||||
Statistics *data.Statistics `json:"statistics"`
|
Statistics *data.Statistics `json:"statistics"`
|
||||||
Nodeinfo *data.NodeInfo `json:"nodeinfo"`
|
Nodeinfo *data.NodeInfo `json:"nodeinfo"`
|
||||||
Neighbours *data.Neighbours `json:"-"`
|
Neighbours *data.Neighbours `json:"-"`
|
||||||
|
@ -80,9 +80,10 @@ func (nodes *Nodes) Update(nodeID string, res *data.ResponseData) *Node {
|
|||||||
// Update fields
|
// Update fields
|
||||||
node.Lastseen = now
|
node.Lastseen = now
|
||||||
node.Online = true
|
node.Online = true
|
||||||
node.Neighbours = res.Neighbours
|
|
||||||
node.Nodeinfo = res.NodeInfo
|
node.Nodeinfo = res.NodeInfo
|
||||||
node.Statistics = res.Statistics
|
node.Statistics = res.Statistics
|
||||||
|
node.Neighbours = res.Neighbours
|
||||||
|
node.NoRespondd = res.Statistics == nil && res.Neighbours == nil
|
||||||
|
|
||||||
return node
|
return node
|
||||||
}
|
}
|
||||||
@ -170,12 +171,17 @@ func (nodes *Nodes) expire() {
|
|||||||
nodes.Lock()
|
nodes.Lock()
|
||||||
defer nodes.Unlock()
|
defer nodes.Unlock()
|
||||||
|
|
||||||
|
wg := sync.WaitGroup{}
|
||||||
|
|
||||||
for id, node := range nodes.List {
|
for id, node := range nodes.List {
|
||||||
if node.Lastseen.Before(pruneAfter) {
|
if node.Lastseen.Before(pruneAfter) {
|
||||||
// expire
|
// expire
|
||||||
delete(nodes.List, id)
|
delete(nodes.List, id)
|
||||||
} else if node.Lastseen.Before(offlineAfter) {
|
} else if node.Lastseen.Before(offlineAfter) {
|
||||||
// set to offline
|
// set to offline
|
||||||
|
wg.Add(1)
|
||||||
|
go func(node *Node) {
|
||||||
|
defer wg.Done()
|
||||||
if nodes.config.PingCount > 0 && nodes.ping(node) {
|
if nodes.config.PingCount > 0 && nodes.ping(node) {
|
||||||
node.Online = true
|
node.Online = true
|
||||||
node.NoRespondd = true
|
node.NoRespondd = true
|
||||||
@ -186,8 +192,11 @@ func (nodes *Nodes) expire() {
|
|||||||
node.Online = false
|
node.Online = false
|
||||||
node.NoRespondd = false
|
node.NoRespondd = false
|
||||||
}
|
}
|
||||||
|
}(node)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
wg.Wait()
|
||||||
|
log.WithField("nodes", "expire").Debug("end")
|
||||||
}
|
}
|
||||||
|
|
||||||
// adds the nodes interface addresses to the internal map
|
// adds the nodes interface addresses to the internal map
|
||||||
@ -249,6 +258,7 @@ func (nodes *Nodes) save() {
|
|||||||
|
|
||||||
// serialize nodes
|
// serialize nodes
|
||||||
SaveJSON(nodes, nodes.config.StatePath)
|
SaveJSON(nodes, nodes.config.StatePath)
|
||||||
|
log.WithField("nodes", "save").Debug("end")
|
||||||
}
|
}
|
||||||
|
|
||||||
// SaveJSON to path
|
// SaveJSON to path
|
||||||
|
@ -10,14 +10,22 @@ func (nodes *Nodes) ping(node *Node) bool {
|
|||||||
if node.Nodeinfo != nil {
|
if node.Nodeinfo != nil {
|
||||||
logNode = logNode.WithField("node_id", node.Nodeinfo.NodeID)
|
logNode = logNode.WithField("node_id", node.Nodeinfo.NodeID)
|
||||||
}
|
}
|
||||||
if node.Address == nil {
|
var addr string
|
||||||
logNode.Debug("error no address found")
|
if node.Address != nil {
|
||||||
return false
|
addr = node.Address.IP.String()
|
||||||
}
|
|
||||||
addr := node.Address.IP.String()
|
|
||||||
if node.Address.IP.IsLinkLocalUnicast() {
|
if node.Address.IP.IsLinkLocalUnicast() {
|
||||||
addr += "%" + node.Address.Zone
|
addr += "%" + node.Address.Zone
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
logNode.Debug("error no address found")
|
||||||
|
if node.Nodeinfo != nil {
|
||||||
|
for _, addrMaybe := range node.Nodeinfo.Network.Addresses {
|
||||||
|
if len(addrMaybe) >= 5 && addrMaybe[:5] != "fe80:" {
|
||||||
|
addr = addrMaybe
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
logAddr := logNode.WithField("addr", addr)
|
logAddr := logNode.WithField("addr", addr)
|
||||||
|
|
||||||
@ -26,9 +34,10 @@ func (nodes *Nodes) ping(node *Node) bool {
|
|||||||
logAddr.Debugf("error during ping: %s", err)
|
logAddr.Debugf("error during ping: %s", err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
//pinger.SetPrivileged(true)
|
pinger.SetPrivileged(true)
|
||||||
pinger.Count = nodes.config.PingCount
|
pinger.Count = nodes.config.PingCount
|
||||||
pinger.Timeout = nodes.config.PingTimeout.Duration
|
pinger.Timeout = nodes.config.PingTimeout.Duration
|
||||||
|
pinger.Interval = pinger.Timeout / pinger.Count
|
||||||
pinger.Run() // blocks until finished
|
pinger.Run() // blocks until finished
|
||||||
stats := pinger.Statistics()
|
stats := pinger.Statistics()
|
||||||
logAddr.WithFields(map[string]interface{}{
|
logAddr.WithFields(map[string]interface{}{
|
||||||
|
@ -27,7 +27,13 @@ func TestPing(t *testing.T) {
|
|||||||
ifaceToNodeID: make(map[string]string),
|
ifaceToNodeID: make(map[string]string),
|
||||||
}
|
}
|
||||||
|
|
||||||
node := nodes.Update("expire", &data.ResponseData{NodeInfo: &data.NodeInfo{NodeID: "nodeID-Lola"}})
|
node := nodes.Update("expire", &data.ResponseData{NodeInfo: &data.NodeInfo{
|
||||||
|
NodeID: "nodeID-Lola",
|
||||||
|
Network: data.Network{Addresses: []string{"fe80::1", "fd2f::1"}},
|
||||||
|
}})
|
||||||
|
// get fallback
|
||||||
|
assert.False(nodes.ping(node))
|
||||||
|
|
||||||
node.Address = &net.UDPAddr{Zone: "bat0"}
|
node.Address = &net.UDPAddr{Zone: "bat0"}
|
||||||
// error during ping
|
// error during ping
|
||||||
assert.False(nodes.ping(node))
|
assert.False(nodes.ping(node))
|
||||||
|
Loading…
Reference in New Issue
Block a user