Documentation ¶
Index ¶
- Constants
- func CreateListener(cfg *common.Config) (listener net.Listener, err error)
- func StartListen(cfg *common.Config) (conChan chan *PeerConn, listener net.Listener, err error)
- type ActivePiece
- type 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 CacheProvider
- type DispatchTask
- type File
- type FileCache
- type FileDict
- type FileStore
- type FileSystem
- type FsProvider
- type LinkChain
- type MetaInfo
- type OsFsProvider
- type PHeader
- type PeerConn
- type RAMCache
- type RAMCacheProvider
- type StartTask
- type StatusReport
- type TaskSession
- type TaskSessionMgnt
Constants ¶
const ( // HAVE 每当客户端下载了一个piece,即将该piece的下标作为have消息的负载构造have消息,并把该消息发送给所有建立连接的peer HAVE = iota // BITFIELD 交换位图 BITFIELD // REQUEST 向该peer发送数据请求 REQUEST // PIECE 当客户端收到某个peer的request消息后,则发送piece消息将文件数据传给该peer。 PIECE )
Variables ¶
This section is empty.
Functions ¶
func CreateListener ¶
CreateListener ...
Types ¶
type ActivePiece ¶
type ActivePiece struct {
// contains filtered or unexported fields
}
ActivePiece 正在下载的Piece
type Bitset ¶
type Bitset struct {
// contains filtered or unexported fields
}
Bitset As defined by the bittorrent protocol, this bitset is big-endian, such that the high bit of the first byte is block 0
func NewBitsetFromBytes ¶
NewBitsetFromBytes Creates a new bitset from a given byte stream. Returns nil if the data is invalid in some way.
func (*Bitset) FindNextClear ¶
FindNextClear ... TODO: Make this fast
func (*Bitset) FindNextSet ¶
FindNextSet ... TODO: Make this fast
type CacheProvider ¶
type CacheProvider interface {
NewCache(infohash string, numPieces int, pieceLength int, totalSize int64) FileCache
}
CacheProvider ...
func NewRAMCacheProvider ¶
func NewRAMCacheProvider(capacity int) CacheProvider
NewRAMCacheProvider ...
type DispatchTask ¶
type DispatchTask struct { TaskID string `json:"taskId"` MetaInfo *MetaInfo `json:"metaInfo"` LinkChain *LinkChain `json:"linkChain"` Speed int64 `json:"speed"` }
DispatchTask 下发给Agent的分发任务
type FileCache ¶
type FileCache interface { //Marks a piece as committed to permanent storage. MarkCommitted(piece int) //Close the cache and free all the things Close() // contains filtered or unexported methods }
FileCache ...
type FileDict ¶
type FileDict struct { Length int64 `json:"length"` Path string `json:"path"` Name string `json:"name"` Sum string `json:"sum" ` }
FileDict 一个文件的元数据信息
type FileStore ¶
type FileStore interface { io.ReaderAt io.WriterAt io.Closer SetCache(FileCache) Commit(int, []byte, int64) }
FileStore a file store.
func NewFileStore ¶
func NewFileStore(info *MetaInfo, fileSystem FileSystem) (f FileStore, totalSize int64, err error)
NewFileStore 根据元数据信息打开所有文件
type FileSystem ¶
FileSystem Interface for a file system. A file system contains files.
type FsProvider ¶
type FsProvider interface {
NewFS() (FileSystem, error)
}
FsProvider Interface for a provider of filesystems.
type LinkChain ¶
type LinkChain struct { // 软件分发的路径,要求服务端的地址排在第一个 DispatchAddrs []string `json:"dispatchAddrs"` // 服务端管理接口,用于上报状态 ServerAddr string `json:"serverAddr"` }
LinkChain 分发路径
type MetaInfo ¶
type MetaInfo struct { Length int64 `json:"length"` PieceLen int64 `json:"PieceLen"` Pieces []byte `json:"pieces"` Files []*FileDict `json:"files"` }
MetaInfo 一个任务内所有文件的元数据信息
type PeerConn ¶
type PeerConn struct {
// contains filtered or unexported fields
}
PeerConn wraps an incoming network connection and contains metadata that helps identify which active p2pSession it's relevant for.
type RAMCache ¶
type RAMCache struct {
// contains filtered or unexported fields
}
RAMCache ... 'pieceSize' is the size of the average piece 'capacity' is how many pieces the cache can hold 'actualUsage' is how many pieces the cache has at the moment 'atime' is an array of access times for each stored box 'store' is an array of "boxes" ([]byte of 1 piece each) 'isBoxFull' indicates if a box entirely contains written data 'isBoxCommit' indicates if a box has been committed to storage 'isByteSet' for [i] indicates for box 'i' if a byte has been written to 'torrentLength' is the number of bytes in the torrent 'cacheProvider' is a pointer to the cacheProvider that created this cache 'infohash' is the infohash of the torrent
type RAMCacheProvider ¶
type RAMCacheProvider struct {
// contains filtered or unexported fields
}
RAMCacheProvider provider creates a ram cache for each torrent. Each time a cache is created or closed, all cache are recalculated so they total <= capacity (in MiB).
type StatusReport ¶
type StatusReport struct { TaskID string `json:"taskId"` IP string `json:"�ip"` PercentComplete float32 `json:"percentComplete"` }
StatusReport Agent分发状态上报
type TaskSession ¶
type TaskSession struct {
// contains filtered or unexported fields
}
TaskSession ...
func NewTaskSession ¶
func NewTaskSession(g *global, dt *DispatchTask, stopSessChan chan string) (s *TaskSession, err error)
NewTaskSession ...
func (*TaskSession) AcceptNewPeer ¶
func (s *TaskSession) AcceptNewPeer(c *PeerConn)
AcceptNewPeer 接入其它的Peer连接
type TaskSessionMgnt ¶
type TaskSessionMgnt struct {
// contains filtered or unexported fields
}
TaskSessionMgnt ...
func (*TaskSessionMgnt) CreateTask ¶
func (sm *TaskSessionMgnt) CreateTask(dt *DispatchTask)
CreateTask 创建一个任务
func (*TaskSessionMgnt) StartTask ¶
func (sm *TaskSessionMgnt) StartTask(st *StartTask)
StartTask 启动一个任务
func (*TaskSessionMgnt) StopTask ¶
func (sm *TaskSessionMgnt) StopTask(taskID string)
StopTask 停止一下任务