Documentation ¶
Index ¶
- Variables
- func NewDownload(connector *torrent.Connector) torrent.Download
- func NewPicker(storage torrent.Storage) torrent.Picker
- func NewUpload(connector *torrent.Connector) torrent.Upload
- type CacheDownload
- type CachePicker
- type CacheUpload
- type Candidate
- type Election
- func (e *Election) Elect(as string) []string
- func (e *Election) GetElected() []string
- func (e *Election) NewJoin(id string)
- func (e *Election) Recv(m interface{})
- func (e *Election) RegisterCandidate(candidate Candidate)
- func (e *Election) RemoveCandidate(toRemove string)
- func (e *Election) Run()
- func (e *Election) RunElection()
- type Follower
- type Forwarder
- type Leader
- type LeaderStart
- type Leaders
- type Neighbours
- type Peer
- type Tracker
Constants ¶
This section is empty.
Variables ¶
var LeaderPercent config.Const = config.NewConst(config.LeaderPercent)
Functions ¶
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
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 ¶
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 ¶
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 (*Election) Elect ¶
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 (*Election) NewJoin ¶
The NewJoin message updates the Cameras when a new node Joins the system.
func (*Election) RegisterCandidate ¶
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 (*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 ¶
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 ¶
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.
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 ¶
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.
type Tracker ¶
The CacheTorrent Tracker is identical to the BitTorrent tracker, with the addition that it also handles Candidate messages by sending messages towards the Election.