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 ¶
- func PipeFixture(config Config, info *storage.TorrentInfo) (local *Conn, remote *Conn, cleanupFunc func())
- type Config
- type Conn
- func (c *Conn) Close()
- func (c *Conn) CreatedAt() time.Time
- func (c *Conn) InfoHash() core.InfoHash
- func (c *Conn) IsClosed() bool
- func (c *Conn) PeerID() core.PeerID
- func (c *Conn) Receiver() <-chan *Message
- func (c *Conn) Send(msg *Message) error
- func (c *Conn) Start()
- func (c *Conn) String() string
- type Events
- type FakePeer
- type HandshakeResult
- type Handshaker
- func (h *Handshaker) Accept(nc net.Conn) (*PendingConn, error)
- func (h *Handshaker) Establish(pc *PendingConn, info *storage.TorrentInfo, remoteBitfields RemoteBitfields) (*Conn, error)
- func (h *Handshaker) Initialize(peerID core.PeerID, addr string, info *storage.TorrentInfo, ...) (*HandshakeResult, error)
- type Message
- func NewAnnouncePieceMessage(index int) *Message
- func NewCompleteMessage() *Message
- func NewErrorMessage(index int, code p2p.ErrorMessage_ErrorCode, err error) *Message
- func NewPiecePayloadMessage(index int, pr storage.PieceReader) *Message
- func NewPieceRequestMessage(index int, length int64) *Message
- type PendingConn
- func (pc *PendingConn) Bitfield() *bitset.BitSet
- func (pc *PendingConn) Close()
- func (pc *PendingConn) Digest() core.Digest
- func (pc *PendingConn) InfoHash() core.InfoHash
- func (pc *PendingConn) Namespace() string
- func (pc *PendingConn) PeerID() core.PeerID
- func (pc *PendingConn) RemoteBitfields() RemoteBitfields
- type RemoteBitfields
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PipeFixture ¶
func PipeFixture( config Config, info *storage.TorrentInfo) (local *Conn, remote *Conn, cleanupFunc func())
PipeFixture returns Conns for both sides of a live connection for testing.
Types ¶
type Config ¶
type Config struct { // HandshakeTimeout is the timeout for dialing, writing, and reading connections // during handshake. HandshakeTimeout time.Duration `yaml:"handshake_timeout"` // SenderBufferSize is the size of the sender channel for a connection. // Prevents writers to the connection from being blocked if there are many // writers trying to send messages at the same time. SenderBufferSize int `yaml:"sender_buffer_size"` // ReceiverBufferSize is the size of the receiver channel for a connection. // Prevents the connection reader from being blocked if a receiver consumer // is taking a long time to process a message. ReceiverBufferSize int `yaml:"receiver_buffer_size"` Bandwidth bandwidth.Config `yaml:"bandwidth"` }
Config is the configuration for individual live connections.
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn manages peer communication over a connection for multiple torrents. Inbound messages are multiplexed based on the torrent they pertain to.
func (*Conn) InfoHash ¶
InfoHash returns the info hash for the torrent being transmitted over this connection.
func (*Conn) Receiver ¶
Receiver returns a read-only channel for reading incoming messages off the connection.
type FakePeer ¶ added in v0.1.3
type FakePeer struct {
// contains filtered or unexported fields
}
FakePeer is a testing utility which reciprocates handshakes against arbitrary incoming connections, parroting back the requested torrent but with an empty bitfield (so no pieces are requested).
Useful for initializing real Conns against a motionless peer.
func NewFakePeer ¶ added in v0.1.3
NewFakePeer creates and starts a new FakePeer.
type HandshakeResult ¶
type HandshakeResult struct { Conn *Conn Bitfield *bitset.BitSet RemoteBitfields RemoteBitfields }
HandshakeResult wraps data returned from a successful handshake.
type Handshaker ¶
type Handshaker struct {
// contains filtered or unexported fields
}
Handshaker defines the handshake protocol for establishing connections to other peers.
func HandshakerFixture ¶
func HandshakerFixture(config Config) *Handshaker
HandshakerFixture returns a Handshaker for testing.
func NewHandshaker ¶
func NewHandshaker( config Config, stats tally.Scope, clk clock.Clock, networkEvents networkevent.Producer, peerID core.PeerID, events Events, logger *zap.SugaredLogger) (*Handshaker, error)
NewHandshaker creates a new Handshaker.
func (*Handshaker) Accept ¶
func (h *Handshaker) Accept(nc net.Conn) (*PendingConn, error)
Accept upgrades a raw network connection opened by a remote peer into a PendingConn.
func (*Handshaker) Establish ¶
func (h *Handshaker) Establish( pc *PendingConn, info *storage.TorrentInfo, remoteBitfields RemoteBitfields) (*Conn, error)
Establish upgrades a PendingConn returned via Accept into a fully established Conn.
func (*Handshaker) Initialize ¶
func (h *Handshaker) Initialize( peerID core.PeerID, addr string, info *storage.TorrentInfo, remoteBitfields RemoteBitfields, namespace string) (*HandshakeResult, error)
Initialize returns a fully established Conn for the given torrent to the given peer / address. Also returns the bitfield of the remote peer and its connections for the torrent.
type Message ¶
type Message struct { Message *p2p.Message Payload storage.PieceReader }
Message joins a protobuf message with an optional payload. The only p2p.Message type which should include a payload is PiecePayloadMessage.
func NewAnnouncePieceMessage ¶
NewAnnouncePieceMessage returns a Message for announcing a piece.
func NewCompleteMessage ¶
func NewCompleteMessage() *Message
NewCompleteMessage returns a Message for a completed torrent.
func NewErrorMessage ¶
func NewErrorMessage(index int, code p2p.ErrorMessage_ErrorCode, err error) *Message
NewErrorMessage returns a Message for indicating an error.
func NewPiecePayloadMessage ¶
func NewPiecePayloadMessage(index int, pr storage.PieceReader) *Message
NewPiecePayloadMessage returns a Message for sending a piece payload.
func NewPieceRequestMessage ¶
NewPieceRequestMessage returns a Message for requesting a piece.
type PendingConn ¶
type PendingConn struct {
// contains filtered or unexported fields
}
PendingConn represents half-opened, pending connection initialized by a remote peer.
func (*PendingConn) Bitfield ¶
func (pc *PendingConn) Bitfield() *bitset.BitSet
Bitfield returns the bitfield of the remote peer's torrent.
func (*PendingConn) Digest ¶
func (pc *PendingConn) Digest() core.Digest
Digest returns the digest of the blob the remote peer wants to open.
func (*PendingConn) InfoHash ¶
func (pc *PendingConn) InfoHash() core.InfoHash
InfoHash returns the info hash of the torrent the remote peer wants to open.
func (*PendingConn) Namespace ¶
func (pc *PendingConn) Namespace() string
Namespace returns the namespace of the remote peer's torrent.
func (*PendingConn) PeerID ¶
func (pc *PendingConn) PeerID() core.PeerID
PeerID returns the remote peer id.
func (*PendingConn) RemoteBitfields ¶
func (pc *PendingConn) RemoteBitfields() RemoteBitfields
RemoteBitfields returns the bitfield of the remote peer's torrent.