dispatch

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2019 License: Apache-2.0 Imports: 21 Imported by: 0

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.

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.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {

	// PieceRequestMinTimeout is the minimum timeout for all piece requests, regardless of
	// size.
	PieceRequestMinTimeout time.Duration `yaml:"piece_request_min_timeout"`

	// PieceRequestTimeoutPerMb is the duration that will be added to piece request
	// timeouts based on the piece size (in megabytes).
	PieceRequestTimeoutPerMb time.Duration `yaml:"piece_request_timeout_per_mb"`

	// PieceRequestPolicy is the policy that is used to decide which pieces to request
	// from a peer.
	PieceRequestPolicy string `yaml:"piece_request_policy"`

	// PipelineLimit limits the total number of requests can be sent to a peer
	// at the same time.
	PipelineLimit int `yaml:"pipeline_limit"`

	// EndgameThreshold is the number pieces required to complete the torrent
	// before the torrent enters "endgame", where we start overloading piece
	// requests to multiple peers.
	EndgameThreshold int `yaml:"endgame_threshold"`

	DisableEndgame bool `yaml:"disable_endgame"`
}

Config defines the configuration for piece dispatch.

type Dispatcher

type Dispatcher struct {
	// contains filtered or unexported fields
}

Dispatcher coordinates torrent state with sending / receiving messages between multiple peers. As such, Dispatcher and Torrent have a one-to-one relationship, while Dispatcher and Conn have a one-to-many relationship.

func New

func New(
	config Config,
	stats tally.Scope,
	clk clock.Clock,
	netevents networkevent.Producer,
	events Events,
	peerID core.PeerID,
	t storage.Torrent,
	logger *zap.SugaredLogger,
	tlog *torrentlog.Logger) (*Dispatcher, error)

New creates a new Dispatcher.

func (*Dispatcher) AddPeer

func (d *Dispatcher) AddPeer(
	peerID core.PeerID, b *bitset.BitSet, messages Messages) error

AddPeer registers a new peer with the Dispatcher.

func (*Dispatcher) Complete

func (d *Dispatcher) Complete() bool

Complete returns true if d's torrent is complete.

func (*Dispatcher) CreatedAt

func (d *Dispatcher) CreatedAt() time.Time

CreatedAt returns when d was created.

func (*Dispatcher) Digest

func (d *Dispatcher) Digest() core.Digest

Digest returns the blob digest for d's torrent.

func (*Dispatcher) Empty

func (d *Dispatcher) Empty() bool

Empty returns true if the Dispatcher has no peers.

func (*Dispatcher) InfoHash

func (d *Dispatcher) InfoHash() core.InfoHash

InfoHash returns d's torrent hash.

func (*Dispatcher) LastGoodPieceReceived

func (d *Dispatcher) LastGoodPieceReceived(peerID core.PeerID) time.Time

LastGoodPieceReceived returns when d last received a valid and needed piece from peerID.

func (*Dispatcher) LastPieceSent

func (d *Dispatcher) LastPieceSent(peerID core.PeerID) time.Time

LastPieceSent returns when d last sent a piece to peerID.

func (*Dispatcher) LastReadTime

func (d *Dispatcher) LastReadTime() time.Time

LastReadTime returns when d's torrent was last read from.

func (*Dispatcher) LastWriteTime

func (d *Dispatcher) LastWriteTime() time.Time

LastWriteTime returns when d's torrent was last written to.

func (*Dispatcher) Length

func (d *Dispatcher) Length() int64

Length returns d's torrent length.

func (*Dispatcher) NumPeers

func (d *Dispatcher) NumPeers() int

NumPeers returns the number of peers connected to the dispatcher.

func (*Dispatcher) RemoteBitfields

func (d *Dispatcher) RemoteBitfields() conn.RemoteBitfields

RemoteBitfields returns the bitfields of peers connected to the dispatcher.

func (*Dispatcher) Stat

func (d *Dispatcher) Stat() *storage.TorrentInfo

Stat returns d's TorrentInfo.

func (*Dispatcher) String

func (d *Dispatcher) String() string

func (*Dispatcher) TearDown

func (d *Dispatcher) TearDown()

TearDown closes all Dispatcher connections.

type Events

type Events interface {
	DispatcherComplete(*Dispatcher)
}

Events defines Dispatcher events.

type Messages

type Messages interface {
	Send(msg *conn.Message) error
	Receiver() <-chan *conn.Message
	Close()
}

Messages defines a subset of conn.Conn methods which Dispatcher requires to communicate with remote peers.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL