Commit ac8126c1 authored by Luke Champine's avatar Luke Champine

start implementing Renter

parent 5923a2d3
......@@ -55,12 +55,12 @@ type HostDB interface {
FlagHost(network.Address) error
// Insert adds a host to the database.
InsertHost(HostEntry) error
Insert(HostEntry) error
// RandomHost pulls a host entry at random from the database, weighted
// according to whatever score is assigned the hosts.
RandomHost() (HostEntry, error)
// Remove deletes the host with the given address from the database.
RemoveHost(network.Address) error
Remove(network.Address) error
}
......@@ -22,8 +22,8 @@ type RentInfo struct {
type Renter interface {
Download(nickname, filepath string) error
RentInfo() (RentInfo, error)
RenameFile(currentName, newName string) error
Info() (RentInfo, error)
Rename(currentName, newName string) error
RentFile(RentFileParameters) error
RentSmallFile(RentSmallFileParameters) error
......
......@@ -32,16 +32,6 @@ type Renter struct {
mu sync.RWMutex
}
func (r *Renter) RentInfo() (ri modules.RentInfo, err error) {
r.mu.RLock()
defer r.mu.RUnlock()
for key := range r.files {
ri.Files = append(ri.Files, key)
}
return
}
func New(state *consensus.State, hdb modules.HostDB, wallet modules.Wallet) (r *Renter, err error) {
if state == nil {
err = errors.New("renter.New: cannot have nil state")
......@@ -65,7 +55,7 @@ func New(state *consensus.State, hdb modules.HostDB, wallet modules.Wallet) (r *
return
}
func (r *Renter) RenameFile(currentName, newName string) error {
func (r *Renter) Rename(currentName, newName string) error {
// Check that the currentName exists and the newName doesn't.
entry, exists := r.files[currentName]
if !exists {
......@@ -130,3 +120,13 @@ func (r *Renter) Download(nickname, filename string) (err error) {
return
}
func (r *Renter) Info() (ri modules.RentInfo) {
r.mu.RLock()
defer r.mu.RUnlock()
for filename := range r.files {
ri.Files = append(ri.Files, filename)
}
return
}
......@@ -87,14 +87,5 @@ func (d *daemon) fileDownloadHandler(w http.ResponseWriter, req *http.Request) {
}
func (d *daemon) fileStatusHandler(w http.ResponseWriter, req *http.Request) {
http.Error(w, "Unimplemented", 500)
/*
info, err := d.core.RentInfo()
if err != nil {
http.Error(w, "Couldn't get renter info: "+err.Error(), 500)
return
}
writeJSON(w, info)
*/
writeJSON(w, d.renter.Info())
}
......@@ -9,6 +9,7 @@ import (
"github.com/NebulousLabs/Sia/modules/host"
"github.com/NebulousLabs/Sia/modules/hostdb"
"github.com/NebulousLabs/Sia/modules/miner"
"github.com/NebulousLabs/Sia/modules/renter"
"github.com/NebulousLabs/Sia/modules/transactionpool"
"github.com/NebulousLabs/Sia/modules/wallet"
"github.com/NebulousLabs/Sia/network"
......@@ -41,6 +42,7 @@ type daemon struct {
miner *miner.Miner
host *host.Host
hostDB *hostdb.HostDB
renter *renter.Renter
styleDir string
downloadDir string
......@@ -77,13 +79,10 @@ func newDaemon(config DaemonConfig) (d *daemon, err error) {
if err != nil {
return
}
/*
Renter, err := renter.New(d.state, hostDB, d.wallet)
if err != nil {
return
}
*/
d.renter, err = renter.New(d.state, d.hostDB, d.wallet)
if err != nil {
return
}
// register RPC handlers
// TODO: register all RPCs in a separate function
......
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