Commit 4b20cfaf authored by Luke Champine's avatar Luke Champine

add state to HostDB

parent d3cdce5b
......@@ -21,6 +21,9 @@ import (
// The HostDB is a set of hosts that get weighted and inserted into a tree
type HostDB struct {
state *consensus.State
recentBlock consensus.BlockID
hostTree *hostNode
activeHosts map[network.Address]*hostNode
inactiveHosts map[network.Address]*modules.HostEntry
......@@ -29,8 +32,14 @@ type HostDB struct {
}
// New returns an empty HostDatabase.
func New() (hdb *HostDB, err error) {
func New(state *consensus.State) (hdb *HostDB, err error) {
if state == nil {
err = errors.New("HostDB can't use nil State")
return
}
hdb = &HostDB{
state: state,
recentBlock: state.CurrentBlock().ID(),
activeHosts: make(map[network.Address]*hostNode),
inactiveHosts: make(map[network.Address]*modules.HostEntry),
}
......
......@@ -60,7 +60,7 @@ func uniformTreeVerification(hdb *HostDB, numEntries int, t *testing.T) {
// verifies that the tree stays consistent through the adjustments.
func TestWeightedList(t *testing.T) {
// Create a hostdb and 3 equal entries to insert.
hdb, err := New()
hdb, err := New(consensus.CreateGenesisState())
if err != nil {
t.Fatal(err)
}
......
......@@ -7,6 +7,7 @@ import (
"github.com/NebulousLabs/Sia/consensus"
"github.com/NebulousLabs/Sia/modules/host"
"github.com/NebulousLabs/Sia/modules/hostdb"
"github.com/NebulousLabs/Sia/modules/miner"
"github.com/NebulousLabs/Sia/modules/transactionpool"
"github.com/NebulousLabs/Sia/modules/wallet"
......@@ -39,6 +40,7 @@ type daemon struct {
wallet *wallet.Wallet
miner *miner.Miner
host *host.Host
hostDB *hostdb.HostDB
styleDir string
downloadDir string
......@@ -71,16 +73,16 @@ func newDaemon(config DaemonConfig) (d *daemon, err error) {
if err != nil {
return
}
d.hostDB, err = hostdb.New(d.state)
if err != nil {
return
}
/*
hostDB, err := hostdb.New()
Renter, err := renter.New(d.state, hostDB, d.wallet)
if err != nil {
return
}
Renter, err := renter.New(d.state, hostDB, d.wallet)
if err != nil {
return
}
*/
// register RPC handlers
......
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