forked from NebulousLabs/Sia
/
host.go
114 lines (95 loc) · 4.84 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package modules
import (
"github.com/NebulousLabs/Sia/types"
)
const (
// HostDir names the directory that contains the host persistence.
HostDir = "host"
)
var (
// BytesPerTerabyte is the conversion rate between bytes and terabytes.
BytesPerTerabyte = types.NewCurrency64(1e12)
// BlockBytesPerMonthTerabyte is the conversion rate between block-bytes and month-TB.
BlockBytesPerMonthTerabyte = BytesPerTerabyte.Mul64(4320)
)
type (
// HostFinancialMetrics provides financial statistics for the host,
// including money that is locked in contracts. Though verbose, these
// statistics should provide a clear picture of where the host's money is
// currently being used. The front end can consolidate stats where desired.
// Potential revenue refers to revenue that is available in a file
// contract for which the file contract window has not yet closed.
HostFinancialMetrics struct {
// Every time a renter forms a contract with a host, a contract fee is
// paid by the renter. These stats track the total contract fees.
ContractCount uint64 `json:"contractcount"`
ContractCompensation types.Currency `json:"contractcompensation"`
PotentialContractCompensation types.Currency `json:"potentialcontractcompensation"`
// Metrics related to storage proofs, collateral, and submitting
// transactions to the blockchain.
LockedStorageCollateral types.Currency `json:"lockedstoragecollateral"`
LostRevenue types.Currency `json:"lostrevenue"`
LostStorageCollateral types.Currency `json:"loststoragecollateral"`
PotentialStorageRevenue types.Currency `json:"potentialstoragerevenue"`
RiskedStorageCollateral types.Currency `json:"riskedstoragecollateral"`
StorageRevenue types.Currency `json:"storagerevenue"`
TransactionFeeExpenses types.Currency `json:"transactionfeeexpenses"`
// Bandwidth financial metrics.
DownloadBandwidthRevenue types.Currency `json:"downloadbandwidthrevenue"`
PotentialDownloadBandwidthRevenue types.Currency `json:"potentialdownloadbandwidthrevenue"`
PotentialUploadBandwidthRevenue types.Currency `json:"potentialuploadbandwidthrevenue"`
UploadBandwidthRevenue types.Currency `json:"uploadbandwidthrevenue"`
}
// HostInternalSettings contains a list of settings that can be changed.
HostInternalSettings struct {
AcceptingContracts bool `json:"acceptingcontracts"`
MaxDownloadBatchSize uint64 `json:"maxdownloadbatchsize"`
MaxDuration types.BlockHeight `json:"maxduration"`
MaxReviseBatchSize uint64 `json:"maxrevisebatchsize"`
NetAddress NetAddress `json:"netaddress"`
WindowSize types.BlockHeight `json:"windowsize"`
Collateral types.Currency `json:"collateral"`
CollateralBudget types.Currency `json:"collateralbudget"`
MaxCollateral types.Currency `json:"maxcollateral"`
MinContractPrice types.Currency `json:"mincontractprice"`
MinDownloadBandwidthPrice types.Currency `json:"mindownloadbandwidthprice"`
MinStoragePrice types.Currency `json:"minstorageprice"`
MinUploadBandwidthPrice types.Currency `json:"minuploadbandwidthprice"`
}
// HostNetworkMetrics reports the quantity of each type of RPC call that
// has been made to the host.
HostNetworkMetrics struct {
DownloadCalls uint64 `json:"downloadcalls"`
ErrorCalls uint64 `json:"errorcalls"`
FormContractCalls uint64 `json:"formcontractcalls"`
RenewCalls uint64 `json:"renewcalls"`
ReviseCalls uint64 `json:"revisecalls"`
SettingsCalls uint64 `json:"settingscalls"`
UnrecognizedCalls uint64 `json:"unrecognizedcalls"`
}
// A Host can take storage from disk and offer it to the network, managing
// things such as announcements, settings, and implementing all of the RPCs
// of the host protocol.
Host interface {
// Announce submits a host announcement to the blockchain.
Announce() error
// AnnounceAddress submits an announcement using the given address.
AnnounceAddress(NetAddress) error
// ExternalSettings returns the settings of the host as seen by an
// untrusted node querying the host for settings.
ExternalSettings() HostExternalSettings
// FinancialMetrics returns the financial statistics of the host.
FinancialMetrics() HostFinancialMetrics
// InternalSettings returns the host's internal settings, including
// potentially private or sensitive information.
InternalSettings() HostInternalSettings
// NetworkMetrics returns information on the types of RPC calls that
// have been made to the host.
NetworkMetrics() HostNetworkMetrics
// SetInternalSettings sets the hosting parameters of the host.
SetInternalSettings(HostInternalSettings) error
// The storage manager provides an interface for adding and removing
// storage folders and data sectors to the host.
StorageManager
}
)