summaryrefslogtreecommitdiffhomepage
path: root/src/trie.go
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2017-07-13 14:32:40 +0200
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2017-07-13 14:32:40 +0200
commit93e3848ea76e755477bec8d9540a3c4c31ea7320 (patch)
tree31c27266ebf12fa9cef06ab531ee4b9fa7b69c56 /src/trie.go
parent8393cbff521560caef5b1b468cbb2ad030e8eda4 (diff)
Terminate on interface deletion
Program now terminates when the interface is removed Increases the number of os threads (relevant for Go <1.5, not tested) More consistent commenting Improved logging (additional peer information)
Diffstat (limited to 'src/trie.go')
-rw-r--r--src/trie.go19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/trie.go b/src/trie.go
index c2304b2..e81b5b6 100644
--- a/src/trie.go
+++ b/src/trie.go
@@ -23,7 +23,8 @@ type Trie struct {
bits []byte
peer *Peer
- // Index of "branching" bit
+ // index of "branching" bit
+
bit_at_byte uint
bit_at_shift uint
}
@@ -36,7 +37,7 @@ type Trie struct {
func commonBits(ip1 net.IP, ip2 net.IP) uint {
var i uint
size := uint(len(ip1))
- for i = 0; i < size; i += 1 {
+ for i = 0; i < size; i++ {
v := ip1[i] ^ ip2[i]
if v != 0 {
v >>= 1
@@ -84,7 +85,7 @@ func (node *Trie) RemovePeer(p *Peer) *Trie {
return node
}
- // Walk recursivly
+ // walk recursivly
node.child[0] = node.child[0].RemovePeer(p)
node.child[1] = node.child[1].RemovePeer(p)
@@ -93,7 +94,7 @@ func (node *Trie) RemovePeer(p *Peer) *Trie {
return node
}
- // Remove peer & merge
+ // remove peer & merge
node.peer = nil
if node.child[0] == nil {
@@ -108,7 +109,7 @@ func (node *Trie) choose(ip net.IP) byte {
func (node *Trie) Insert(ip net.IP, cidr uint, peer *Peer) *Trie {
- // At leaf
+ // at leaf
if node == nil {
return &Trie{
@@ -120,7 +121,7 @@ func (node *Trie) Insert(ip net.IP, cidr uint, peer *Peer) *Trie {
}
}
- // Traverse deeper
+ // traverse deeper
common := commonBits(node.bits, ip)
if node.cidr <= cidr && common >= node.cidr {
@@ -133,7 +134,7 @@ func (node *Trie) Insert(ip net.IP, cidr uint, peer *Peer) *Trie {
return node
}
- // Split node
+ // split node
newNode := &Trie{
bits: ip,
@@ -145,7 +146,7 @@ func (node *Trie) Insert(ip net.IP, cidr uint, peer *Peer) *Trie {
cidr = min(cidr, common)
- // Check for shorter prefix
+ // check for shorter prefix
if newNode.cidr == cidr {
bit := newNode.choose(node.bits)
@@ -153,7 +154,7 @@ func (node *Trie) Insert(ip net.IP, cidr uint, peer *Peer) *Trie {
return newNode
}
- // Create new parent for node & newNode
+ // create new parent for node & newNode
parent := &Trie{
bits: ip,