gitlab.com/jokerrs1/Sia@v1.3.2/modules/gateway/consts.go (about) 1 package gateway 2 3 import ( 4 "time" 5 6 "github.com/NebulousLabs/Sia/build" 7 "github.com/NebulousLabs/Sia/modules" 8 ) 9 10 const ( 11 // handshakeUpgradeVersion is the version where the gateway handshake RPC 12 // was altered to include additional information transfer. 13 handshakeUpgradeVersion = "1.0.0" 14 15 // maxEncodedSessionHeaderSize is the maximum allowed size of an encoded 16 // sessionHeader object. 17 maxEncodedSessionHeaderSize = 40 + modules.MaxEncodedNetAddressLength 18 19 // maxLocalOutbound is currently set to 3, meaning the gateway will not 20 // consider a local node to be an outbound peer if the gateway already has 21 // 3 outbound peers. Three is currently needed to handle situations where 22 // the gateway is at high risk of connecting to itself (such as a low 23 // number of total peers, especially such as in a testing environment). 24 // Once the gateway has a proper way to figure out that it's trying to 25 // connect to itself, this number can be reduced. 26 maxLocalOutboundPeers = 3 27 28 // minAcceptableVersion is the version below which the gateway will refuse to 29 // connect to peers and reject connection attempts. 30 // 31 // Reject peers < v1.3.0 due to hardfork. 32 minAcceptableVersion = "1.3.0" 33 34 // saveFrequency defines how often the gateway saves its persistence. 35 saveFrequency = time.Minute * 2 36 37 // minimumAcceptablePeerVersion is the oldest version for which we accept 38 // incoming connections. This version is usually raised if changes to the 39 // codebase were made that weren't backwards compatible. This might include 40 // changes to the protocol or hardforks. 41 minimumAcceptablePeerVersion = "1.3.1" 42 ) 43 44 var ( 45 // fastNodePurgeDelay defines the amount of time that is waited between each 46 // iteration of the purge loop when the gateway has enough nodes to be 47 // needing to purge quickly. 48 fastNodePurgeDelay = build.Select(build.Var{ 49 Standard: 1 * time.Minute, 50 Dev: 5 * time.Second, 51 Testing: 200 * time.Millisecond, 52 }).(time.Duration) 53 54 // healthyNodeListLen defines the number of nodes that the gateway must 55 // have in the node list before it will stop asking peers for more nodes. 56 healthyNodeListLen = build.Select(build.Var{ 57 Standard: int(200), 58 Dev: int(30), 59 Testing: int(15), 60 }).(int) 61 62 // maxSharedNodes defines the number of nodes that will be shared between 63 // peers when they are expanding their node lists. 64 maxSharedNodes = build.Select(build.Var{ 65 Standard: uint64(10), 66 Dev: uint64(5), 67 Testing: uint64(3), 68 }).(uint64) 69 70 // nodeListDelay defines the amount of time that is waited between each 71 // iteration of the node list loop. 72 nodeListDelay = build.Select(build.Var{ 73 Standard: 5 * time.Second, 74 Dev: 3 * time.Second, 75 Testing: 500 * time.Millisecond, 76 }).(time.Duration) 77 78 // nodePurgeDelay defines the amount of time that is waited between each 79 // iteration of the node purge loop. 80 nodePurgeDelay = build.Select(build.Var{ 81 Standard: 10 * time.Minute, 82 Dev: 20 * time.Second, 83 Testing: 500 * time.Millisecond, 84 }).(time.Duration) 85 86 // peerRPCDelay defines the amount of time waited between each RPC accepted 87 // from a peer. Without this delay, a peer can force us to spin up thousands 88 // of goroutines per second. 89 peerRPCDelay = build.Select(build.Var{ 90 Standard: 3 * time.Second, 91 Dev: 1 * time.Second, 92 Testing: 20 * time.Millisecond, 93 }).(time.Duration) 94 95 // pruneNodeListLen defines the number of nodes that the gateway must have 96 // to be pruning nodes from the node list. 97 pruneNodeListLen = build.Select(build.Var{ 98 Standard: int(50), 99 Dev: int(15), 100 Testing: int(10), 101 }).(int) 102 103 // quickPruneListLen defines the number of nodes that the gateway must have 104 // to be pruning nodes quickly from the node list. 105 quickPruneListLen = build.Select(build.Var{ 106 Standard: int(250), 107 Dev: int(40), 108 Testing: int(20), 109 }).(int) 110 ) 111 112 var ( 113 // The gateway will sleep this long between incoming connections. For 114 // attack reasons, the acceptInterval should be longer than the 115 // nodeListDelay. Right at startup, a node is vulnerable to being flooded 116 // by Sybil attackers. The node's best defense is to wait until it has 117 // filled out its nodelist somewhat from the bootstrap nodes. An attacker 118 // needs to completely dominate the nodelist and the peerlist to be 119 // successful, so just a few honest nodes from requests to the bootstraps 120 // should be enough to fend from most attacks. 121 acceptInterval = build.Select(build.Var{ 122 Standard: 6 * time.Second, 123 Dev: 3 * time.Second, 124 Testing: 100 * time.Millisecond, 125 }).(time.Duration) 126 127 // acquiringPeersDelay defines the amount of time that is waited between 128 // iterations of the peer acquisition loop if the gateway is actively 129 // forming new connections with peers. 130 acquiringPeersDelay = build.Select(build.Var{ 131 Standard: 5 * time.Second, 132 Dev: 3 * time.Second, 133 Testing: 500 * time.Millisecond, 134 }).(time.Duration) 135 136 // fullyConnectedThreshold defines the number of peers that the gateway can 137 // have before it stops accepting inbound connections. 138 fullyConnectedThreshold = build.Select(build.Var{ 139 Standard: 128, 140 Dev: 20, 141 Testing: 10, 142 }).(int) 143 144 // maxConcurrentOutboundPeerRequests defines the maximum number of peer 145 // connections that the gateway will try to form concurrently. 146 maxConcurrentOutboundPeerRequests = build.Select(build.Var{ 147 Standard: 3, 148 Dev: 2, 149 Testing: 2, 150 }).(int) 151 152 // noNodesDelay defines the amount of time that is waited between 153 // iterations of the peer acquisition loop if the gateway does not have any 154 // nodes in the nodelist. 155 noNodesDelay = build.Select(build.Var{ 156 Standard: 20 * time.Second, 157 Dev: 10 * time.Second, 158 Testing: 3 * time.Second, 159 }).(time.Duration) 160 161 // unwawntedLocalPeerDelay defines the amount of time that is waited 162 // between iterations of the permanentPeerManager if the gateway has at 163 // least a few outbound peers, but is not well connected, and the recently 164 // selected peer was a local peer. The wait is mostly to prevent the 165 // gateway from hogging the CPU in the event that all peers are local 166 // peers. 167 unwantedLocalPeerDelay = build.Select(build.Var{ 168 Standard: 2 * time.Second, 169 Dev: 1 * time.Second, 170 Testing: 100 * time.Millisecond, 171 }).(time.Duration) 172 173 // wellConnectedDelay defines the amount of time that is waited between 174 // iterations of the peer acquisition loop if the gateway is well 175 // connected. 176 wellConnectedDelay = build.Select(build.Var{ 177 Standard: 5 * time.Minute, 178 Dev: 1 * time.Minute, 179 Testing: 3 * time.Second, 180 }).(time.Duration) 181 182 // wellConnectedThreshold is the number of outbound connections at which 183 // the gateway will not attempt to make new outbound connections. 184 wellConnectedThreshold = build.Select(build.Var{ 185 Standard: 8, 186 Dev: 5, 187 Testing: 4, 188 }).(int) 189 ) 190 191 var ( 192 // connStdDeadline defines the standard deadline that should be used for 193 // all temporary connections to the gateway. 194 connStdDeadline = build.Select(build.Var{ 195 Standard: 5 * time.Minute, 196 Dev: 2 * time.Minute, 197 Testing: 30 * time.Second, 198 }).(time.Duration) 199 200 // the gateway will abort a connection attempt after this long 201 dialTimeout = build.Select(build.Var{ 202 Standard: 3 * time.Minute, 203 Dev: 20 * time.Second, 204 Testing: 500 * time.Millisecond, 205 }).(time.Duration) 206 207 // rpcStdDeadline defines the standard deadline that should be used for all 208 // incoming RPC calls. 209 rpcStdDeadline = build.Select(build.Var{ 210 Standard: 5 * time.Minute, 211 Dev: 3 * time.Minute, 212 Testing: 5 * time.Second, 213 }).(time.Duration) 214 )