Commit e2668e9f authored by David Vorick's avatar David Vorick

switch to using proper string format for SiaPubKeys in hostdb

parent 40f0ab37
......@@ -88,7 +88,7 @@ type HostDB struct {
// insert inserts the HostDBEntry into both hosttrees
func (hdb *HostDB) insert(host modules.HostDBEntry) error {
err := hdb.hostTree.Insert(host)
_, ok := hdb.filteredHosts[string(host.PublicKey.Key)]
_, ok := hdb.filteredHosts[host.PublicKey.String()]
isWhitelist := hdb.filterMode == modules.HostDBActiveWhitelist
if isWhitelist == ok {
errF := hdb.filteredTree.Insert(host)
......@@ -102,7 +102,7 @@ func (hdb *HostDB) insert(host modules.HostDBEntry) error {
// modify modifies the HostDBEntry in both hosttrees
func (hdb *HostDB) modify(host modules.HostDBEntry) error {
err := hdb.hostTree.Modify(host)
_, ok := hdb.filteredHosts[string(host.PublicKey.Key)]
_, ok := hdb.filteredHosts[host.PublicKey.String()]
isWhitelist := hdb.filterMode == modules.HostDBActiveWhitelist
if isWhitelist == ok {
err = errors.Compose(err, hdb.filteredTree.Modify(host))
......@@ -113,7 +113,7 @@ func (hdb *HostDB) modify(host modules.HostDBEntry) error {
// remove removes the HostDBEntry from both hosttrees
func (hdb *HostDB) remove(pk types.SiaPublicKey) error {
err := hdb.hostTree.Remove(pk)
_, ok := hdb.filteredHosts[string(pk.Key)]
_, ok := hdb.filteredHosts[pk.String()]
isWhitelist := hdb.filterMode == modules.HostDBActiveWhitelist
if isWhitelist == ok {
errF := hdb.filteredTree.Remove(pk)
......@@ -374,7 +374,7 @@ func (hdb *HostDB) Host(spk types.SiaPublicKey) (modules.HostDBEntry, bool) {
if !exists {
return host, exists
}
_, ok := filteredHosts[string(spk.Key)]
_, ok := filteredHosts[spk.String()]
host.Filtered = whitelist != ok
hdb.mu.RLock()
updateHostHistoricInteractions(&host, hdb.blockHeight)
......@@ -422,16 +422,16 @@ func (hdb *HostDB) SetFilterMode(fm modules.FilterMode, hosts []types.SiaPublicK
// Create filteredHosts map
filteredHosts := make(map[string]types.SiaPublicKey)
for _, h := range hosts {
if _, ok := filteredHosts[string(h.Key)]; ok {
if _, ok := filteredHosts[h.String()]; ok {
continue
}
filteredHosts[string(h.Key)] = h
filteredHosts[h.String()] = h
}
var allErrs error
allHosts := hdb.hostTree.All()
for _, host := range allHosts {
// Add hosts to filtered tree
_, ok := filteredHosts[string(host.PublicKey.Key)]
_, ok := filteredHosts[host.PublicKey.String()]
if isWhitelist != ok {
continue
}
......@@ -514,7 +514,7 @@ func (hdb *HostDB) RandomHostsWithAllowance(n int, blacklist, addressBlacklist [
isWhitelist := filterType == modules.HostDBActiveWhitelist
for _, host := range allHosts {
// Filter out listed hosts
_, ok := filteredHosts[string(host.PublicKey.Key)]
_, ok := filteredHosts[host.PublicKey.String()]
if isWhitelist != ok {
continue
}
......
......@@ -6,6 +6,8 @@ import (
"gitlab.com/NebulousLabs/Sia/modules"
"gitlab.com/NebulousLabs/Sia/types"
"gitlab.com/NebulousLabs/fastrand"
)
// quitAfterLoadDeps will quit startup in newHostDB
......@@ -52,8 +54,8 @@ func TestSaveLoad(t *testing.T) {
host1.FirstSeen = 1
host2.FirstSeen = 2
host3.FirstSeen = 3
host1.PublicKey.Key = []byte("foo")
host2.PublicKey.Key = []byte("bar")
host1.PublicKey.Key = fastrand.Bytes(32)
host2.PublicKey.Key = fastrand.Bytes(32)
host3.PublicKey.Key = []byte("baz")
hdbt.hdb.hostTree.Insert(host1)
hdbt.hdb.hostTree.Insert(host2)
......@@ -61,9 +63,9 @@ func TestSaveLoad(t *testing.T) {
// Manually set listed Hosts and filterMode
filteredHosts := make(map[string]types.SiaPublicKey)
filteredHosts[string(host1.PublicKey.Key)] = host1.PublicKey
filteredHosts[string(host2.PublicKey.Key)] = host2.PublicKey
filteredHosts[string(host3.PublicKey.Key)] = host3.PublicKey
filteredHosts[host1.PublicKey.String()] = host1.PublicKey
filteredHosts[host2.PublicKey.String()] = host2.PublicKey
filteredHosts[host3.PublicKey.String()] = host3.PublicKey
filterMode := modules.HostDBActiveWhitelist
// Save, close, and reload.
......@@ -120,13 +122,13 @@ func TestSaveLoad(t *testing.T) {
if hdbt.hdb.filterMode != modules.HostDBActiveWhitelist {
t.Error("filter mode should be whitelist")
}
if _, ok := hdbt.hdb.filteredHosts[string(host1.PublicKey.Key)]; !ok {
if _, ok := hdbt.hdb.filteredHosts[host1.PublicKey.String()]; !ok {
t.Error("host1 not found in filteredHosts")
}
if _, ok := hdbt.hdb.filteredHosts[string(host2.PublicKey.Key)]; !ok {
if _, ok := hdbt.hdb.filteredHosts[host2.PublicKey.String()]; !ok {
t.Error("host2 not found in filteredHosts")
}
if _, ok := hdbt.hdb.filteredHosts[string(host3.PublicKey.Key)]; !ok {
if _, ok := hdbt.hdb.filteredHosts[host3.PublicKey.String()]; !ok {
t.Error("host3 not found in filteredHosts")
}
}
......
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