-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
138 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package runtime | ||
|
||
import ( | ||
"github.com/bdlm/log" | ||
"github.com/sparrc/go-ping" | ||
) | ||
|
||
func (nodes *Nodes) ping(node *Node) bool { | ||
logNode := log.WithField("node_id", "unknown") | ||
if node.Nodeinfo != nil { | ||
logNode = logNode.WithField("node_id", node.Nodeinfo.NodeID) | ||
} | ||
if node.Address == nil { | ||
logNode.Debug("error no address found") | ||
return false | ||
} | ||
addr := node.Address.IP.String() | ||
if node.Address.IP.IsLinkLocalUnicast() { | ||
addr += "%" + node.Address.Zone | ||
} | ||
|
||
logAddr := logNode.WithField("addr", addr) | ||
|
||
pinger, err := ping.NewPinger(addr) | ||
if err != nil { | ||
logAddr.Debugf("error during ping: %s", err) | ||
return false | ||
} | ||
//pinger.SetPrivileged(true) | ||
pinger.Count = nodes.config.PingCount | ||
pinger.Timeout = nodes.config.PingTimeout.Duration | ||
pinger.Run() // blocks until finished | ||
stats := pinger.Statistics() | ||
logAddr.WithFields(map[string]interface{}{ | ||
"pkg_lost": stats.PacketLoss, | ||
}).Debug("pong") | ||
return stats.PacketLoss < 100 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package runtime | ||
|
||
import ( | ||
"net" | ||
"testing" | ||
"time" | ||
|
||
"github.com/bdlm/log" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/FreifunkBremen/yanic/data" | ||
) | ||
|
||
func TestPing(t *testing.T) { | ||
log.SetLevel(log.DebugLevel) | ||
|
||
assert := assert.New(t) | ||
config := &NodesConfig{ | ||
PingCount: 1, | ||
} | ||
config.OfflineAfter.Duration = time.Minute * 10 | ||
// to get default (100%) path of testing | ||
// config.PruneAfter.Duration = time.Hour * 24 * 6 | ||
nodes := &Nodes{ | ||
config: config, | ||
List: make(map[string]*Node), | ||
ifaceToNodeID: make(map[string]string), | ||
} | ||
|
||
node := nodes.Update("expire", &data.ResponseData{NodeInfo: &data.NodeInfo{NodeID: "nodeID-Lola"}}) | ||
node.Address = &net.UDPAddr{Zone: "bat0"} | ||
// error during ping | ||
assert.False(nodes.ping(node)) | ||
|
||
node.Address.IP = net.ParseIP("fe80::1") | ||
// error during ping | ||
assert.False(nodes.ping(node)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters