Documentation ¶
Overview ¶
Copyright (c) 2016-2019 Uber Technologies, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright (c) 2016-2019 Uber Technologies, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Variables
- type BlacklistedConn
- type Config
- type State
- func (s *State) ActiveConns() []*conn.Conn
- func (s *State) AddPending(peerID core.PeerID, h core.InfoHash, neighbors []core.PeerID) error
- func (s *State) Blacklist(peerID core.PeerID, h core.InfoHash) error
- func (s *State) BlacklistSnapshot() []BlacklistedConn
- func (s *State) Blacklisted(peerID core.PeerID, h core.InfoHash) bool
- func (s *State) ClearBlacklist(h core.InfoHash)
- func (s *State) DeleteActive(c *conn.Conn)
- func (s *State) DeletePending(peerID core.PeerID, h core.InfoHash)
- func (s *State) MovePendingToActive(c *conn.Conn) error
- func (s *State) Saturated(h core.InfoHash) bool
Constants ¶
This section is empty.
Variables ¶
var ( ErrTorrentAtCapacity = errors.New("torrent is at capacity") ErrConnAlreadyPending = errors.New("conn is already pending") ErrConnAlreadyActive = errors.New("conn is already active") ErrConnClosed = errors.New("conn is closed") ErrInvalidActiveTransition = errors.New("conn must be pending to transition to active") ErrTooManyMutualConns = errors.New("conn has too many mutual connections") )
State errors.
Functions ¶
This section is empty.
Types ¶
type BlacklistedConn ¶
type BlacklistedConn struct { PeerID core.PeerID `json:"peer_id"` InfoHash core.InfoHash `json:"info_hash"` Remaining time.Duration `json:"remaining"` }
BlacklistedConn represents a connection which has been blacklisted.
type Config ¶
type Config struct { // MaxOpenConnectionsPerTorrent is the maximum number of connections which a // Scheduler will maintain at once for each torrent. MaxOpenConnectionsPerTorrent int `yaml:"max_open_conn"` // MaxMutualConnections is the maximum number of mutual connections a peer // can have and still connect with us. MaxMutualConnections int `yaml:"max_mutual_conn"` // DisableBlacklist disables the blacklisting of peers. Should only be used // for testing purposes. DisableBlacklist bool `yaml:"disable_blacklist"` // BlacklistDuration is the duration a connection will remain blacklisted. BlacklistDuration time.Duration `yaml:"blacklist_duration"` }
Config defines State configuration.
type State ¶
type State struct {
// contains filtered or unexported fields
}
State provides connection lifecycle management and enforces connection limits. A connection to a peer is identified by torrent info hash and peer id. Each connection may exist in the following states: pending, active, or blacklisted. Pending connections are unestablished connections which "reserve" connection capacity until they are done handshaking. Active connections are established connections. Blacklisted connections are failed connections which should be skipped in each peer handout.
Note, State is NOT thread-safe. Synchronization must be provided by the client.
func New ¶
func New( config Config, clk clock.Clock, localPeerID core.PeerID, netevents networkevent.Producer, logger *zap.SugaredLogger) *State
New creates a new State.
func (*State) ActiveConns ¶
ActiveConns returns a list of all active connections.
func (*State) AddPending ¶
AddPending sets the connection for peerID/h as pending and reserves capacity for it.
func (*State) Blacklist ¶
Blacklist blacklists peerID/h for the configured BlacklistDuration. Returns error if the connection is already blacklisted.
func (*State) BlacklistSnapshot ¶
func (s *State) BlacklistSnapshot() []BlacklistedConn
BlacklistSnapshot returns a snapshot of all valid blacklist entries.
func (*State) Blacklisted ¶
Blacklisted returns true if peerID/h is blacklisted.
func (*State) ClearBlacklist ¶
ClearBlacklist un-blacklists all connections for h.
func (*State) DeleteActive ¶
DeleteActive deletes c. No-ops if c is not an active conn.
func (*State) DeletePending ¶
DeletePending deletes the pending connection for peerID/h and frees capacity.
func (*State) MovePendingToActive ¶
MovePendingToActive sets a previously pending connection as active.