github.com/Synthesix/Sia@v1.3.3-0.20180413141344-f863baeed3ca/modules/host.go (about)

     1  package modules
     2  
     3  import (
     4  	"github.com/Synthesix/Sia/types"
     5  )
     6  
     7  const (
     8  	// HostDir names the directory that contains the host persistence.
     9  	HostDir = "host"
    10  )
    11  
    12  var (
    13  	// BlockBytesPerMonthTerabyte is the conversion rate between block-bytes and month-TB.
    14  	BlockBytesPerMonthTerabyte = BytesPerTerabyte.Mul64(4320)
    15  
    16  	// BytesPerTerabyte is the conversion rate between bytes and terabytes.
    17  	BytesPerTerabyte = types.NewCurrency64(1e12)
    18  
    19  	// HostConnectabilityStatusChecking is returned from ConnectabilityStatus()
    20  	// if the host is still determining if it is connectable.
    21  	HostConnectabilityStatusChecking = HostConnectabilityStatus("checking")
    22  
    23  	// HostConnectabilityStatusConnectable is returned from
    24  	// ConnectabilityStatus() if the host is connectable at its configured
    25  	// netaddress.
    26  	HostConnectabilityStatusConnectable = HostConnectabilityStatus("connectable")
    27  
    28  	// HostConnectabilityStatusNotConnectable is returned from
    29  	// ConnectabilityStatus() if the host is not connectable at its configured
    30  	// netaddress.
    31  	HostConnectabilityStatusNotConnectable = HostConnectabilityStatus("not connectable")
    32  
    33  	// HostWorkingStatusChecking is returned from WorkingStatus() if the host is
    34  	// still determining if it is working, that is, if settings calls are
    35  	// incrementing.
    36  	HostWorkingStatusChecking = HostWorkingStatus("checking")
    37  
    38  	// HostWorkingStatusNotWorking is returned from WorkingStatus() if the host
    39  	// has not received any settings calls over the duration of
    40  	// workingStatusFrequency.
    41  	HostWorkingStatusNotWorking = HostWorkingStatus("not working")
    42  
    43  	// HostWorkingStatusWorking is returned from WorkingStatus() if the host has
    44  	// received more than workingThreshold settings calls over the duration of
    45  	// workingStatusFrequency.
    46  	HostWorkingStatusWorking = HostWorkingStatus("working")
    47  )
    48  
    49  type (
    50  	// HostFinancialMetrics provides financial statistics for the host,
    51  	// including money that is locked in contracts. Though verbose, these
    52  	// statistics should provide a clear picture of where the host's money is
    53  	// currently being used. The front end can consolidate stats where desired.
    54  	// Potential revenue refers to revenue that is available in a file
    55  	// contract for which the file contract window has not yet closed.
    56  	HostFinancialMetrics struct {
    57  		// Every time a renter forms a contract with a host, a contract fee is
    58  		// paid by the renter. These stats track the total contract fees.
    59  		ContractCount                 uint64         `json:"contractcount"`
    60  		ContractCompensation          types.Currency `json:"contractcompensation"`
    61  		PotentialContractCompensation types.Currency `json:"potentialcontractcompensation"`
    62  
    63  		// Metrics related to storage proofs, collateral, and submitting
    64  		// transactions to the blockchain.
    65  		LockedStorageCollateral types.Currency `json:"lockedstoragecollateral"`
    66  		LostRevenue             types.Currency `json:"lostrevenue"`
    67  		LostStorageCollateral   types.Currency `json:"loststoragecollateral"`
    68  		PotentialStorageRevenue types.Currency `json:"potentialstoragerevenue"`
    69  		RiskedStorageCollateral types.Currency `json:"riskedstoragecollateral"`
    70  		StorageRevenue          types.Currency `json:"storagerevenue"`
    71  		TransactionFeeExpenses  types.Currency `json:"transactionfeeexpenses"`
    72  
    73  		// Bandwidth financial metrics.
    74  		DownloadBandwidthRevenue          types.Currency `json:"downloadbandwidthrevenue"`
    75  		PotentialDownloadBandwidthRevenue types.Currency `json:"potentialdownloadbandwidthrevenue"`
    76  		PotentialUploadBandwidthRevenue   types.Currency `json:"potentialuploadbandwidthrevenue"`
    77  		UploadBandwidthRevenue            types.Currency `json:"uploadbandwidthrevenue"`
    78  	}
    79  
    80  	// HostInternalSettings contains a list of settings that can be changed.
    81  	HostInternalSettings struct {
    82  		AcceptingContracts   bool              `json:"acceptingcontracts"`
    83  		MaxDownloadBatchSize uint64            `json:"maxdownloadbatchsize"`
    84  		MaxDuration          types.BlockHeight `json:"maxduration"`
    85  		MaxReviseBatchSize   uint64            `json:"maxrevisebatchsize"`
    86  		NetAddress           NetAddress        `json:"netaddress"`
    87  		WindowSize           types.BlockHeight `json:"windowsize"`
    88  
    89  		Collateral       types.Currency `json:"collateral"`
    90  		CollateralBudget types.Currency `json:"collateralbudget"`
    91  		MaxCollateral    types.Currency `json:"maxcollateral"`
    92  
    93  		MinContractPrice          types.Currency `json:"mincontractprice"`
    94  		MinDownloadBandwidthPrice types.Currency `json:"mindownloadbandwidthprice"`
    95  		MinStoragePrice           types.Currency `json:"minstorageprice"`
    96  		MinUploadBandwidthPrice   types.Currency `json:"minuploadbandwidthprice"`
    97  	}
    98  
    99  	// HostNetworkMetrics reports the quantity of each type of RPC call that
   100  	// has been made to the host.
   101  	HostNetworkMetrics struct {
   102  		DownloadCalls     uint64 `json:"downloadcalls"`
   103  		ErrorCalls        uint64 `json:"errorcalls"`
   104  		FormContractCalls uint64 `json:"formcontractcalls"`
   105  		RenewCalls        uint64 `json:"renewcalls"`
   106  		ReviseCalls       uint64 `json:"revisecalls"`
   107  		SettingsCalls     uint64 `json:"settingscalls"`
   108  		UnrecognizedCalls uint64 `json:"unrecognizedcalls"`
   109  	}
   110  
   111  	// StorageObligation contains information about a storage obligation that
   112  	// the host has accepted.
   113  	StorageObligation struct {
   114  		NegotiationHeight types.BlockHeight `json:"negotiationheight"`
   115  
   116  		OriginConfirmed     bool   `json:"originconfirmed"`
   117  		RevisionConstructed bool   `json:"revisionconstructed"`
   118  		RevisionConfirmed   bool   `json:"revisionconfirmed"`
   119  		ProofConstructed    bool   `json:"proofconstructed"`
   120  		ProofConfirmed      bool   `json:"proofconfirmed"`
   121  		ObligationStatus    uint64 `json:"obligationstatus"`
   122  	}
   123  
   124  	// HostWorkingStatus reports the working state of a host. Can be one of
   125  	// "checking", "working", or "not working".
   126  	HostWorkingStatus string
   127  
   128  	// HostConnectabilityStatus reports the connectability state of a host. Can be
   129  	// one of "checking", "connectable", or "not connectable"
   130  	HostConnectabilityStatus string
   131  
   132  	// A Host can take storage from disk and offer it to the network, managing
   133  	// things such as announcements, settings, and implementing all of the RPCs
   134  	// of the host protocol.
   135  	Host interface {
   136  		// Announce submits a host announcement to the blockchain.
   137  		Announce() error
   138  
   139  		// AnnounceAddress submits an announcement using the given address.
   140  		AnnounceAddress(NetAddress) error
   141  
   142  		// ExternalSettings returns the settings of the host as seen by an
   143  		// untrusted node querying the host for settings.
   144  		ExternalSettings() HostExternalSettings
   145  
   146  		// FinancialMetrics returns the financial statistics of the host.
   147  		FinancialMetrics() HostFinancialMetrics
   148  
   149  		// InternalSettings returns the host's internal settings, including
   150  		// potentially private or sensitive information.
   151  		InternalSettings() HostInternalSettings
   152  
   153  		// NetworkMetrics returns information on the types of RPC calls that
   154  		// have been made to the host.
   155  		NetworkMetrics() HostNetworkMetrics
   156  
   157  		// PublicKey returns the public key of the host.
   158  		PublicKey() types.SiaPublicKey
   159  
   160  		// SetInternalSettings sets the hosting parameters of the host.
   161  		SetInternalSettings(HostInternalSettings) error
   162  
   163  		// StorageObligations returns the set of storage obligations held by
   164  		// the host.
   165  		StorageObligations() []StorageObligation
   166  
   167  		// ConnectabilityStatus returns the connectability status of the host, that
   168  		// is, if it can connect to itself on the configured NetAddress.
   169  		ConnectabilityStatus() HostConnectabilityStatus
   170  
   171  		// WorkingStatus returns the working state of the host, determined by if
   172  		// settings calls are increasing.
   173  		WorkingStatus() HostWorkingStatus
   174  
   175  		// The storage manager provides an interface for adding and removing
   176  		// storage folders and data sectors to the host.
   177  		StorageManager
   178  	}
   179  )