github.com/mutagen-io/mutagen@v0.18.0-rc1/pkg/multiplexing/configuration.go (about)

     1  package multiplexing
     2  
     3  import (
     4  	"time"
     5  )
     6  
     7  // Configuration encodes multiplexer configuration.
     8  type Configuration struct {
     9  	// StreamReceiveWindow is the size (in bytes) of the stream receive window
    10  	// (which also sets the size of the local per-stream receive buffer). If
    11  	// less than or equal to 0, then no inbound data will be allowed and all
    12  	// writes on the other end of the stream will block until write deadline
    13  	// expiration or a call to CloseWrite or Close. The default value is 64 kB.
    14  	StreamReceiveWindow int
    15  	// WriteBufferCount is the number of write buffers to use within the
    16  	// multiplexer. Each write buffer contains a fixed amount of internal
    17  	// storage, currently 65548 bytes. If less than or equal to 0, then a single
    18  	// write buffer will be created. The default is 5.
    19  	WriteBufferCount int
    20  	// AcceptBacklog is the maximum number of concurrent pending inbound open
    21  	// requests that will be allowed. If less than or equal to 0, then it will
    22  	// be set to 1. The default value is 10.
    23  	AcceptBacklog int
    24  	// HeartbeatTransmitInterval is the interval on which heartbeats will be
    25  	// transmitted. If less than or equal to 0, then heartbeat transmission will
    26  	// be disabled. The default interval is 5 seconds.
    27  	HeartbeatTransmitInterval time.Duration
    28  	// MaximumHeartbeatReceiveInterval is the maximum amount of time that the
    29  	// multiplexer will be allowed to operate without receiving a heartbeat
    30  	// message from the remote. If less than or equal to 0, remote heartbeats
    31  	// will be processed but not required. The default interval is 10 seconds.
    32  	MaximumHeartbeatReceiveInterval time.Duration
    33  }
    34  
    35  // DefaultConfiguration returns the default multiplexer configuration.
    36  func DefaultConfiguration() *Configuration {
    37  	return &Configuration{
    38  		StreamReceiveWindow:             (1 << 16) - 1, // 65535 bytes
    39  		WriteBufferCount:                5,
    40  		AcceptBacklog:                   10,
    41  		HeartbeatTransmitInterval:       5 * time.Second,
    42  		MaximumHeartbeatReceiveInterval: 10 * time.Second,
    43  	}
    44  }
    45  
    46  // normalize normalizes out-of-range configuration values.
    47  func (c *Configuration) normalize() {
    48  	if c.StreamReceiveWindow < 0 {
    49  		c.StreamReceiveWindow = 0
    50  	}
    51  	if c.WriteBufferCount <= 0 {
    52  		c.WriteBufferCount = 1
    53  	}
    54  	if c.AcceptBacklog <= 0 {
    55  		c.AcceptBacklog = 1
    56  	}
    57  	if c.HeartbeatTransmitInterval < 0 {
    58  		c.HeartbeatTransmitInterval = 0
    59  	}
    60  	if c.MaximumHeartbeatReceiveInterval < 0 {
    61  		c.MaximumHeartbeatReceiveInterval = 0
    62  	}
    63  }