Documentation ¶
Overview ¶
swarm package provides compelete bittorrent client that tracks 1 swarm
Index ¶
- Constants
- Variables
- type Holder
- func (h *Holder) Close(announce bool)
- func (h *Holder) ForEachTorrent(visit func(*Torrent))
- func (h *Holder) ForEachTorrentParallel(visit func(*Torrent))
- func (h *Holder) GetTorrent(ih common.Infohash) (t *Torrent)
- func (h *Holder) GetTorrentByID(id int64) (t *Torrent)
- func (h *Holder) TorrentIDs() (ids map[int64]string)
- func (h *Holder) VisitTorrent(ih common.Infohash, visit func(*Torrent))
- type InfohashList
- type PEXSwarmState
- type PeerConn
- func (c *PeerConn) Bitfield() *bittorrent.Bitfield
- func (c *PeerConn) Chocking() bool
- func (c *PeerConn) Choke()
- func (c *PeerConn) Close()
- func (c *PeerConn) HasPiece(piece uint32) bool
- func (c *PeerConn) RemoteChoking() bool
- func (c *PeerConn) Send(msg common.WireMessage)
- func (c *PeerConn) Stats() (st *PeerConnStats)
- func (c *PeerConn) SupportsI2PPEX() bool
- func (c *PeerConn) SupportsLNPEX() bool
- func (c *PeerConn) Unchoke()
- type PeerConnStats
- type PiecePicker
- type Swarm
- func (sw *Swarm) AddMagnet(uri string) (err error)
- func (sw *Swarm) AddOpenTracker(url string)
- func (sw *Swarm) AddRemoteTorrent(remote string) (err error)
- func (sw *Swarm) AddTorrent(t storage.Torrent) (err error)
- func (sw *Swarm) Close() (err error)
- func (sw *Swarm) IsOnline() bool
- func (sw *Swarm) LostNetwork()
- func (sw *Swarm) Network() network.Network
- func (sw *Swarm) ObtainedNetwork(n network.Network)
- func (sw *Swarm) Run() error
- func (sw *Swarm) Running() bool
- type SwarmBandwidth
- type SwarmStatus
- type Torrent
- func (t *Torrent) AddedAt() time.Time
- func (t *Torrent) AnnounceSeed()
- func (t *Torrent) Bitfield() *bittorrent.Bitfield
- func (t *Torrent) Close() error
- func (t *Torrent) Delete() error
- func (t *Torrent) DialPeer(a net.Addr, id common.PeerID) error
- func (t *Torrent) Done() bool
- func (t *Torrent) DownloadDir() string
- func (t *Torrent) GetStatus() TorrentStatus
- func (t *Torrent) HasIBConn(a net.Addr) (has bool)
- func (t *Torrent) HasOBConn(a net.Addr) (has bool)
- func (t *Torrent) Infohash() common.Infohash
- func (t *Torrent) MetaInfo() *metainfo.TorrentFile
- func (t *Torrent) Name() string
- func (t *Torrent) NeedsPeers() bool
- func (t *Torrent) NumPeers() (count uint)
- func (t *Torrent) PersistPeer(a net.Addr, id common.PeerID)
- func (t *Torrent) Private() bool
- func (t *Torrent) RX() (rx int64)
- func (t *Torrent) Ready() bool
- func (t *Torrent) Remove() error
- func (t *Torrent) SetPieceWindow(n int)
- func (t *Torrent) ShouldAcceptNewPeer() bool
- func (t *Torrent) Start() error
- func (t *Torrent) StartAnnouncing()
- func (t *Torrent) Stop() error
- func (t *Torrent) StopAnnouncing(announce bool)
- func (t *Torrent) TX() (tx int64)
- func (t *Torrent) VisitPeers(v func(*PeerConn))
- type TorrentFileInfo
- type TorrentPeers
- type TorrentState
- type TorrentStatus
- type TorrentStatusList
- type TorrentsList
Constants ¶
const BlockSize = 1024 * 16
how big should we download pieces at a time (bytes)?
const Checking = TorrentState("checking")
const DefaultAnnounceNumWant = 10
const DefaultAnnouncePort = 6881
const DefaultMaxParallelRequests = 4
const DefaultMaxSwarmPeers = 50
max peers peer swarm default
const DefaultPEXDialect = extensions.I2PPeerExchange
const Downloading = TorrentState("downloading")
const RateDownload = "download"
rate name for download
const RateUpload = "upload"
rate name for upload
const Seeding = TorrentState("seeding")
const Stopped = TorrentState("stopped")
Variables ¶
var ErrAlreadyStarted = errors.New("torrent already started")
var ErrAlreadyStopped = errors.New("torrent already stopped")
Functions ¶
This section is empty.
Types ¶
type Holder ¶
torrent swarm container
func (*Holder) ForEachTorrent ¶
func (*Holder) ForEachTorrentParallel ¶
func (*Holder) GetTorrent ¶
find a torrent by infohash returns nil if we don't have a torrent with this infohash
func (*Holder) GetTorrentByID ¶
func (*Holder) TorrentIDs ¶
type InfohashList ¶
type InfohashList []string
func (InfohashList) Len ¶
func (l InfohashList) Len() int
func (InfohashList) Less ¶
func (l InfohashList) Less(i, j int) bool
func (*InfohashList) Swap ¶
func (l *InfohashList) Swap(i, j int)
type PEXSwarmState ¶
type PEXSwarmState struct {
// contains filtered or unexported fields
}
PEXSwarmState manages PeerExchange state on a bittorrent swarm
func (*PEXSwarmState) PopDestHashLists ¶
func (p *PEXSwarmState) PopDestHashLists() (connected, disconnected []byte)
PopDestHashList gets list of i2p destination hashes of currently active and disconnected peers
type PeerConn ¶
type PeerConn struct { Done func() MaxParalellRequests int // contains filtered or unexported fields }
a peer connection
func (*PeerConn) Bitfield ¶
func (c *PeerConn) Bitfield() *bittorrent.Bitfield
func (*PeerConn) RemoteChoking ¶
return true if this peer is choking us otherwise return false
func (*PeerConn) Send ¶
func (c *PeerConn) Send(msg common.WireMessage)
queue a send of a bittorrent wire message to this peer
func (*PeerConn) Stats ¶
func (c *PeerConn) Stats() (st *PeerConnStats)
get stats for this connection
func (*PeerConn) SupportsI2PPEX ¶
func (*PeerConn) SupportsLNPEX ¶
type PeerConnStats ¶
type PeerConnStats struct { TX float64 RX float64 ID string Client string Addr string UsInterested bool UsChoking bool ThemInterested bool ThemChoking bool Downloading bool Inbound bool Uploading bool Bitfield bittorrent.Bitfield }
connection statistics
func (*PeerConnStats) Less ¶
func (p *PeerConnStats) Less(o *PeerConnStats) bool
type PiecePicker ¶
type PiecePicker func(*bittorrent.Bitfield, []uint32) (uint32, bool)
picks the next good piece to download
type Swarm ¶
type Swarm struct { Torrents Holder // contains filtered or unexported fields }
a bittorrent swarm tracking many torrents
func NewSwarm ¶
create a new swarm using a storage backend for storing downloads and torrent metadata
func (*Swarm) AddOpenTracker ¶
AddOpenTracker adds an opentracker by url to be used by this swarm
func (*Swarm) AddRemoteTorrent ¶
func (*Swarm) AddTorrent ¶
add a torrent to this swarm
func (*Swarm) ObtainedNetwork ¶
give this swarm a new network context
type SwarmBandwidth ¶
SwarmBandwidth is a string tuple for bandwith
func (SwarmBandwidth) String ¶
func (sb SwarmBandwidth) String() string
type SwarmStatus ¶
type SwarmStatus map[string]TorrentStatus
infohash -> torrent status map
func (SwarmStatus) Ratio ¶
func (sw SwarmStatus) Ratio() (r float64)
func (SwarmStatus) TotalSpeed ¶
func (sw SwarmStatus) TotalSpeed() (tx, rx float64)
type Torrent ¶
type Torrent struct { TID int64 Completed func() Started func() Stopped func() RemoveSelf func() Network func() network.Network Trackers map[string]tracker.Announcer MaxRequests int MaxPeers uint // contains filtered or unexported fields }
single torrent tracked in a swarm
func (*Torrent) AnnounceSeed ¶
func (t *Torrent) AnnounceSeed()
manually announce as seed to all trackers blocks until done
func (*Torrent) Bitfield ¶
func (t *Torrent) Bitfield() *bittorrent.Bitfield
func (*Torrent) DownloadDir ¶
func (*Torrent) GetStatus ¶
func (t *Torrent) GetStatus() TorrentStatus
func (*Torrent) MetaInfo ¶
func (t *Torrent) MetaInfo() *metainfo.TorrentFile
get metainfo for this torrent
func (*Torrent) NeedsPeers ¶
return false if we reached max peers for this torrent
func (*Torrent) PersistPeer ¶
persit a connection to a peer
func (*Torrent) SetPieceWindow ¶
func (*Torrent) ShouldAcceptNewPeer ¶ added in v0.4.1
func (*Torrent) StartAnnouncing ¶
func (t *Torrent) StartAnnouncing()
start annoucing on all trackers
func (*Torrent) StopAnnouncing ¶
stop annoucing on all trackers
func (*Torrent) VisitPeers ¶
call a visitor on each open peer connection
type TorrentFileInfo ¶
func (TorrentFileInfo) BytesCompleted ¶
func (i TorrentFileInfo) BytesCompleted() int64
func (TorrentFileInfo) Length ¶
func (i TorrentFileInfo) Length() int64
func (TorrentFileInfo) Name ¶
func (i TorrentFileInfo) Name() string
type TorrentPeers ¶
type TorrentPeers []*PeerConnStats
func (TorrentPeers) Len ¶
func (p TorrentPeers) Len() int
func (TorrentPeers) Less ¶
func (p TorrentPeers) Less(i, j int) bool
func (TorrentPeers) RX ¶
func (p TorrentPeers) RX() (rx float64)
func (*TorrentPeers) Swap ¶
func (p *TorrentPeers) Swap(i, j int)
func (TorrentPeers) TX ¶
func (p TorrentPeers) TX() (tx float64)
type TorrentState ¶
type TorrentState string
func (TorrentState) String ¶
func (t TorrentState) String() string
type TorrentStatus ¶
type TorrentStatus struct { Files []TorrentFileInfo Peers TorrentPeers Us PeerConnStats Name string State TorrentState Infohash string Progress float64 TX uint64 RX uint64 }
immutable status of torrent
func (TorrentStatus) Ratio ¶
func (t TorrentStatus) Ratio() (r float64)
type TorrentStatusList ¶
type TorrentStatusList []TorrentStatus
func (TorrentStatusList) Len ¶
func (l TorrentStatusList) Len() int
func (TorrentStatusList) Less ¶
func (l TorrentStatusList) Less(i, j int) bool
func (TorrentStatusList) RX ¶
func (l TorrentStatusList) RX() (rx float64)
func (TorrentStatusList) Ratio ¶
func (l TorrentStatusList) Ratio() (r float64)
func (*TorrentStatusList) Swap ¶
func (l *TorrentStatusList) Swap(i, j int)
func (TorrentStatusList) TX ¶
func (l TorrentStatusList) TX() (tx float64)
type TorrentsList ¶
type TorrentsList struct {
Infohashes InfohashList
}