forked from NebulousLabs/Sia
/
host.go
95 lines (78 loc) · 2.82 KB
/
host.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package modules
import (
"github.com/NebulousLabs/Sia/types"
)
const (
AcceptResponse = "accept"
HostDir = "host"
)
var (
// RPC identifiers
// Each identifier has a version number at the end, which will be
// incremented whenever the protocol changes.
RPCSettings = types.Specifier{'S', 'e', 't', 't', 'i', 'n', 'g', 's', 0}
RPCUpload = types.Specifier{'U', 'p', 'l', 'o', 'a', 'd', 0}
RPCRevise = types.Specifier{'R', 'e', 'v', 'i', 's', 'e', 0}
RPCDownload = types.Specifier{'D', 'o', 'w', 'n', 'l', 'o', 'a', 'd', 0}
// PrefixHostAnnouncement is used to indicate that a transaction's
// Arbitrary Data field contains a host announcement. The encoded
// announcement will follow this prefix.
PrefixHostAnnouncement = types.Specifier{'H', 'o', 's', 't', 'A', 'n', 'n', 'o', 'u', 'n', 'c', 'e', 'm', 'e', 'n', 't'}
)
// HostAnnouncements are stored in the Arbitrary Data section of transactions
// on the blockchain. They announce the willingness of a node to host files.
// Renters can contact the host privately to obtain more detailed hosting
// parameters (see HostSettings).
type HostAnnouncement struct {
IPAddress NetAddress
}
// HostSettings are the parameters advertised by the host. These are the
// values that the renter will request from the host in order to build its
// database.
type HostSettings struct {
IPAddress NetAddress
TotalStorage int64 // Can go negative.
MinFilesize uint64
MaxFilesize uint64
MinDuration types.BlockHeight
MaxDuration types.BlockHeight
WindowSize types.BlockHeight
Price types.Currency
Collateral types.Currency
UnlockHash types.UnlockHash
}
// A DownloadRequest is used to retrieve a particular segment of a file from a
// host.
type DownloadRequest struct {
Offset uint64
Length uint64
}
// HostInfo contains HostSettings and details pertinent to the host's understanding
// of their offered services
type HostInfo struct {
HostSettings
StorageRemaining int64
NumContracts int
Profit types.Currency
PotentialProfit types.Currency
Competition types.Currency
}
type Host interface {
// Address returns the host's network address
Address() NetAddress
// Announce announces the host on the blockchain, returning an error if the
// host cannot reach itself or if the external ip address is unknown.
Announce() error
// ForceAnnounce announces the specified address on the blockchain,
// regardless of connectivity.
ForceAnnounce(NetAddress) error
// SetConfig sets the hosting parameters of the host.
SetSettings(HostSettings)
// Settings returns the host's settings.
Settings() HostSettings
// Info returns info about the host, including its hosting parameters, the
// amount of storage remaining, and the number of active contracts.
Info() HostInfo
// Close saves the state of the host and stops its listener process.
Close() error
}