swarm

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

swarm package provides compelete bittorrent client that tracks 1 swarm

Index

Constants

View Source
const BlockSize = 1024 * 16

how big should we download pieces at a time (bytes)?

View Source
const Checking = TorrentState("checking")
View Source
const DefaultAnnounceNumWant = 10
View Source
const DefaultAnnouncePort = 6881
View Source
const DefaultMaxParallelRequests = 4
View Source
const DefaultMaxSwarmPeers = 50

max peers peer swarm default

View Source
const DefaultPEXDialect = extensions.I2PPeerExchange
View Source
const Downloading = TorrentState("downloading")
View Source
const RateDownload = "download"

rate name for download

View Source
const RateUpload = "upload"

rate name for upload

View Source
const Seeding = TorrentState("seeding")
View Source
const Stopped = TorrentState("stopped")

Variables

View Source
var ErrAlreadyStarted = errors.New("torrent already started")
View Source
var ErrAlreadyStopped = errors.New("torrent already stopped")

Functions

This section is empty.

Types

type Holder

type Holder struct {
	MaxReq    int
	QueueSize int
	// contains filtered or unexported fields
}

torrent swarm container

func (*Holder) Close

func (h *Holder) Close(announce bool)

func (*Holder) ForEachTorrent

func (h *Holder) ForEachTorrent(visit func(*Torrent))

func (*Holder) ForEachTorrentParallel

func (h *Holder) ForEachTorrentParallel(visit func(*Torrent))

func (*Holder) GetTorrent

func (h *Holder) GetTorrent(ih common.Infohash) (t *Torrent)

find a torrent by infohash returns nil if we don't have a torrent with this infohash

func (*Holder) GetTorrentByID

func (h *Holder) GetTorrentByID(id int64) (t *Torrent)

func (*Holder) TorrentIDs

func (h *Holder) TorrentIDs() (ids map[int64]string)

func (*Holder) VisitTorrent

func (h *Holder) VisitTorrent(ih common.Infohash, visit func(*Torrent))

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) Chocking

func (c *PeerConn) Chocking() bool

return true if we are choking the remote peer otherwise return false

func (*PeerConn) Choke

func (c *PeerConn) Choke()

send choke

func (*PeerConn) Close

func (c *PeerConn) Close()

func (*PeerConn) HasPiece

func (c *PeerConn) HasPiece(piece uint32) bool

returns true if the remote peer has piece with given index

func (*PeerConn) RemoteChoking

func (c *PeerConn) RemoteChoking() bool

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 (c *PeerConn) SupportsI2PPEX() bool

func (*PeerConn) SupportsLNPEX

func (c *PeerConn) SupportsLNPEX() bool

func (*PeerConn) Unchoke

func (c *PeerConn) Unchoke()

send unchoke

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

func NewSwarm(storage storage.Storage, gnutella *gnutella.Swarm) *Swarm

create a new swarm using a storage backend for storing downloads and torrent metadata

func (*Swarm) AddMagnet

func (sw *Swarm) AddMagnet(uri string) (err error)

func (*Swarm) AddOpenTracker

func (sw *Swarm) AddOpenTracker(url string)

AddOpenTracker adds an opentracker by url to be used by this swarm

func (*Swarm) AddRemoteTorrent

func (sw *Swarm) AddRemoteTorrent(remote string) (err error)

func (*Swarm) AddTorrent

func (sw *Swarm) AddTorrent(t storage.Torrent) (err error)

add a torrent to this swarm

func (*Swarm) Close

func (sw *Swarm) Close() (err error)

implements io.Closer

func (*Swarm) IsOnline

func (sw *Swarm) IsOnline() bool

func (*Swarm) LostNetwork

func (sw *Swarm) LostNetwork()

inform that we lost the network context

func (*Swarm) Network

func (sw *Swarm) Network() network.Network

func (*Swarm) ObtainedNetwork

func (sw *Swarm) ObtainedNetwork(n network.Network)

give this swarm a new network context

func (*Swarm) Run

func (sw *Swarm) Run() error

run until error

func (*Swarm) Running

func (sw *Swarm) Running() bool

type SwarmBandwidth

type SwarmBandwidth struct {
	Upload   string
	Download string
}

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) AddedAt

func (t *Torrent) AddedAt() time.Time

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) Close

func (t *Torrent) Close() error

implements io.Closer

func (*Torrent) Delete

func (t *Torrent) Delete() error

func (*Torrent) DialPeer

func (t *Torrent) DialPeer(a net.Addr, id common.PeerID) error

connect to a new peer for this swarm, blocks

func (*Torrent) Done

func (t *Torrent) Done() bool

func (*Torrent) DownloadDir

func (t *Torrent) DownloadDir() string

func (*Torrent) GetStatus

func (t *Torrent) GetStatus() TorrentStatus

func (*Torrent) HasIBConn

func (t *Torrent) HasIBConn(a net.Addr) (has bool)

func (*Torrent) HasOBConn

func (t *Torrent) HasOBConn(a net.Addr) (has bool)

func (*Torrent) Infohash

func (t *Torrent) Infohash() common.Infohash

func (*Torrent) MetaInfo

func (t *Torrent) MetaInfo() *metainfo.TorrentFile

get metainfo for this torrent

func (*Torrent) Name

func (t *Torrent) Name() string

func (*Torrent) NeedsPeers

func (t *Torrent) NeedsPeers() bool

return false if we reached max peers for this torrent

func (*Torrent) NumPeers

func (t *Torrent) NumPeers() (count uint)

NumPeers counts how many peers we have on this torrent

func (*Torrent) PersistPeer

func (t *Torrent) PersistPeer(a net.Addr, id common.PeerID)

persit a connection to a peer

func (*Torrent) Private

func (t *Torrent) Private() bool

func (*Torrent) RX

func (t *Torrent) RX() (rx int64)

func (*Torrent) Ready

func (t *Torrent) Ready() bool

func (*Torrent) Remove

func (t *Torrent) Remove() error

func (*Torrent) SetPieceWindow

func (t *Torrent) SetPieceWindow(n int)

func (*Torrent) ShouldAcceptNewPeer added in v0.4.1

func (t *Torrent) ShouldAcceptNewPeer() bool

func (*Torrent) Start

func (t *Torrent) Start() error

func (*Torrent) StartAnnouncing

func (t *Torrent) StartAnnouncing()

start annoucing on all trackers

func (*Torrent) Stop

func (t *Torrent) Stop() error

func (*Torrent) StopAnnouncing

func (t *Torrent) StopAnnouncing(announce bool)

stop annoucing on all trackers

func (*Torrent) TX

func (t *Torrent) TX() (tx int64)

func (*Torrent) VisitPeers

func (t *Torrent) VisitPeers(v func(*PeerConn))

call a visitor on each open peer connection

type TorrentFileInfo

type TorrentFileInfo struct {
	FileInfo metainfo.FileInfo
	Progress float64
}

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
}

Jump to

Keyboard shortcuts

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