github.com/NebulousLabs/Sia@v1.3.7/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  	// saveFrequency defines how often the gateway saves its persistence.
    29  	saveFrequency = time.Minute * 2
    30  
    31  	// minimumAcceptablePeerVersion is the oldest version for which we accept
    32  	// incoming connections. This version is usually raised if changes to the
    33  	// codebase were made that weren't backwards compatible. This might include
    34  	// changes to the protocol or hardforks.
    35  	minimumAcceptablePeerVersion = "1.3.1"
    36  )
    37  
    38  var (
    39  	// fastNodePurgeDelay defines the amount of time that is waited between each
    40  	// iteration of the purge loop when the gateway has enough nodes to be
    41  	// needing to purge quickly.
    42  	fastNodePurgeDelay = build.Select(build.Var{
    43  		Standard: 1 * time.Minute,
    44  		Dev:      5 * time.Second,
    45  		Testing:  200 * time.Millisecond,
    46  	}).(time.Duration)
    47  
    48  	// healthyNodeListLen defines the number of nodes that the gateway must
    49  	// have in the node list before it will stop asking peers for more nodes.
    50  	healthyNodeListLen = build.Select(build.Var{
    51  		Standard: int(200),
    52  		Dev:      int(30),
    53  		Testing:  int(15),
    54  	}).(int)
    55  
    56  	// maxSharedNodes defines the number of nodes that will be shared between
    57  	// peers when they are expanding their node lists.
    58  	maxSharedNodes = build.Select(build.Var{
    59  		Standard: uint64(10),
    60  		Dev:      uint64(5),
    61  		Testing:  uint64(3),
    62  	}).(uint64)
    63  
    64  	// nodeListDelay defines the amount of time that is waited between each
    65  	// iteration of the node list loop.
    66  	nodeListDelay = build.Select(build.Var{
    67  		Standard: 5 * time.Second,
    68  		Dev:      3 * time.Second,
    69  		Testing:  500 * time.Millisecond,
    70  	}).(time.Duration)
    71  
    72  	// nodePurgeDelay defines the amount of time that is waited between each
    73  	// iteration of the node purge loop.
    74  	nodePurgeDelay = build.Select(build.Var{
    75  		Standard: 10 * time.Minute,
    76  		Dev:      20 * time.Second,
    77  		Testing:  500 * time.Millisecond,
    78  	}).(time.Duration)
    79  
    80  	// peerRPCDelay defines the amount of time waited between each RPC accepted
    81  	// from a peer. Without this delay, a peer can force us to spin up thousands
    82  	// of goroutines per second.
    83  	peerRPCDelay = build.Select(build.Var{
    84  		Standard: 3 * time.Second,
    85  		Dev:      1 * time.Second,
    86  		Testing:  20 * time.Millisecond,
    87  	}).(time.Duration)
    88  
    89  	// pruneNodeListLen defines the number of nodes that the gateway must have
    90  	// to be pruning nodes from the node list.
    91  	pruneNodeListLen = build.Select(build.Var{
    92  		Standard: int(50),
    93  		Dev:      int(15),
    94  		Testing:  int(10),
    95  	}).(int)
    96  
    97  	// quickPruneListLen defines the number of nodes that the gateway must have
    98  	// to be pruning nodes quickly from the node list.
    99  	quickPruneListLen = build.Select(build.Var{
   100  		Standard: int(250),
   101  		Dev:      int(40),
   102  		Testing:  int(20),
   103  	}).(int)
   104  )
   105  
   106  var (
   107  	// The gateway will sleep this long between incoming connections. For
   108  	// attack reasons, the acceptInterval should be longer than the
   109  	// nodeListDelay. Right at startup, a node is vulnerable to being flooded
   110  	// by Sybil attackers. The node's best defense is to wait until it has
   111  	// filled out its nodelist somewhat from the bootstrap nodes. An attacker
   112  	// needs to completely dominate the nodelist and the peerlist to be
   113  	// successful, so just a few honest nodes from requests to the bootstraps
   114  	// should be enough to fend from most attacks.
   115  	acceptInterval = build.Select(build.Var{
   116  		Standard: 6 * time.Second,
   117  		Dev:      3 * time.Second,
   118  		Testing:  100 * time.Millisecond,
   119  	}).(time.Duration)
   120  
   121  	// acquiringPeersDelay defines the amount of time that is waited between
   122  	// iterations of the peer acquisition loop if the gateway is actively
   123  	// forming new connections with peers.
   124  	acquiringPeersDelay = build.Select(build.Var{
   125  		Standard: 5 * time.Second,
   126  		Dev:      3 * time.Second,
   127  		Testing:  500 * time.Millisecond,
   128  	}).(time.Duration)
   129  
   130  	// fullyConnectedThreshold defines the number of peers that the gateway can
   131  	// have before it stops accepting inbound connections.
   132  	fullyConnectedThreshold = build.Select(build.Var{
   133  		Standard: 128,
   134  		Dev:      20,
   135  		Testing:  10,
   136  	}).(int)
   137  
   138  	// maxConcurrentOutboundPeerRequests defines the maximum number of peer
   139  	// connections that the gateway will try to form concurrently.
   140  	maxConcurrentOutboundPeerRequests = build.Select(build.Var{
   141  		Standard: 3,
   142  		Dev:      2,
   143  		Testing:  2,
   144  	}).(int)
   145  
   146  	// noNodesDelay defines the amount of time that is waited between
   147  	// iterations of the peer acquisition loop if the gateway does not have any
   148  	// nodes in the nodelist.
   149  	noNodesDelay = build.Select(build.Var{
   150  		Standard: 20 * time.Second,
   151  		Dev:      10 * time.Second,
   152  		Testing:  3 * time.Second,
   153  	}).(time.Duration)
   154  
   155  	// unwawntedLocalPeerDelay defines the amount of time that is waited
   156  	// between iterations of the permanentPeerManager if the gateway has at
   157  	// least a few outbound peers, but is not well connected, and the recently
   158  	// selected peer was a local peer. The wait is mostly to prevent the
   159  	// gateway from hogging the CPU in the event that all peers are local
   160  	// peers.
   161  	unwantedLocalPeerDelay = build.Select(build.Var{
   162  		Standard: 2 * time.Second,
   163  		Dev:      1 * time.Second,
   164  		Testing:  100 * time.Millisecond,
   165  	}).(time.Duration)
   166  
   167  	// wellConnectedDelay defines the amount of time that is waited between
   168  	// iterations of the peer acquisition loop if the gateway is well
   169  	// connected.
   170  	wellConnectedDelay = build.Select(build.Var{
   171  		Standard: 5 * time.Minute,
   172  		Dev:      1 * time.Minute,
   173  		Testing:  3 * time.Second,
   174  	}).(time.Duration)
   175  
   176  	// wellConnectedThreshold is the number of outbound connections at which
   177  	// the gateway will not attempt to make new outbound connections.
   178  	wellConnectedThreshold = build.Select(build.Var{
   179  		Standard: 8,
   180  		Dev:      5,
   181  		Testing:  4,
   182  	}).(int)
   183  )
   184  
   185  var (
   186  	// connStdDeadline defines the standard deadline that should be used for
   187  	// all temporary connections to the gateway.
   188  	connStdDeadline = build.Select(build.Var{
   189  		Standard: 5 * time.Minute,
   190  		Dev:      2 * time.Minute,
   191  		Testing:  30 * time.Second,
   192  	}).(time.Duration)
   193  
   194  	// the gateway will abort a connection attempt after this long
   195  	dialTimeout = build.Select(build.Var{
   196  		Standard: 3 * time.Minute,
   197  		Dev:      20 * time.Second,
   198  		Testing:  500 * time.Millisecond,
   199  	}).(time.Duration)
   200  
   201  	// rpcStdDeadline defines the standard deadline that should be used for all
   202  	// incoming RPC calls.
   203  	rpcStdDeadline = build.Select(build.Var{
   204  		Standard: 5 * time.Minute,
   205  		Dev:      3 * time.Minute,
   206  		Testing:  5 * time.Second,
   207  	}).(time.Duration)
   208  )
   209  
   210  var (
   211  	// minPeersForIPDiscovery is the minimum number of peer connections we wait
   212  	// for before we try to discover our public ip from them. It is also the
   213  	// minimum number of successful replies we expect from our peers before we
   214  	// accept a result.
   215  	minPeersForIPDiscovery = build.Select(build.Var{
   216  		Standard: 5,
   217  		Dev:      3,
   218  		Testing:  2,
   219  	}).(int)
   220  
   221  	// timeoutIPDiscovery is the time after which managedIPFromPeers will fail
   222  	// if the ip couldn't be discovered successfully.
   223  	timeoutIPDiscovery = build.Select(build.Var{
   224  		Standard: 5 * time.Minute,
   225  		Dev:      5 * time.Minute,
   226  		Testing:  time.Minute,
   227  	}).(time.Duration)
   228  
   229  	// rediscoverIPIntervalSuccess is the time that has to pass after a
   230  	// successful IP discovery before we rediscover the IP.
   231  	rediscoverIPIntervalSuccess = build.Select(build.Var{
   232  		Standard: 3 * time.Hour,
   233  		Dev:      10 * time.Minute,
   234  		Testing:  30 * time.Second,
   235  	}).(time.Duration)
   236  
   237  	// rediscoverIPIntervalFailure is the time that has to pass after a failed
   238  	// IP discovery before we try again.
   239  	rediscoverIPIntervalFailure = build.Select(build.Var{
   240  		Standard: 15 * time.Minute,
   241  		Dev:      1 * time.Minute,
   242  		Testing:  10 * time.Second,
   243  	}).(time.Duration)
   244  
   245  	// peerDiscoveryRetryInterval is the time we wait when there were not
   246  	// enough peers to determine our public ip address before trying again.
   247  	peerDiscoveryRetryInterval = build.Select(build.Var{
   248  		Standard: 10 * time.Second,
   249  		Dev:      1 * time.Second,
   250  		Testing:  100 * time.Millisecond,
   251  	}).(time.Duration)
   252  )