cache_torrent

package
v0.0.0-...-1364d92 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

func NewDownload

func NewDownload(connector *torrent.Connector) torrent.Download

func NewPicker

func NewPicker(storage torrent.Storage) torrent.Picker

func NewUpload

func NewUpload(connector *torrent.Connector) torrent.Upload

Types

type CacheDownload

type CacheDownload struct {
	*torrent.TorrentDownload
}

The CacheDownload is a Downloader corresponding to a leader. When a 'Have' message is received it uses a Forwarder to forward the message towards the Followers and the request are made by the CacheTorrent picker heuristic, rather than usual Rarest First.

func (*CacheDownload) Recv

func (d *CacheDownload) Recv(m interface{})

type CachePicker

type CachePicker struct {
	*torrent.TorrentPicker
	// contains filtered or unexported fields
}

The CachePicker is the Picker used by Leaders. It favors pieces that were requested by followers and, in case no piece was requested by a follower, it uses the default rarest first strategy as explained in BitTorrent's Picker.

func (*CachePicker) GotRequest

func (p *CachePicker) GotRequest(index int)

func (*CachePicker) IsBanned

func (p *CachePicker) IsBanned(index int) bool

func (*CachePicker) Next

func (p *CachePicker) Next(peer string) (int, bool)

func (*CachePicker) SelectBucket

func (p *CachePicker) SelectBucket(bucket map[int]bool,
	haves map[int]bool,
	tiebreaks map[int]int) (int, bool)

We use a different bucket selection which takes into account the indirect requested that were made as well.

type CacheUpload

type CacheUpload struct {
	*torrent.TorrentUpload
}

The CacheUpload is used by Leaders. It acts like a BitTorrent upload, but it may be that it does not have a Piece that it advertised. In this case, it will not transfer the piece.

func (*CacheUpload) Recv

func (u *CacheUpload) Recv(m interface{})

type Candidate

type Candidate struct {
	Id string

	Up   int
	Down int
}

Message type used by the location awareness extension. A Peer sends a Candidate message with its ID, upload and download rates to be propose itself as a leader in an election.

type Election

type Election struct {
	sync.Mutex
	// contains filtered or unexported fields
}

The Election component is reponsible with Leader election. It runs as a centralized component onto the Tracker. The election algorithm runs as follows. Each autonomous system represents an Election Camera. When a lower bound of 'limit' nodes have joined an entire system, all camera election run for the whole system. Nodes joining later do not participate in the election. When a camera was elected, the nodes in the camera are notfied via a 'Leaders' message.

The nodes are elected leaders by the biggest upload capacity criteria. In case of equallity the leaders are chosen by arrival time. Most methods are made public so that the MultiTorrent extension can use CacheTorrent elections.

func NewElection

func NewElection(limit int, transport Transport) *Election

func (*Election) Elect

func (e *Election) Elect(as string) []string

Run leader election for a specific autonomous system. Candidates are elected the the biggest upload capacity criteria. In case of equallity, the nodes' download capacity is compared and, finally, the provided ID.

func (*Election) GetElected

func (e *Election) GetElected() []string

func (*Election) NewJoin

func (e *Election) NewJoin(id string)

The NewJoin message updates the Cameras when a new node Joins the system.

func (*Election) Recv

func (e *Election) Recv(m interface{})

func (*Election) RegisterCandidate

func (e *Election) RegisterCandidate(candidate Candidate)

A candidate gets registered when a 'Candidate' message arrives. The candidate messages are sent by all Peers directly to the Tracker.

func (*Election) RemoveCandidate

func (e *Election) RemoveCandidate(toRemove string)

func (*Election) Run

func (e *Election) Run()

func (*Election) RunElection

func (e *Election) RunElection()

Run elections for all autonomous systems. RunElection is called when the node limit is reached. This limit is checked when Join messages arrive.

type Follower

type Follower struct {
	*Peer
}

A Follower is a Peer with limited capabilities. A Follower can:

  • upload to anybody
  • download only from same AS

The Follower mostly acts like a BitTorrent peer, whereas the Leader would have further modifications such as message forwarding and special piece picking, basically acting as a proxy between followers and other peers.

The same autonomous system connections are establised as in the BitTorrent protocol. For indirect connections, the Follower sends the 'leaderStart' message towards randomly-chosen leaders of its autonomous system. When the Leader receives the leaderStart message, it opens a download-only connection with the remote peer that the follower wants to communicate with.

func NewFollower

func NewFollower(p *Peer) *Follower

func (*Follower) Recv

func (f *Follower) Recv(m interface{})

func (*Follower) Run

func (f *Follower) Run()

type Forwarder

type Forwarder struct {
	*Leader
	// contains filtered or unexported fields
}

A Forwarder is a structure used by a Leader to forward 'Have' messages towards all its Followers.

func NewForwarder

func NewForwarder(leader *Leader, from, to string) *Forwarder

func (*Forwarder) Recv

func (f *Forwarder) Recv(m interface{})

type Leader

type Leader struct {
	*Peer
	// contains filtered or unexported fields
}

A Leader is a privileaged node. It was appointed as a leader in an election and acts as a cache at the margin of the autonomous system. A Leader can:

  • download from anybody
  • upload to anybody(see race condition)

A Leader can not:

  • upload to different AS via an indirect connection

The Leader forwards the 'have' message towards the Follower. When a Follower asks the Leader for a piece, the Leader with either have the piece and respond, or, in case it does not have it, it will try acquire the piece as fast as possbile. To to that, the Leader gives priority to pieces requested by Followers. This is achieved by using a new Picker.

func NewLeader

func NewLeader(p *Peer) *Leader

func (*Leader) Recv

func (l *Leader) Recv(m interface{})

func (*Leader) Run

func (l *Leader) Run()

type LeaderStart

type LeaderStart struct {
	Id   string // the ID of the local node
	Dest string // the ID of the destination
}

Message type used by the indirect requests extension. When a Follower wants to start an inidirect connection via a Leader it sends a LeaderStart message.

type Leaders

type Leaders struct {
	Ids []string
}

Message type used by the location awareness extension. The Tracker send the Leaders message back to Peers, letting them know who was elected leader.

type Neighbours

type Neighbours struct {
	Ids []string
}

Message type used by the location awareness extension. The Neighbours message is similar to the Neighbours message produces by BitTorrent.

type Peer

type Peer struct {
	*torrent.Peer

	Leaders []string
	// contains filtered or unexported fields
}

The CacheTorrent peer is only a container extending the BitTorrent peer. Depending on the role assigned by the election component, the CacheTorrent peer will either implement a Follower or a Leader. The Follower mostly acts like a BitTorrent peer, whereas the Leader will have further modifications such as message forwarding and special piece picking algorithm, basically acting as a proxy between followers and other peers.

func (*Peer) Bind

func (p *Peer) Bind(m interface{}) (state int)

The Bind method is backwards compatible with BitTorrent's Bind, but it support 'cache_torrent.Neighbours' messages and 'cache_torrent.Leaders' messages.

func (*Peer) GetId

func (p *Peer) GetId(m interface{}) string

func (*Peer) New

func (p *Peer) New(util TorrentNodeUtil) TorrentNode

func (*Peer) OnJoin

func (p *Peer) OnJoin()

func (*Peer) Process

func (p *Peer) Process(m interface{}, state int)

The Process method is identical to BitTorrent's one, but it dispaches the message towards the specific node component(i.e. Leader of Follower).

type Tracker

type Tracker struct {
	*torrent.Tracker
	// contains filtered or unexported fields
}

The CacheTorrent Tracker is identical to the BitTorrent tracker, with the addition that it also handles Candidate messages by sending messages towards the Election.

func (*Tracker) Local

func (t *Tracker) Local(id string) []string

func (*Tracker) Neighbours

func (t *Tracker) Neighbours(id string) interface{}

func (*Tracker) New

func (t *Tracker) New(util TorrentNodeUtil) TorrentNode

func (*Tracker) OnJoin

func (t *Tracker) OnJoin()

func (*Tracker) Recv

func (t *Tracker) Recv(m interface{})

Jump to

Keyboard shortcuts

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