Documentation ¶
Overview ¶
Compute missing pieces for a torrent.
Index ¶
- Constants
- func CreateListener(flags *TorrentFlags) (listener net.Listener, externalPort int, err error)
- func ListenForPeerConnections(flags *TorrentFlags) (conChan chan *btConn, listener net.Listener, listenPort int, err error)
- func NewPeerState(conn net.Conn) *peerState
- func SaveTorrent(meta *MetaInfo) string
- func WriteMetaInfoBytes(root string, w io.Writer) (err error)
- type Accumulator
- type ActivePiece
- type Bitset
- func (b *Bitset) AndNot(b2 *Bitset)
- func (b *Bitset) Bytes() []byte
- func (b *Bitset) Clear(index int)
- func (b *Bitset) FindNextClear(index int) int
- func (b *Bitset) FindNextSet(index int) int
- func (b *Bitset) InRange(index int) bool
- func (b *Bitset) IsEndValid() bool
- func (b *Bitset) IsSet(index int) bool
- func (b *Bitset) Len() int
- func (b *Bitset) Set(index int)
- type ByDownloadBPS
- type ChokePolicy
- type Choker
- type ClassicChokePolicy
- type ClientStatusReport
- type Dialer
- type ExtensionHandshake
- type File
- type FileDict
- type FileStore
- type FileStoreFileAdapter
- type FileStoreFileSystemAdapter
- type FileSystem
- type InfoDict
- type MetaDataExchange
- type MetaInfo
- type MetaInfoFile
- type MetaInfoFileSystem
- type MetadataMessage
- type NeverChokePolicy
- type OSMetaInfoFileSystem
- type SessionInfo
- type TorrentClient
- type TorrentFlags
- type TorrentSession
- func (t *TorrentSession) AcceptNewPeer(btconn *btConn)
- func (t *TorrentSession) AddPeer(btconn *btConn)
- func (t *TorrentSession) ChoosePiece(p *peerState) (piece int)
- func (t *TorrentSession) ClosePeer(peer *peerState)
- func (t *TorrentSession) DoExtension(msg []byte, p *peerState) (err error)
- func (t *TorrentSession) DoMessage(p *peerState, message []byte) (err error)
- func (t *TorrentSession) DoMetadata(msg []byte, p *peerState)
- func (t *TorrentSession) DoTorrent()
- func (ts *TorrentSession) Header() (header []byte)
- func (ts *TorrentSession) HintNewPeer(peer string)
- func (t *TorrentSession) Quit() (err error)
- func (t *TorrentSession) RecordBlock(p *peerState, piece, begin, length uint32) (err error)
- func (t *TorrentSession) RequestBlock(p *peerState) (err error)
- func (t *TorrentSession) RequestBlock2(p *peerState, piece int, endGame bool) (err error)
- func (t *TorrentSession) Shutdown() (err error)
- type TrackerResponse
Constants ¶
const ( MAX_NUM_PEERS = 60 TARGET_NUM_PEERS = 15 )
const ( CHOKE = iota UNCHOKE INTERESTED NOT_INTERESTED HAVE BITFIELD REQUEST PIECE CANCEL PORT // Not implemented. For DHT support. EXTENSION = 20 )
BitTorrent message types. Sources: http://bittorrent.org/beps/bep_0003.html http://wiki.theory.org/BitTorrentSpecification
const ( METADATA_REQUEST = iota METADATA_DATA METADATA_REJECT )
const (
EXTENSION_HANDSHAKE = iota
)
const HIGH_BANDWIDTH_SLOTS = 3
const MAX_OUR_REQUESTS = 2
const MAX_PEER_REQUESTS = 10
const MinimumPieceLength = 16 * 1024
const OPTIMISTIC_UNCHOKE_COUNT = 3
How many cycles of this algorithm before we pick a new optimistic
const OPTIMISTIC_UNCHOKE_INDEX = HIGH_BANDWIDTH_SLOTS
const STANDARD_BLOCK_LENGTH = 16 * 1024
const TargetPieceCountLog2 = 10
const TargetPieceCountMax = TargetPieceCountMin << 1
Target piece count should be < TargetPieceCountMax
const TargetPieceCountMin = 1 << TargetPieceCountLog2
Variables ¶
This section is empty.
Functions ¶
func CreateListener ¶
func CreateListener(flags *TorrentFlags) (listener net.Listener, externalPort int, err error)
func ListenForPeerConnections ¶
func ListenForPeerConnections(flags *TorrentFlags) (conChan chan *btConn, listener net.Listener, listenPort int, err error)
listenForPeerConnections listens on a TCP port for incoming connections and demuxes them to the appropriate active torrentSession based on the InfoHash in the header.
func NewPeerState ¶
func SaveTorrent ¶
Types ¶
type Accumulator ¶
type Accumulator struct {
// contains filtered or unexported fields
}
An accumulator that keeps track of the rate of increase.
func NewAccumulator ¶
func NewAccumulator(now time.Time, maxRatePeriod time.Duration) (acc *Accumulator)
func (*Accumulator) DurationUntilRate ¶
func (*Accumulator) GetRateNoUpdate ¶
func (a *Accumulator) GetRateNoUpdate() float64
type ActivePiece ¶
type ActivePiece struct {
// contains filtered or unexported fields
}
type Bitset ¶
type Bitset struct {
// contains filtered or unexported fields
}
func NewBitsetFromBytes ¶
Creates a new bitset from a given byte stream. Returns nil if the data is invalid in some way.
func (*Bitset) IsEndValid ¶
type ByDownloadBPS ¶
type ByDownloadBPS []Choker
func (ByDownloadBPS) Len ¶
func (a ByDownloadBPS) Len() int
func (ByDownloadBPS) Less ¶
func (a ByDownloadBPS) Less(i, j int) bool
func (ByDownloadBPS) Swap ¶
func (a ByDownloadBPS) Swap(i, j int)
type ChokePolicy ¶
type Choker ¶
type Choker interface {
DownloadBPS() float32 // bps
}
The choking policy's view of a peer. For current policies we only care about identity and download bandwidth.
type ClassicChokePolicy ¶
type ClassicChokePolicy struct {
// contains filtered or unexported fields
}
Our interpretation of the classic bittorrent choke policy. Expects to be called once every 10 seconds. See the section "Choking and optimistic unchoking" in https://wiki.theory.org/BitTorrentSpecification
type ClientStatusReport ¶
type ExtensionHandshake ¶
type FileStore ¶
A torrent file store.
func NewFileStore ¶
func NewFileStore(info *InfoDict, fileSystem FileSystem) (f FileStore, totalSize int64, err error)
type FileStoreFileAdapter ¶
type FileStoreFileAdapter struct {
// contains filtered or unexported fields
}
func (*FileStoreFileAdapter) Close ¶
func (f *FileStoreFileAdapter) Close() (err error)
type FileStoreFileSystemAdapter ¶
type FileStoreFileSystemAdapter struct {
// contains filtered or unexported fields
}
Adapt a MetaInfoFileSystem into a torrent file store FileSystem
type FileSystem ¶
Interface for a file system. A file system contains files.
func NewOSFileSystem ¶
func NewOSFileSystem(directory string) (fs FileSystem, err error)
type MetaDataExchange ¶
type MetaInfo ¶
type MetaInfo struct { Info InfoDict InfoHash string Announce string AnnounceList [][]string `bencode:"announce-list"` CreationDate string `bencode:"creation date"` Comment string CreatedBy string `bencode:"created by"` Encoding string }
func CreateMetaInfoFromFileSystem ¶
func CreateMetaInfoFromFileSystem(fs MetaInfoFileSystem, root string, pieceLength int64, wantMD5Sum bool) (metaInfo *MetaInfo, err error)
Create a MetaInfo for a given file and file system. If fs is nil then the OSMetaInfoFileSystem will be used. If pieceLength is 0 then an optimal piece length will be chosen.
func (*MetaInfo) UpdateInfoHash ¶
Updates the InfoHash field. Call this after manually changing the Info data.
type MetaInfoFile ¶
type MetaInfoFileSystem ¶
type MetadataMessage ¶
type OSMetaInfoFileSystem ¶
type OSMetaInfoFileSystem struct {
// contains filtered or unexported fields
}
func (*OSMetaInfoFileSystem) Open ¶
func (o *OSMetaInfoFileSystem) Open(name string) (MetaInfoFile, error)
type SessionInfo ¶
type TorrentClient ¶
type TorrentClient struct { Flags *TorrentFlags ListenPort int DoneConn chan *TorrentSession Sessions map[string]*TorrentSession // contains filtered or unexported fields }
func NewTorrentClient ¶
func NewTorrentClient(dir string, port int) *TorrentClient
func (*TorrentClient) Download ¶
func (c *TorrentClient) Download(meta *MetaInfo) *TorrentSession
func (*TorrentClient) Serve ¶
func (c *TorrentClient) Serve(torrentfile string) *TorrentSession
func (*TorrentClient) Shutdown ¶
func (c *TorrentClient) Shutdown()
func (*TorrentClient) Unserve ¶
func (c *TorrentClient) Unserve(session *TorrentSession)
type TorrentFlags ¶
type TorrentSession ¶
type TorrentSession struct { Done chan bool M *MetaInfo TorrentFile string // contains filtered or unexported fields }
func NewTorrentSession ¶
func NewTorrentSession(flags *TorrentFlags, torrent string, listenPort uint16) (ts *TorrentSession, err error)
func (*TorrentSession) AcceptNewPeer ¶
func (t *TorrentSession) AcceptNewPeer(btconn *btConn)
func (*TorrentSession) AddPeer ¶
func (t *TorrentSession) AddPeer(btconn *btConn)
Can be called from any goroutine
func (*TorrentSession) ChoosePiece ¶
func (t *TorrentSession) ChoosePiece(p *peerState) (piece int)
func (*TorrentSession) ClosePeer ¶
func (t *TorrentSession) ClosePeer(peer *peerState)
func (*TorrentSession) DoExtension ¶
func (t *TorrentSession) DoExtension(msg []byte, p *peerState) (err error)
func (*TorrentSession) DoMessage ¶
func (t *TorrentSession) DoMessage(p *peerState, message []byte) (err error)
func (*TorrentSession) DoMetadata ¶
func (t *TorrentSession) DoMetadata(msg []byte, p *peerState)
func (*TorrentSession) DoTorrent ¶
func (t *TorrentSession) DoTorrent()
func (*TorrentSession) Header ¶
func (ts *TorrentSession) Header() (header []byte)
func (*TorrentSession) HintNewPeer ¶
func (ts *TorrentSession) HintNewPeer(peer string)
Try to connect if the peer is not already in our peers. Can be called from any goroutine.
func (*TorrentSession) Quit ¶
func (t *TorrentSession) Quit() (err error)
func (*TorrentSession) RecordBlock ¶
func (t *TorrentSession) RecordBlock(p *peerState, piece, begin, length uint32) (err error)
func (*TorrentSession) RequestBlock ¶
func (t *TorrentSession) RequestBlock(p *peerState) (err error)
func (*TorrentSession) RequestBlock2 ¶
func (t *TorrentSession) RequestBlock2(p *peerState, piece int, endGame bool) (err error)
func (*TorrentSession) Shutdown ¶
func (t *TorrentSession) Shutdown() (err error)