github.com/uber/kraken@v0.1.4/lib/torrent/scheduler/connstate/config.go (about)

     1  // Copyright (c) 2016-2019 Uber Technologies, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  package connstate
    15  
    16  import "time"
    17  
    18  // Config defines State configuration.
    19  type Config struct {
    20  
    21  	// MaxOpenConnectionsPerTorrent is the maximum number of connections which a
    22  	// Scheduler will maintain at once for each torrent.
    23  	MaxOpenConnectionsPerTorrent int `yaml:"max_open_conn"`
    24  
    25  	// MaxMutualConnections is the maximum number of mutual connections a peer
    26  	// can have and still connect with us.
    27  	MaxMutualConnections int `yaml:"max_mutual_conn"`
    28  
    29  	// DisableBlacklist disables the blacklisting of peers. Should only be used
    30  	// for testing purposes.
    31  	DisableBlacklist bool `yaml:"disable_blacklist"`
    32  
    33  	// BlacklistDuration is the duration a connection will remain blacklisted.
    34  	BlacklistDuration time.Duration `yaml:"blacklist_duration"`
    35  }
    36  
    37  func (c Config) applyDefaults() Config {
    38  	if c.MaxOpenConnectionsPerTorrent == 0 {
    39  		c.MaxOpenConnectionsPerTorrent = 10
    40  	}
    41  	// Defaults to no mutual connection limit.
    42  	if c.MaxMutualConnections == 0 {
    43  		c.MaxMutualConnections = c.MaxOpenConnectionsPerTorrent
    44  	}
    45  	if c.BlacklistDuration == 0 {
    46  		c.BlacklistDuration = 30 * time.Second
    47  	}
    48  	return c
    49  }