summaryrefslogtreecommitdiffhomepage
path: root/device/allowedips_rand_test.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2021-06-03 14:50:28 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2021-06-03 15:08:42 +0200
commitb41f4cc768021d68b98fed6ca76e7d20fcc38120 (patch)
tree88c1c5ff2b385384be07cb0cee7790c97adad9b5 /device/allowedips_rand_test.go
parent4a57024b94edf23a20f1e4289052d0717227683b (diff)
device: remove recursion from insertion and connect parent pointers
This makes the insertion algorithm a bit more efficient, while also now taking on the additional task of connecting up parent pointers. This will be handy in the following commit. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'device/allowedips_rand_test.go')
-rw-r--r--device/allowedips_rand_test.go12
1 files changed, 6 insertions, 6 deletions
diff --git a/device/allowedips_rand_test.go b/device/allowedips_rand_test.go
index 2da8795..48a5bcd 100644
--- a/device/allowedips_rand_test.go
+++ b/device/allowedips_rand_test.go
@@ -65,9 +65,9 @@ func (r SlowRouter) Lookup(addr []byte) *Peer {
}
func TestTrieRandomIPv4(t *testing.T) {
- var trie *trieEntry
var slow SlowRouter
var peers []*Peer
+ var allowedIPs AllowedIPs
rand.Seed(1)
@@ -82,7 +82,7 @@ func TestTrieRandomIPv4(t *testing.T) {
rand.Read(addr[:])
cidr := uint8(rand.Uint32() % (AddressLength * 8))
index := rand.Int() % NumberOfPeers
- trie = trie.insert(addr[:], cidr, peers[index])
+ allowedIPs.Insert(addr[:], cidr, peers[index])
slow = slow.Insert(addr[:], cidr, peers[index])
}
@@ -90,7 +90,7 @@ func TestTrieRandomIPv4(t *testing.T) {
var addr [AddressLength]byte
rand.Read(addr[:])
peer1 := slow.Lookup(addr[:])
- peer2 := trie.lookup(addr[:])
+ peer2 := allowedIPs.LookupIPv4(addr[:])
if peer1 != peer2 {
t.Error("Trie did not match naive implementation, for:", addr)
}
@@ -98,9 +98,9 @@ func TestTrieRandomIPv4(t *testing.T) {
}
func TestTrieRandomIPv6(t *testing.T) {
- var trie *trieEntry
var slow SlowRouter
var peers []*Peer
+ var allowedIPs AllowedIPs
rand.Seed(1)
@@ -115,7 +115,7 @@ func TestTrieRandomIPv6(t *testing.T) {
rand.Read(addr[:])
cidr := uint8(rand.Uint32() % (AddressLength * 8))
index := rand.Int() % NumberOfPeers
- trie = trie.insert(addr[:], cidr, peers[index])
+ allowedIPs.Insert(addr[:], cidr, peers[index])
slow = slow.Insert(addr[:], cidr, peers[index])
}
@@ -123,7 +123,7 @@ func TestTrieRandomIPv6(t *testing.T) {
var addr [AddressLength]byte
rand.Read(addr[:])
peer1 := slow.Lookup(addr[:])
- peer2 := trie.lookup(addr[:])
+ peer2 := allowedIPs.LookupIPv6(addr[:])
if peer1 != peer2 {
t.Error("Trie did not match naive implementation, for:", addr)
}