Commit 200f6dd6 authored by David Vorick's avatar David Vorick

consistent conversion from pubkey to string throughout hostdb

parent 4b97132a
Pipeline #40899323 failed with stages
in 27 minutes and 24 seconds
......@@ -211,7 +211,7 @@ func TestRandomHosts(t *testing.T) {
nEntries := int(1e3)
for i := 0; i < nEntries; i++ {
entry := makeHostDBEntry()
entries[string(entry.PublicKey.Key)] = entry
entries[entry.PublicKey.String()] = entry
err := hdbt.hdb.filteredTree.Insert(entry)
if err != nil {
t.Error(err)
......@@ -229,15 +229,15 @@ func TestRandomHosts(t *testing.T) {
}
dupCheck := make(map[string]modules.HostDBEntry)
for _, host := range hosts {
_, exists := entries[string(host.PublicKey.Key)]
_, exists := entries[host.PublicKey.String()]
if !exists {
t.Error("hostdb returning host that doesn't exist.")
}
_, exists = dupCheck[string(host.PublicKey.Key)]
_, exists = dupCheck[host.PublicKey.String()]
if exists {
t.Error("RandomHosts returning duplicates")
}
dupCheck[string(host.PublicKey.Key)] = host
dupCheck[host.PublicKey.String()] = host
}
}
......@@ -251,15 +251,15 @@ func TestRandomHosts(t *testing.T) {
t.Fatalf("RandomHosts returned few entries. got %v wanted %v\n", len(hosts), nEntries/2)
}
for _, host := range hosts {
_, exists := entries[string(host.PublicKey.Key)]
_, exists := entries[host.PublicKey.String()]
if !exists {
t.Error("hostdb returning host that doesn't exist.")
}
_, exists = dupCheck1[string(host.PublicKey.Key)]
_, exists = dupCheck1[host.PublicKey.String()]
if exists {
t.Error("RandomHosts returning duplicates")
}
dupCheck1[string(host.PublicKey.Key)] = host
dupCheck1[host.PublicKey.String()] = host
}
// Iterative case. Check that every time you query for random hosts, you
......@@ -275,21 +275,21 @@ func TestRandomHosts(t *testing.T) {
t.Fatalf("RandomHosts returned few entries. got %v wanted %v\n", len(hosts), nEntries/2)
}
for _, host := range hosts {
_, exists := entries[string(host.PublicKey.Key)]
_, exists := entries[host.PublicKey.String()]
if !exists {
t.Error("hostdb returning host that doesn't exist.")
}
_, exists = dupCheck2[string(host.PublicKey.Key)]
_, exists = dupCheck2[host.PublicKey.String()]
if exists {
t.Error("RandomHosts returning duplicates")
}
_, exists = dupCheck1[string(host.PublicKey.Key)]
_, exists = dupCheck1[host.PublicKey.String()]
if exists {
overlap = true
} else {
disjoint = true
}
dupCheck2[string(host.PublicKey.Key)] = host
dupCheck2[host.PublicKey.String()] = host
}
if !overlap || !disjoint {
......@@ -316,7 +316,7 @@ func TestRandomHosts(t *testing.T) {
if len(rand) != 1 {
t.Fatal("wrong number of hosts returned")
}
if string(rand[0].PublicKey.Key) != string(hosts[0].PublicKey.Key) {
if rand[0].PublicKey.String() != hosts[0].PublicKey.String() {
t.Error("exclude list seems to be excluding the wrong hosts.")
}
......@@ -328,7 +328,7 @@ func TestRandomHosts(t *testing.T) {
if len(rand) != 1 {
t.Fatal("wrong number of hosts returned")
}
if string(rand[0].PublicKey.Key) != string(hosts[0].PublicKey.Key) {
if rand[0].PublicKey.String() != hosts[0].PublicKey.String() {
t.Error("exclude list seems to be excluding the wrong hosts.")
}
......@@ -337,7 +337,7 @@ func TestRandomHosts(t *testing.T) {
// map.
includeMap := make(map[string]struct{})
for j := 0; j < 50; j++ {
includeMap[string(hosts[j].PublicKey.Key)] = struct{}{}
includeMap[hosts[j].PublicKey.String()] = struct{}{}
}
exclude = exclude[49:]
......@@ -351,12 +351,12 @@ func TestRandomHosts(t *testing.T) {
t.Error("random hosts is returning the wrong number of hosts")
}
for _, host := range rand {
_, exists := dupCheck[string(host.PublicKey.Key)]
_, exists := dupCheck[host.PublicKey.String()]
if exists {
t.Error("RandomHosts is selecting duplicates")
}
dupCheck[string(host.PublicKey.Key)] = struct{}{}
_, exists = includeMap[string(host.PublicKey.Key)]
dupCheck[host.PublicKey.String()] = struct{}{}
_, exists = includeMap[host.PublicKey.String()]
if !exists {
t.Error("RandomHosts returning excluded hosts")
}
......@@ -372,12 +372,12 @@ func TestRandomHosts(t *testing.T) {
t.Error("random hosts is returning the wrong number of hosts")
}
for _, host := range rand {
_, exists := dupCheck[string(host.PublicKey.Key)]
_, exists := dupCheck[host.PublicKey.String()]
if exists {
t.Error("RandomHosts is selecting duplicates")
}
dupCheck[string(host.PublicKey.Key)] = struct{}{}
_, exists = includeMap[string(host.PublicKey.Key)]
dupCheck[host.PublicKey.String()] = struct{}{}
_, exists = includeMap[host.PublicKey.String()]
if !exists {
t.Error("RandomHosts returning excluded hosts")
}
......@@ -393,12 +393,12 @@ func TestRandomHosts(t *testing.T) {
t.Error("random hosts is returning the wrong number of hosts")
}
for _, host := range rand {
_, exists := dupCheck[string(host.PublicKey.Key)]
_, exists := dupCheck[host.PublicKey.String()]
if exists {
t.Error("RandomHosts is selecting duplicates")
}
dupCheck[string(host.PublicKey.Key)] = struct{}{}
_, exists = includeMap[string(host.PublicKey.Key)]
dupCheck[host.PublicKey.String()] = struct{}{}
_, exists = includeMap[host.PublicKey.String()]
if !exists {
t.Error("RandomHosts returning excluded hosts")
}
......
......@@ -216,12 +216,12 @@ func (ht *HostTree) Remove(pk types.SiaPublicKey) error {
ht.mu.Lock()
defer ht.mu.Unlock()
node, exists := ht.hosts[string(pk.Key)]
node, exists := ht.hosts[pk.String()]
if !exists {
return ErrNoSuchHost
}
node.remove()
delete(ht.hosts, string(pk.Key))
delete(ht.hosts, pk.String())
return nil
}
......@@ -232,7 +232,7 @@ func (ht *HostTree) Modify(hdbe modules.HostDBEntry) error {
ht.mu.Lock()
defer ht.mu.Unlock()
node, exists := ht.hosts[string(hdbe.PublicKey.Key)]
node, exists := ht.hosts[hdbe.PublicKey.String()]
if !exists {
return ErrNoSuchHost
}
......@@ -246,7 +246,7 @@ func (ht *HostTree) Modify(hdbe modules.HostDBEntry) error {
_, node = ht.root.recursiveInsert(entry)
ht.hosts[string(entry.PublicKey.Key)] = node
ht.hosts[entry.PublicKey.String()] = node
return nil
}
......@@ -285,7 +285,7 @@ func (ht *HostTree) Select(spk types.SiaPublicKey) (modules.HostDBEntry, bool) {
ht.mu.Lock()
defer ht.mu.Unlock()
node, exists := ht.hosts[string(spk.Key)]
node, exists := ht.hosts[spk.String()]
if !exists {
return modules.HostDBEntry{}, false
}
......@@ -312,7 +312,7 @@ func (ht *HostTree) SelectRandom(n int, blacklist, addressBlacklist []types.SiaP
// Add the hosts from the addressBlacklist to the filter.
for _, pubkey := range addressBlacklist {
node, exists := ht.hosts[string(pubkey.Key)]
node, exists := ht.hosts[pubkey.String()]
if !exists {
continue
}
......@@ -322,13 +322,13 @@ func (ht *HostTree) SelectRandom(n int, blacklist, addressBlacklist []types.SiaP
// Remove hosts we want to blacklist from the tree but remember them to make
// sure we can insert them later.
for _, pubkey := range blacklist {
node, exists := ht.hosts[string(pubkey.Key)]
node, exists := ht.hosts[pubkey.String()]
if !exists {
continue
}
// Remove the host from the tree.
node.remove()
delete(ht.hosts, string(pubkey.Key))
delete(ht.hosts, pubkey.String())
// Remember the host to insert it again later.
removedEntries = append(removedEntries, node.entry)
......@@ -355,12 +355,12 @@ func (ht *HostTree) SelectRandom(n int, blacklist, addressBlacklist []types.SiaP
removedEntries = append(removedEntries, node.entry)
node.remove()
delete(ht.hosts, string(node.entry.PublicKey.Key))
delete(ht.hosts, node.entry.PublicKey.String())
}
for _, entry := range removedEntries {
_, node := ht.root.recursiveInsert(entry)
ht.hosts[string(entry.PublicKey.Key)] = node
ht.hosts[entry.PublicKey.String()] = node
}
return hosts
......@@ -389,12 +389,12 @@ func (ht *HostTree) insert(hdbe modules.HostDBEntry) error {
weight: ht.weightFn(hdbe).Score(),
}
if _, exists := ht.hosts[string(entry.PublicKey.Key)]; exists {
if _, exists := ht.hosts[entry.PublicKey.String()]; exists {
return ErrHostExists
}
_, node := ht.root.recursiveInsert(entry)
ht.hosts[string(entry.PublicKey.Key)] = node
ht.hosts[entry.PublicKey.String()] = node
return nil
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment