github.com/johnathanhowell/sia@v0.5.1-beta.0.20160524050156-83dcc3d37c94/modules/host/negotiatesettings.go (about) 1 package host 2 3 import ( 4 "net" 5 "time" 6 7 "github.com/NebulousLabs/Sia/build" 8 "github.com/NebulousLabs/Sia/crypto" 9 "github.com/NebulousLabs/Sia/modules" 10 ) 11 12 // capacity returns the amount of storage still available on the machine. The 13 // amount can be negative if the total capacity was reduced to below the active 14 // capacity. 15 func (h *Host) capacity() (total, remaining uint64) { 16 // Total storage can be computed by summing the size of all the storage 17 // folders. 18 sfs := h.StorageFolders() 19 for _, sf := range sfs { 20 total += sf.Capacity 21 remaining += sf.CapacityRemaining 22 } 23 return total, remaining 24 } 25 26 // externalSettings compiles and returns the external settings for the host. 27 func (h *Host) externalSettings() modules.HostExternalSettings { 28 totalStorage, remainingStorage := h.capacity() 29 var netAddr modules.NetAddress 30 if h.settings.NetAddress != "" { 31 netAddr = h.settings.NetAddress 32 } else { 33 netAddr = h.autoAddress 34 } 35 return modules.HostExternalSettings{ 36 AcceptingContracts: h.settings.AcceptingContracts, 37 MaxDownloadBatchSize: h.settings.MaxDownloadBatchSize, 38 MaxDuration: h.settings.MaxDuration, 39 MaxReviseBatchSize: h.settings.MaxReviseBatchSize, 40 NetAddress: netAddr, 41 RemainingStorage: remainingStorage, 42 SectorSize: modules.SectorSize, 43 TotalStorage: totalStorage, 44 UnlockHash: h.unlockHash, 45 WindowSize: h.settings.WindowSize, 46 47 Collateral: h.settings.Collateral, 48 MaxCollateral: h.settings.MaxCollateral, 49 50 ContractPrice: h.settings.MinimumContractPrice, 51 DownloadBandwidthPrice: h.settings.MinimumDownloadBandwidthPrice, 52 StoragePrice: h.settings.MinimumStoragePrice, 53 UploadBandwidthPrice: h.settings.MinimumUploadBandwidthPrice, 54 55 RevisionNumber: h.revisionNumber, 56 Version: build.Version, 57 } 58 } 59 60 // managedRPCSettings is an rpc that returns the host's settings. 61 func (h *Host) managedRPCSettings(conn net.Conn) error { 62 // Set the negotiation deadline. 63 conn.SetDeadline(time.Now().Add(modules.NegotiateSettingsTime)) 64 65 var hes modules.HostExternalSettings 66 var secretKey crypto.SecretKey 67 h.mu.Lock() 68 h.revisionNumber++ 69 secretKey = h.secretKey 70 hes = h.externalSettings() 71 h.mu.Unlock() 72 return crypto.WriteSignedObject(conn, hes, secretKey) 73 }