github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/network/netconf/unicast.go (about) 1 package netconf 2 3 import "time" 4 5 const ( 6 rateLimiterKey = "rate-limiter" 7 unicastManagerKey = "manager" 8 enableStreamProtectionKey = "enable-stream-protection" 9 MessageTimeoutKey = "message-timeout" 10 ) 11 12 // Unicast configuration parameters for the unicast protocol. 13 type Unicast struct { 14 // RateLimiter configuration for all unicast rate limiters. 15 RateLimiter RateLimiter `mapstructure:"rate-limiter"` 16 17 // UnicastManager configuration for the unicast manager. The unicast manager is responsible for establishing unicast streams. 18 UnicastManager UnicastManager `mapstructure:"manager"` 19 20 // EnableStreamProtection enables stream protection for unicast streams. When enabled, all connections that are being established or 21 // have been already established for unicast streams are protected, meaning that they won't be closed by the connection manager. 22 // This is useful for preventing the connection manager from closing unicast streams that are being used by the application layer. 23 // However, it may interfere with the resource manager of libp2p, i.e., the connection manager may not be able to close connections 24 // that are not being used by the application layer while at the same time the node is running out of resources for new connections. 25 EnableStreamProtection bool `mapstructure:"enable-stream-protection"` 26 27 MessageTimeout time.Duration `validate:"gt=0s" mapstructure:"message-timeout"` 28 } 29 30 const ( 31 DryRunKey = "dry-run" 32 LockoutDurationKey = "lockout-duration" 33 messageRateLimitKey = "message-rate-limit" 34 BandwidthRateLimitKey = "bandwidth-rate-limit" 35 BandwidthBurstLimitKey = "bandwidth-burst-limit" 36 ) 37 38 // RateLimiter unicast rate limiter configuration for the message and bandwidth rate limiters. 39 type RateLimiter struct { 40 // DryRun setting this to true will disable connection disconnects and gating when unicast rate limiters are configured 41 DryRun bool `mapstructure:"dry-run"` 42 // LockoutDuration the number of seconds a peer will be forced to wait before being allowed to successfully reconnect to the node 43 // after being rate limited. 44 LockoutDuration time.Duration `validate:"gte=0" mapstructure:"lockout-duration"` 45 // MessageRateLimit amount of unicast messages that can be sent by a peer per second. 46 MessageRateLimit int `validate:"gte=0" mapstructure:"message-rate-limit"` 47 // BandwidthRateLimit bandwidth size in bytes a peer is allowed to send via unicast streams per second. 48 BandwidthRateLimit int `validate:"gte=0" mapstructure:"bandwidth-rate-limit"` 49 // BandwidthBurstLimit bandwidth size in bytes a peer is allowed to send via unicast streams at once. 50 BandwidthBurstLimit int `validate:"gte=0" mapstructure:"bandwidth-burst-limit"` 51 } 52 53 const ( 54 createStreamBackoffDelayKey = "create-stream-retry-delay" 55 streamZeroRetryResetThresholdKey = "stream-zero-retry-reset-threshold" 56 maxStreamCreationRetryAttemptTimesKey = "max-stream-creation-retry-attempt-times" 57 configCacheSizeKey = "dial-config-cache-size" 58 ) 59 60 // UnicastManager configuration for the unicast manager. The unicast manager is responsible for establishing unicast streams. 61 type UnicastManager struct { 62 // CreateStreamBackoffDelay initial delay used in the exponential backoff for create stream retries. 63 CreateStreamBackoffDelay time.Duration `validate:"gt=0s" mapstructure:"create-stream-retry-delay"` 64 // StreamZeroRetryResetThreshold is the threshold that determines when to reset the stream creation retry budget to the default value. 65 // 66 // For example the default value of 100 means that if the stream creation retry budget is decreased to 0, then it will be reset to default value 67 // when the number of consecutive successful streams reaches 100. 68 // 69 // This is to prevent the retry budget from being reset too frequently, as the retry budget is used to gauge the reliability of the stream creation. 70 // When the stream creation retry budget is reset to the default value, it means that the stream creation is reliable enough to be trusted again. 71 // This parameter mandates when the stream creation is reliable enough to be trusted again; i.e., when the number of consecutive successful streams reaches this threshold. 72 // Note that the counter is reset to 0 when the stream creation fails, so the value of for example 100 means that the stream creation is reliable enough that the recent 73 // 100 stream creations are all successful. 74 StreamZeroRetryResetThreshold uint64 `validate:"gt=0" mapstructure:"stream-zero-retry-reset-threshold"` 75 // MaxStreamCreationRetryAttemptTimes is the maximum number of attempts to be made to create a stream to a remote node over a direct unicast (1:1) connection before we give up. 76 MaxStreamCreationRetryAttemptTimes uint64 `validate:"gt=1" mapstructure:"max-stream-creation-retry-attempt-times"` 77 // ConfigCacheSize is the cache size of the dial config cache that keeps the individual dial config for each peer. 78 ConfigCacheSize uint32 `validate:"gt=0" mapstructure:"dial-config-cache-size"` 79 }