Documentation
¶
Overview ¶
Package goed2k provides a Go library for ED2K/eMule style downloads.
The public API is exposed from the module root so callers can import:
import "github.com/goed2k/core"
Lower-level protocol helpers are available from subpackages such as protocol, protocol/client, protocol/server, and protocol/kad.
Index ¶
- Constants
- Variables
- func Byte2String(value []byte) string
- func ComputeEd2kFileMeta(path string) (root protocol.Hash, size int64, pieceHashes []protocol.Hash, err error)
- func CurrentTime() int64
- func CurrentTimeHiRes() int64
- func CurrentTimeMillis() int64
- func CurrentTimeToDeadline(nsFromNow int64) time.Time
- func DivCeil(a, b int64) int64
- func FormatLink(fileName string, fileSize int64, hash fmt.Stringer) string
- func HTONL(ip int32) int32
- func HTONLBytes(order []byte) int32
- func HiPart(value int64) int32
- func Hours(value int64) int64
- func IP2String(ip int32) string
- func Int2Address(ip int32) net.IP
- func IsBit(value, mask int32) bool
- func IsLocalAddress(ip int32) bool
- func IsLowID(v int32) bool
- func LowPart(value int64) int32
- func MakeFullED2KVersion(clientID, a, b, c int64) int64
- func Minutes(value int64) int64
- func NTOHL(ip int32) int32
- func PackToNetworkByteOrder(order []byte) int32
- func PeerSourceLabels(sourceFlag int) []string
- func Seconds(value int64) int64
- func String2IP(s string) (int32, error)
- func UpdateCachedTime()
- type AddTransferParams
- type AsyncHash
- type AsyncHashResult
- type AsyncOperationResult
- type AsyncRelease
- type AsyncReleaseResult
- type AsyncRestore
- type AsyncRestoreResult
- type AsyncWrite
- type AsyncWriteResult
- type BaseErrorCode
- type BlockManager
- type BlockState
- type BlocksEnumerator
- type Client
- func (c *Client) AddDHTBootstrapNodes(nodes ...string) error
- func (c *Client) AddLink(linkValue, outputDir string) (TransferHandle, string, error)
- func (c *Client) AddSharedDir(path string) error
- func (c *Client) AddTransfer(atp AddTransferParams) (TransferHandle, error)
- func (c *Client) Close()
- func (c *Client) Connect(serverAddr string) error
- func (c *Client) ConnectSavedServer() error
- func (c *Client) ConnectServerLink(linkValue string) error
- func (c *Client) ConnectServerMet(path string) error
- func (c *Client) ConnectServers(serverAddrs ...string) error
- func (c *Client) DHTStatus() DHTStatus
- func (c *Client) EnableDHT() *DHTTracker
- func (c *Client) FindTransfer(hash protocol.Hash) TransferHandle
- func (c *Client) GetDHTTracker() *DHTTracker
- func (c *Client) ImportSharedFile(path string) error
- func (c *Client) ListSharedDirs() []string
- func (c *Client) LoadDHTNodesDat(path ...string) error
- func (c *Client) LoadServerMet(path string) ([]serverproto.ServerMetEntry, error)
- func (c *Client) LoadState(path string) error
- func (c *Client) PauseTransfer(hash protocol.Hash) error
- func (c *Client) PeerStatuses() []ClientPeerSnapshot
- func (c *Client) PublishDHTKeyword(keywordHash protocol.Hash, entries ...kadproto.SearchEntry) bool
- func (c *Client) PublishDHTNotes(fileHash protocol.Hash, entries ...kadproto.SearchEntry) bool
- func (c *Client) PublishDHTSource(hash protocol.Hash, endpoint protocol.Endpoint, size int64) bool
- func (c *Client) RemoveSharedDir(path string) error
- func (c *Client) RemoveSharedFile(hash protocol.Hash) bool
- func (c *Client) RemoveTransfer(hash protocol.Hash, deleteFile bool) error
- func (c *Client) RescanSharedDirs() error
- func (c *Client) ResumeTransfer(hash protocol.Hash) error
- func (c *Client) ResumeUpload(hash protocol.Hash)
- func (c *Client) SaveState(path string) error
- func (c *Client) SearchDHTKeywords(keywordHash protocol.Hash, cb func([]kadproto.SearchEntry)) bool
- func (c *Client) SearchSnapshot() SearchSnapshot
- func (c *Client) ServerAddress() string
- func (c *Client) ServerStatuses() []ServerSnapshot
- func (c *Client) Session() *Session
- func (c *Client) SetAutoSaveInterval(interval time.Duration)
- func (c *Client) SetDHTStoragePoint(address string) error
- func (c *Client) SetDHTTracker(tracker *DHTTracker)
- func (c *Client) SetFriendSlot(hash protocol.Hash, enabled bool)
- func (c *Client) SetStatePath(path string)
- func (c *Client) SetStateStore(store ClientStateStore)
- func (c *Client) SetTransferUploadPriority(hash protocol.Hash, priority UploadPriority) error
- func (c *Client) SharedFiles() []*SharedFile
- func (c *Client) Start() error
- func (c *Client) StartSearch(params SearchParams) (SearchHandle, error)
- func (c *Client) StatePath() string
- func (c *Client) StateStore() ClientStateStore
- func (c *Client) Status() ClientStatus
- func (c *Client) Stop() error
- func (c *Client) StopSearch() error
- func (c *Client) SubscribeStatus() (<-chan ClientStatusEvent, func())
- func (c *Client) SubscribeStatusBuffered(buffer int) (<-chan ClientStatusEvent, func())
- func (c *Client) SubscribeTransferProgress() (<-chan TransferProgressEvent, func())
- func (c *Client) SubscribeTransferProgressBuffered(buffer int) (<-chan TransferProgressEvent, func())
- func (c *Client) SuspendUpload(hash protocol.Hash, terminate bool) uint16
- func (c *Client) TransferSnapshots() []TransferSnapshot
- func (c *Client) Transfers() []TransferHandle
- func (c *Client) Wait() error
- type ClientCreditState
- type ClientDHTNodeState
- type ClientDHTState
- type ClientPeerSnapshot
- type ClientSharedFileState
- type ClientState
- type ClientStateStore
- type ClientStatus
- type ClientStatusEvent
- type ClientTransferState
- type Connection
- func (c *Connection) AppendIncoming(chunk []byte)
- func (c *Connection) Close(ec BaseErrorCode)
- func (c *Connection) Connect(address net.Addr) error
- func (c *Connection) ConsumeIncoming(limit int) []byte
- func (c *Connection) DecodeFrames(combiner *protocol.PacketCombiner) ([]protocol.PacketHeader, []protocol.Serializable, error)
- func (c *Connection) DisconnectCode() BaseErrorCode
- func (c *Connection) DoRead() error
- func (c *Connection) DrainIncoming() []byte
- func (c *Connection) Endpoint() protocol.Endpoint
- func (c *Connection) FlushOutgoing() error
- func (c *Connection) IncomingBytes() int
- func (c *Connection) IncomingChunks() [][]byte
- func (c *Connection) IsDisconnectHandled() bool
- func (c *Connection) IsDisconnecting() bool
- func (c *Connection) MarkDisconnectHandled()
- func (c *Connection) MillisecondsSinceLastReceive() int64
- func (c *Connection) PendingPackets() [][]byte
- func (c *Connection) PopOutgoing() []byte
- func (c *Connection) QueuePacket(packet []byte)
- func (c *Connection) QueuePacketWithStats(packet []byte, protocolBytes, payloadBytes int64)
- func (c *Connection) ReadFrames() ([]protocol.PacketHeader, [][]byte, error)
- func (c *Connection) ReadFramesWithCombiner(combiner *protocol.PacketCombiner) ([]protocol.PacketHeader, [][]byte, error)
- func (c *Connection) SecondTick(tickIntervalMS int64)
- func (c *Connection) Statistics() Statistics
- type DHTStatus
- type DHTTracker
- func (t *DHTTracker) AddNode(addr *net.UDPAddr)
- func (t *DHTTracker) AddNodes(addrs ...*net.UDPAddr)
- func (t *DHTTracker) ApplyNodesDat(nodes *kadproto.NodesDat) error
- func (t *DHTTracker) ApplyState(state *ClientDHTState) error
- func (t *DHTTracker) Close()
- func (t *DHTTracker) IsFirewalled() bool
- func (t *DHTTracker) ListenPort() int
- func (t *DHTTracker) LoadNodesDat(path string) error
- func (t *DHTTracker) PublishKeyword(keywordHash protocol.Hash, entries ...kadproto.SearchEntry) bool
- func (t *DHTTracker) PublishNotes(fileHash protocol.Hash, entries ...kadproto.SearchEntry) bool
- func (t *DHTTracker) PublishSource(hash protocol.Hash, endpoint protocol.Endpoint, size int64) bool
- func (t *DHTTracker) SearchKeywords(hash protocol.Hash, cb func([]kadproto.SearchEntry)) bool
- func (t *DHTTracker) SearchSources(hash protocol.Hash, size int64, cb func([]kadproto.SearchEntry)) bool
- func (t *DHTTracker) SetStoragePoint(addr *net.UDPAddr)
- func (t *DHTTracker) SnapshotState() *ClientDHTState
- func (t *DHTTracker) Start() error
- func (t *DHTTracker) Status() DHTStatus
- type DownloadingBlock
- func (b *DownloadingBlock) Abort(p *Peer)
- func (b *DownloadingBlock) Finish()
- func (b DownloadingBlock) IsFinished() bool
- func (b DownloadingBlock) IsFree() bool
- func (b DownloadingBlock) IsRequested() bool
- func (b DownloadingBlock) IsWriting() bool
- func (b *DownloadingBlock) Request(p *Peer, speed PeerSpeed)
- func (b *DownloadingBlock) Write()
- type DownloadingPiece
- func (d *DownloadingPiece) AbortDownloading(blockIndex int, p *Peer)
- func (d DownloadingPiece) BlocksCount() int
- func (d DownloadingPiece) DownloadedCount() int
- func (d DownloadingPiece) DownloadingBlocksCount() int
- func (d *DownloadingPiece) FinishBlock(blockIndex int)
- func (d DownloadingPiece) FinishedBlocksCount() int
- func (d DownloadingPiece) IsDownloaded(blockIndex int) bool
- func (d DownloadingPiece) IsFinished(blockIndex int) bool
- func (d *DownloadingPiece) PickBlocks(rq *[]data.PieceBlock, orderLength int, peer *Peer, speed PeerSpeed, ...) int
- func (d *DownloadingPiece) RequestBlock(blockIndex int, p *Peer, speed PeerSpeed)
- func (d DownloadingPiece) TotalBlocks() int
- func (d *DownloadingPiece) WriteBlock(blockIndex int) bool
- func (d DownloadingPiece) WritingBlocksCount() int
- type EMuleLink
- type ErrorCode
- type FileClientStateStore
- type JED2KError
- type KadRoutingNode
- type LinkType
- type MiscOptions
- type MiscOptions2
- func (m *MiscOptions2) Assign(value int)
- func (m *MiscOptions2) SetCaptcha()
- func (m *MiscOptions2) SetExtMultipacket()
- func (m *MiscOptions2) SetLargeFiles()
- func (m *MiscOptions2) SetSourceExt2()
- func (m MiscOptions2) SupportCaptcha() bool
- func (m MiscOptions2) SupportExtMultipacket() bool
- func (m MiscOptions2) SupportLargeFiles() bool
- func (m MiscOptions2) SupportSourceExt2() bool
- type Peer
- type PeerConnection
- func (p *PeerConnection) AbortAllRequests()
- func (p *PeerConnection) ActiveUploadSource() UploadableResource
- func (p *PeerConnection) AddUploadRequest(req data.PeerRequest)
- func (p *PeerConnection) ClearUploadBlockRequests()
- func (p *PeerConnection) ClearUploadWaitStart()
- func (p *PeerConnection) CompleteBlock(pb *PendingBlock) bool
- func (p *PeerConnection) Connect() error
- func (p *PeerConnection) Endpoint() protocol.Endpoint
- func (p *PeerConnection) FriendSlot() bool
- func (p *PeerConnection) GetDownloading(block data.PieceBlock) *PendingBlock
- func (p *PeerConnection) GetInfo() PeerInfo
- func (p *PeerConnection) GetPeer() *Peer
- func (p *PeerConnection) HandleAnswerSources2(ans *clientproto.AnswerSources2)
- func (p *PeerConnection) HandleClientCancelTransfer()
- func (p *PeerConnection) HandleClientFileRequest(value *clientproto.FileRequest)
- func (p *PeerConnection) HandleClientFileStatusRequest(value *clientproto.FileStatusRequest)
- func (p *PeerConnection) HandleClientHashSetRequest(value *clientproto.HashSetRequest)
- func (p *PeerConnection) HandleClientHello(value *clientproto.Hello)
- func (p *PeerConnection) HandleClientRequestParts32(value *clientproto.RequestParts32) error
- func (p *PeerConnection) HandleClientRequestParts64(value *clientproto.RequestParts64) error
- func (p *PeerConnection) HandleClientStartUpload(value *clientproto.StartUpload)
- func (p *PeerConnection) HandleExtHello(_ *clientproto.ExtHello)
- func (p *PeerConnection) HandleFileAnswer(value *clientproto.FileAnswer)
- func (p *PeerConnection) HandleFileStatusAnswer(value *clientproto.FileStatusAnswer)
- func (p *PeerConnection) HandleHelloAnswer(value *clientproto.HelloAnswer)
- func (p *PeerConnection) HandleRequestSources2(req *clientproto.RequestSources2)
- func (p *PeerConnection) HasEndpoint() bool
- func (p *PeerConnection) IsRequesting(block data.PieceBlock) bool
- func (p *PeerConnection) IsUploadConnected() bool
- func (p *PeerConnection) IsUploadLowID() bool
- func (p *PeerConnection) OnConnect()
- func (p *PeerConnection) OnDisconnect(ec BaseErrorCode)
- func (p *PeerConnection) PrepareHello() clientproto.Hello
- func (p *PeerConnection) PrepareHelloAnswer() clientproto.HelloAnswer
- func (p *PeerConnection) ProcessIncoming() error
- func (p *PeerConnection) ReceiveCompressedData(header protocol.PacketHeader, offset, compressedLength int64, payloadSize int)
- func (p *PeerConnection) ReceiveData(req data.PeerRequest, compressed bool)
- func (p *PeerConnection) ReceivePendingData()
- func (p *PeerConnection) RequestBlocks()
- func (p *PeerConnection) ResetUploadSession()
- func (p *PeerConnection) SecondTick(tickIntervalMS int64)
- func (p *PeerConnection) SendAcceptUpload()
- func (p *PeerConnection) SendBlockData()
- func (p *PeerConnection) SendCancelTransfer()
- func (p *PeerConnection) SendExtHelloAnswer()
- func (p *PeerConnection) SendFileAnswer(res UploadableResource)
- func (p *PeerConnection) SendFileRequest(hash protocol.Hash)
- func (p *PeerConnection) SendFileStatusAnswer(res UploadableResource)
- func (p *PeerConnection) SendFileStatusRequest(hash protocol.Hash)
- func (p *PeerConnection) SendHashSetAnswer(res UploadableResource)
- func (p *PeerConnection) SendHashSetRequest(hash protocol.Hash)
- func (p *PeerConnection) SendOutOfPartReqsAndAddToWaitingQueue()
- func (p *PeerConnection) SendOutOfParts()
- func (p *PeerConnection) SendPart(begin, end int64, payload []byte) error
- func (p *PeerConnection) SendQueueRanking(rank uint16)
- func (p *PeerConnection) SendRequestParts32(packet *clientproto.RequestParts32)
- func (p *PeerConnection) SendRequestParts64(packet *clientproto.RequestParts64)
- func (p *PeerConnection) SendRequestSources2(hash protocol.Hash) error
- func (p *PeerConnection) SendStartUpload(hash protocol.Hash)
- func (p *PeerConnection) SetFriendSlot(v bool)
- func (p *PeerConnection) SetPeer(peer *Peer)
- func (p *PeerConnection) SetTransfer(transfer *Transfer)
- func (p *PeerConnection) SetUploadAddNextConnect(v bool)
- func (p *PeerConnection) SetUploadQueueRank(rank uint16)
- func (p *PeerConnection) SetUploadResource(res UploadableResource)
- func (p *PeerConnection) SetUploadStartTime(ts int64)
- func (p *PeerConnection) SetUploadState(state UploadState)
- func (p *PeerConnection) SetUploadWaitStart(ts int64)
- func (p *PeerConnection) Speed() PeerSpeed
- func (p *PeerConnection) UploadAddNextConnect() bool
- func (p *PeerConnection) UploadQueueRank() uint16
- func (p *PeerConnection) UploadScore() uint32
- func (p *PeerConnection) UploadSession() int64
- func (p *PeerConnection) UploadStartDelay() int64
- func (p *PeerConnection) UploadState() UploadState
- func (p *PeerConnection) UploadWaitStart() int64
- type PeerCredit
- type PeerCreditManager
- func (m *PeerCreditManager) AddDownloaded(hash protocol.Hash, bytes int64)
- func (m *PeerCreditManager) AddUploaded(hash protocol.Hash, bytes int64)
- func (m *PeerCreditManager) ApplySnapshot(states []ClientCreditState)
- func (m *PeerCreditManager) ScoreRatio(hash protocol.Hash) float64
- func (m *PeerCreditManager) Snapshot() []ClientCreditState
- func (m *PeerCreditManager) TotalsForPeer(hash protocol.Hash) (uploaded, downloaded uint64)
- type PeerInfo
- type PeerSpeed
- type PendingBlock
- type PieceManager
- func (p *PieceManager) Abort() [][]byte
- func (p *PieceManager) DeleteFile() error
- func (p *PieceManager) GetFile() *os.File
- func (p *PieceManager) HashPiece(pieceIndex int) protocol.Hash
- func (p *PieceManager) ReadRange(begin, end int64) ([]byte, error)
- func (p *PieceManager) ReleaseFile(deleteFile bool) ([][]byte, error)
- func (p *PieceManager) RestoreBlock(block data.PieceBlock, fileSize int64) ([][]byte, []byte, error)
- func (p *PieceManager) WriteBlock(block data.PieceBlock, buffer []byte) ([][]byte, error)
- type PiecePicker
- func (p *PiecePicker) AbortDownload(b data.PieceBlock, peer *Peer)
- func (p *PiecePicker) ChooseNextPiece() bool
- func (p *PiecePicker) ChooseNextPieceWithAvailability(available *protocol.BitField) bool
- func (p *PiecePicker) DownloadPiece(pieceIndex int)
- func (p *PiecePicker) GetDownloadingPiece(index int) *DownloadingPiece
- func (p PiecePicker) GetDownloadingQueue() []DownloadingPiece
- func (p PiecePicker) GetPieceCount() int
- func (p PiecePicker) HavePiece(pieceIndex int) bool
- func (p *PiecePicker) IsBlockDownloaded(b data.PieceBlock) bool
- func (p PiecePicker) IsEndGame() bool
- func (p PiecePicker) IsPieceFinished(pieceIndex int) bool
- func (p *PiecePicker) MarkAsDownloading(b data.PieceBlock, peer *Peer) bool
- func (p *PiecePicker) MarkAsFinished(b data.PieceBlock) bool
- func (p *PiecePicker) MarkAsWriting(b data.PieceBlock) bool
- func (p PiecePicker) NumDownloadingPieces() int
- func (p PiecePicker) NumHave() int
- func (p PiecePicker) NumPieces() int
- func (p *PiecePicker) PickPieces(rq *[]data.PieceBlock, orderLength int, peer *Peer, speed PeerSpeed)
- func (p *PiecePicker) PickPiecesWithAvailability(rq *[]data.PieceBlock, orderLength int, peer *Peer, speed PeerSpeed, ...)
- func (p *PiecePicker) RestoreHave(pieceIndex int)
- func (p *PiecePicker) RestorePiece(pieceIndex int)
- func (p PiecePicker) TotalPieces() int
- func (p *PiecePicker) WeHave(pieceIndex int)
- func (p *PiecePicker) WeHaveBlock(b data.PieceBlock)
- type PieceSnapshot
- type PieceSnapshotState
- type PieceState
- type Policy
- func (p *Policy) AddPeer(peer Peer) (bool, error)
- func (p Policy) ComparePeerErase(lhs, rhs Peer) bool
- func (p Policy) ComparePeers(lhs, rhs Peer) bool
- func (p *Policy) ConnectOnePeer(sessionTime int64) (bool, error)
- func (p *Policy) ConnectionClosed(c *PeerConnection, sessionTime int64)
- func (p *Policy) ErasePeers()
- func (p *Policy) FindConnectCandidate(sessionTime int64) *Peer
- func (p Policy) FindPeer(ep protocol.Endpoint) *Peer
- func (p Policy) Get(endpoint protocol.Endpoint) *Peer
- func (p Policy) GetSourceRank(sourceBitmask int) int
- func (p Policy) IsConnectCandidate(pe Peer) bool
- func (p Policy) IsEraseCandidate(pe Peer) bool
- func (p *Policy) MergeSourceExchangePeers(peers []Peer) int
- func (p *Policy) NewConnection(c *PeerConnection) error
- func (p Policy) NumConnectCandidates() int
- func (p *Policy) PeersForSourceExchange(exclude protocol.Endpoint, limit int) []Peer
- func (p *Policy) SetConnection(peer *Peer, c *PeerConnection)
- func (p Policy) Size() int
- type RemotePeerInfo
- type RequestedUploadBlock
- type SearchHandle
- type SearchParams
- type SearchResult
- type SearchResultSource
- type SearchScope
- type SearchSnapshot
- type SearchState
- type ServerConnection
- func (s *ServerConnection) AuxPort() int32
- func (s *ServerConnection) ClientID() int32
- func (s *ServerConnection) Connect() error
- func (s *ServerConnection) Endpoint() protocol.Endpoint
- func (s *ServerConnection) GetAddress() *net.TCPAddr
- func (s *ServerConnection) GetIdentifier() string
- func (s *ServerConnection) IsHandshakeCompleted() bool
- func (s *ServerConnection) OnDisconnect(ec BaseErrorCode)
- func (s *ServerConnection) OnServerIDChange(clientID, tcpFlags, auxPort int32)
- func (s *ServerConnection) ProcessIncoming() error
- func (s *ServerConnection) SecondTick(currentSessionTime int64)
- func (s *ServerConnection) SendCallbackRequest(clientID int32)
- func (s *ServerConnection) SendFileSourcesRequest(hash protocol.Hash, size int64)
- func (s *ServerConnection) SendGetList()
- func (s *ServerConnection) SendLoginRequest()
- func (s *ServerConnection) SendOfferFiles(packet *serverproto.OfferFiles)
- func (s *ServerConnection) SendSearchMore()
- func (s *ServerConnection) SendSearchRequest(packet *serverproto.SearchRequest)
- func (s *ServerConnection) TCPFlags() int32
- type ServerConnectionCandidate
- type ServerConnectionPolicy
- func (p ServerConnectionPolicy) GetConnectCandidate(currentSessionTime int64) *ServerConnectionCandidate
- func (p ServerConnectionPolicy) HasCandidate() bool
- func (p ServerConnectionPolicy) HasIterations() bool
- func (p *ServerConnectionPolicy) RemoveConnectCandidates()
- func (p *ServerConnectionPolicy) SetConnectCandidate(identifier string, address *net.TCPAddr, currentSessionTime int64)
- func (p *ServerConnectionPolicy) SetServerConnectionFailed(identifier string, address *net.TCPAddr, currentSessionTime int64)
- type ServerSnapshot
- type Session
- func (s *Session) AddSharedDir(path string) error
- func (s *Session) AddTransfer(hash protocol.Hash, size int64, file *os.File) (TransferHandle, error)
- func (s *Session) AddTransferParams(atp AddTransferParams) (TransferHandle, error)
- func (s *Session) AddTransferWithHandler(hash protocol.Hash, size int64, handler disk.FileHandler) (TransferHandle, error)
- func (s *Session) CloseConnection(connection *PeerConnection)
- func (s *Session) CloseListener()
- func (s *Session) ConfigureSession(st Settings)
- func (s *Session) ConnectNewPeers()
- func (s *Session) ConnectTo(identifier string, address *net.TCPAddr) error
- func (s *Session) ConnectedServerID() string
- func (s *Session) ConnectedServerIDs() []string
- func (s *Session) Credits() *PeerCreditManager
- func (s *Session) DisconnectFrom()
- func (s *Session) FindTransfer(hash protocol.Hash) TransferHandle
- func (s *Session) GetAppVersion() int
- func (s *Session) GetClientID() int32
- func (s *Session) GetClientName() string
- func (s *Session) GetCompressionVersion() int
- func (s *Session) GetCurrentTime() int64
- func (s *Session) GetDHTTracker() *DHTTracker
- func (s *Session) GetListenPort() int
- func (s *Session) GetModBuildVersion() int
- func (s *Session) GetModMajorVersion() int
- func (s *Session) GetModMinorVersion() int
- func (s *Session) GetModName() string
- func (s *Session) GetTransfers() []TransferHandle
- func (s *Session) GetUDPPort() int
- func (s *Session) GetUserAgent() protocol.Hash
- func (s *Session) ImportSharedFile(path string) error
- func (s *Session) IsFriendSlot(hash protocol.Hash) bool
- func (s *Session) ListSharedDirs() []string
- func (s *Session) Listen() error
- func (s *Session) LookupTransfer(hash protocol.Hash) *Transfer
- func (s *Session) OnServerConnectionClosed(sc *ServerConnection, ec BaseErrorCode)
- func (s *Session) OnServerIDChange(sc *ServerConnection, clientID, tcpFlags, auxPort int32)
- func (s *Session) OnServerSearchResult(sc *ServerConnection, result *serverproto.SearchResult)
- func (s *Session) PublishTransferToKAD(t *Transfer)
- func (s *Session) PublishTransferToServer(t *Transfer)
- func (s *Session) PumpIO()
- func (s *Session) RefreshUPnPMapping()
- func (s *Session) RemoveDiskTask(transfer *Transfer)
- func (s *Session) RemoveSharedDir(path string) error
- func (s *Session) RemoveSharedFile(hash protocol.Hash) bool
- func (s *Session) RemoveTransfer(hash protocol.Hash, deleteFile bool) error
- func (s *Session) RequestSourcesNow(transfer *Transfer) bool
- func (s *Session) RescanSharedDirs() error
- func (s *Session) SearchSnapshot() SearchSnapshot
- func (s *Session) SecondTick(currentSessionTime, tickIntervalMS int64)
- func (s *Session) SendDHTSourcesRequest(hash protocol.Hash, size int64, transfer *Transfer) bool
- func (s *Session) SendSourcesRequest(hash protocol.Hash, size int64) bool
- func (s *Session) ServerSnapshots() []ServerSnapshot
- func (s *Session) SetDHTTracker(tracker *DHTTracker)
- func (s *Session) SetFriendSlot(hash protocol.Hash, enabled bool)
- func (s *Session) SharedFiles() []*SharedFile
- func (s *Session) SharedStore() *SharedStore
- func (s *Session) StartSearch(params SearchParams) (SearchHandle, error)
- func (s *Session) StopSearch(id uint32) error
- func (s *Session) SubmitDiskTask(task TransferCallable)
- func (s *Session) SyncDHTListenPort()
- func (s *Session) UploadQueue() *UploadQueue
- type Settings
- type SharedFile
- func (s *SharedFile) AvailablePieces() protocol.BitField
- func (s *SharedFile) CanUpload() bool
- func (s *SharedFile) CanUploadRange(begin, end int64) bool
- func (s *SharedFile) FileLabel() string
- func (s *SharedFile) GetHash() protocol.Hash
- func (s *SharedFile) ReadRange(begin, end int64) ([]byte, error)
- func (s *SharedFile) Size() int64
- func (s *SharedFile) UploadHashSet() []protocol.Hash
- func (s *SharedFile) UploadPriority() UploadPriority
- type SharedOrigin
- type SharedStore
- type SpeedMonitor
- type StatChannel
- func (s *StatChannel) Add(count int64)
- func (s *StatChannel) AddChannel(other StatChannel)
- func (s *StatChannel) Clear()
- func (s *StatChannel) Counter() int64
- func (s *StatChannel) LowPassRate() int64
- func (s *StatChannel) MergeChannel(other StatChannel)
- func (s *StatChannel) Rate() int64
- func (s *StatChannel) SecondTick(timeIntervalMS int64)
- func (s *StatChannel) Total() int64
- type Statistics
- func (s *Statistics) Add(other Statistics) *Statistics
- func (s *Statistics) Clear()
- func (s Statistics) DownloadPayloadRate() int64
- func (s Statistics) DownloadRate() int64
- func (s Statistics) LastDownload() int64
- func (s Statistics) LastUpload() int64
- func (s Statistics) LowPassDownloadRate() int64
- func (s Statistics) LowPassUploadRate() int64
- func (s *Statistics) Merge(other Statistics) *Statistics
- func (s *Statistics) ReceiveBytes(protocolBytes, payloadBytes int64)
- func (s *Statistics) SecondTick(timeIntervalMS int64)
- func (s *Statistics) SendBytes(protocolBytes, payloadBytes int64)
- func (s Statistics) TotalPayloadDownload() int64
- func (s Statistics) TotalPayloadUpload() int64
- func (s Statistics) TotalProtocolDownload() int64
- func (s Statistics) TotalProtocolUpload() int64
- func (s Statistics) TotalUpload() int64
- func (s Statistics) UploadPayloadRate() int64
- func (s Statistics) UploadRate() int64
- type Transfer
- func (t *Transfer) Abort(deleteFile bool) error
- func (t *Transfer) ActiveConnections() int
- func (t *Transfer) AddPeer(endpoint protocol.Endpoint, sourceFlag int) error
- func (t *Transfer) AddPeerFromKADV6Search(entry kadv6.SearchEntry) (bool, error)
- func (t *Transfer) AddStats(s Statistics)
- func (t *Transfer) AsyncRestoreBlock(block data.PieceBlock)
- func (t *Transfer) AttachIncomingPeer(c *PeerConnection) error
- func (t *Transfer) AttachPeer(c *PeerConnection) error
- func (t *Transfer) AvailablePieces() protocol.BitField
- func (t *Transfer) CanUpload() bool
- func (t *Transfer) CanUploadRange(begin, end int64) bool
- func (t *Transfer) ConnectToPeer(peerInfo *Peer) (*PeerConnection, error)
- func (t *Transfer) FileLabel() string
- func (t *Transfer) FileName() string
- func (t *Transfer) ForceSourceDiscoveryNow()
- func (t *Transfer) GetCreateTime() int64
- func (t *Transfer) GetFile() *os.File
- func (t *Transfer) GetFilePath() string
- func (t *Transfer) GetHash() protocol.Hash
- func (t *Transfer) GetPeersInfo() []PeerInfo
- func (t *Transfer) GetPieceManager() *PieceManager
- func (t *Transfer) GetStatus() TransferStatus
- func (t *Transfer) IsAborted() bool
- func (t *Transfer) IsFinished() bool
- func (t *Transfer) IsPaused() bool
- func (t *Transfer) NeedMoreSources() bool
- func (t *Transfer) NeedResumeDataSave() bool
- func (t *Transfer) OnBlockRestoreCompleted(block data.PieceBlock, ec BaseErrorCode)
- func (t *Transfer) OnBlockWriteCompleted(block data.PieceBlock, _ [][]byte, ec BaseErrorCode)
- func (t *Transfer) OnPieceHashCompleted(pieceIndex int, hash protocol.Hash)
- func (t *Transfer) OnReleaseFile(_ BaseErrorCode, _ [][]byte, _ bool)
- func (t *Transfer) Pause()
- func (t *Transfer) PauseWithDisconnect()
- func (t *Transfer) PieceSnapshots() []PieceSnapshot
- func (t *Transfer) QueuePieceHash(pieceIndex int) bool
- func (t *Transfer) ReadRange(begin, end int64) ([]byte, error)
- func (t *Transfer) RemovePeerConnection(c *PeerConnection)
- func (t *Transfer) Resume()
- func (t *Transfer) ResumeData() *protocol.TransferResumeData
- func (t *Transfer) ResumeWithState()
- func (t *Transfer) SecondTick(accumulator *Statistics, tickIntervalMS int64)
- func (t *Transfer) SetHashSet(hash protocol.Hash, hashes []protocol.Hash)
- func (t *Transfer) SetUploadPriority(priority UploadPriority)
- func (t *Transfer) Size() int64
- func (t *Transfer) TryConnectPeer(sessionTime int64) (bool, error)
- func (t *Transfer) UploadHashSet() []protocol.Hash
- func (t *Transfer) UploadPriority() UploadPriority
- func (t *Transfer) WantMorePeers() bool
- func (t *Transfer) WeHave(pieceIndex int)
- type TransferCallable
- type TransferHandle
- func (h TransferHandle) ActiveConnections() int
- func (h TransferHandle) GetCreateTime() int64
- func (h TransferHandle) GetFile() *os.File
- func (h TransferHandle) GetFilePath() string
- func (h TransferHandle) GetHash() protocol.Hash
- func (h TransferHandle) GetPeersInfo() []PeerInfo
- func (h TransferHandle) GetResumeData() *protocol.TransferResumeData
- func (h TransferHandle) GetSize() int64
- func (h TransferHandle) GetStatus() TransferStatus
- func (h TransferHandle) IsFinished() bool
- func (h TransferHandle) IsPaused() bool
- func (h TransferHandle) IsResumed() bool
- func (h TransferHandle) IsValid() bool
- func (h TransferHandle) NeedResumeDataSave() bool
- func (h TransferHandle) Pause()
- func (h TransferHandle) PieceSnapshots() []PieceSnapshot
- func (h TransferHandle) Resume()
- type TransferProgressEvent
- type TransferProgressSnapshot
- type TransferSnapshot
- type TransferState
- type TransferStatus
- type UploadPriority
- type UploadQueue
- func (q *UploadQueue) AddClientToQueue(client *PeerConnection)
- func (q *UploadQueue) CheckForTimeOver(client *PeerConnection) bool
- func (q *UploadQueue) IsOnUploadQueue(client *PeerConnection) bool
- func (q *UploadQueue) IsUploading(client *PeerConnection) bool
- func (q *UploadQueue) Process()
- func (q *UploadQueue) RemoveFromUploadQueue(client *PeerConnection) bool
- func (q *UploadQueue) RemoveFromWaitingQueue(client *PeerConnection) bool
- func (q *UploadQueue) ResumeUpload(hash protocol.Hash)
- func (q *UploadQueue) SuspendUpload(hash protocol.Hash, terminate bool) uint16
- type UploadState
- type UploadableResource
Constants ¶
const ( PieceSize int64 = 9728000 BlockSize int64 = 190 * 1024 BlockSizeInt = int(BlockSize) BlocksPerPiece = int(PieceSize / BlockSize) HighestLowIDED2K int64 = 16777216 RequestQueueSize = 3 PartsInRequest = 3 )
const ( PeerIncoming byte = 0x1 PeerServer byte = 0x2 PeerDHT byte = 0x4 PeerResume byte = 0x8 PeerSourceExchange byte = 0x10 )
const ( MaxPeerListSize = 100 MinReconnectTimeout = 10 SourceExchangePeerLimit = 50 )
const EndGameDPLimit = 4
const InvalidETA int64 = -1
const (
InvalidSpeed int64 = -1
)
const MaxOutgoingBufferSize = 102*2 + 8
Variables ¶
var ErrClientStopped = errors.New("client stopped")
Functions ¶
func Byte2String ¶
func ComputeEd2kFileMeta ¶
func ComputeEd2kFileMeta(path string) (root protocol.Hash, size int64, pieceHashes []protocol.Hash, err error)
ComputeEd2kFileMeta 从本地文件计算 ed2k 根哈希、大小与分片哈希列表(与 eMule 分片规则一致)。
func CurrentTime ¶
func CurrentTime() int64
func CurrentTimeHiRes ¶
func CurrentTimeHiRes() int64
func CurrentTimeMillis ¶
func CurrentTimeMillis() int64
func CurrentTimeToDeadline ¶
func HTONLBytes ¶
func Int2Address ¶
func IsLocalAddress ¶
func MakeFullED2KVersion ¶
func PackToNetworkByteOrder ¶
func PeerSourceLabels ¶
func UpdateCachedTime ¶
func UpdateCachedTime()
Types ¶
type AddTransferParams ¶
type AddTransferParams struct {
Hash protocol.Hash
CreateTime int64
Size int64
FilePath string
Paused bool
ResumeData *protocol.TransferResumeData
Handler disk.FileHandler
}
func NewAddTransferParamsFromHandler ¶
func NewAddTransferParamsFromHandler(h protocol.Hash, createTime int64, size int64, handler disk.FileHandler, paused bool) AddTransferParams
func (*AddTransferParams) SetExternalFileHandler ¶
func (a *AddTransferParams) SetExternalFileHandler(handler disk.FileHandler)
type AsyncHash ¶
type AsyncHash struct {
PieceIndex int
// contains filtered or unexported fields
}
func NewAsyncHash ¶
func (*AsyncHash) Call ¶
func (a *AsyncHash) Call() AsyncOperationResult
type AsyncHashResult ¶
func (*AsyncHashResult) Code ¶
func (a *AsyncHashResult) Code() BaseErrorCode
func (*AsyncHashResult) OnCompleted ¶
func (a *AsyncHashResult) OnCompleted()
type AsyncOperationResult ¶
type AsyncOperationResult interface {
OnCompleted()
Code() BaseErrorCode
}
type AsyncRelease ¶
type AsyncRelease struct {
DeleteFile bool
// contains filtered or unexported fields
}
func NewAsyncRelease ¶
func NewAsyncRelease(transfer *Transfer, deleteFile bool) *AsyncRelease
func (*AsyncRelease) Call ¶
func (a *AsyncRelease) Call() AsyncOperationResult
type AsyncReleaseResult ¶
type AsyncReleaseResult struct {
Transfer *Transfer
Buffers [][]byte
DeleteFile bool
EC BaseErrorCode
}
func (*AsyncReleaseResult) Code ¶
func (a *AsyncReleaseResult) Code() BaseErrorCode
func (*AsyncReleaseResult) OnCompleted ¶
func (a *AsyncReleaseResult) OnCompleted()
type AsyncRestore ¶
type AsyncRestore struct {
Block data.PieceBlock
FileSize int64
// contains filtered or unexported fields
}
func NewAsyncRestore ¶
func NewAsyncRestore(transfer *Transfer, block data.PieceBlock, fileSize int64) *AsyncRestore
func (*AsyncRestore) Call ¶
func (a *AsyncRestore) Call() AsyncOperationResult
type AsyncRestoreResult ¶
type AsyncRestoreResult struct {
Block data.PieceBlock
Buffers [][]byte
Transfer *Transfer
EC BaseErrorCode
}
func (*AsyncRestoreResult) Code ¶
func (a *AsyncRestoreResult) Code() BaseErrorCode
func (*AsyncRestoreResult) OnCompleted ¶
func (a *AsyncRestoreResult) OnCompleted()
type AsyncWrite ¶
type AsyncWrite struct {
Block data.PieceBlock
Buffer []byte
// contains filtered or unexported fields
}
func NewAsyncWrite ¶
func NewAsyncWrite(block data.PieceBlock, buffer []byte, transfer *Transfer) *AsyncWrite
func (*AsyncWrite) Call ¶
func (a *AsyncWrite) Call() AsyncOperationResult
type AsyncWriteResult ¶
type AsyncWriteResult struct {
Block data.PieceBlock
Buffers [][]byte
Transfer *Transfer
EC BaseErrorCode
}
func (*AsyncWriteResult) Code ¶
func (a *AsyncWriteResult) Code() BaseErrorCode
func (*AsyncWriteResult) OnCompleted ¶
func (a *AsyncWriteResult) OnCompleted()
type BaseErrorCode ¶
type BlockManager ¶
type BlockManager struct {
// contains filtered or unexported fields
}
func NewBlockManager ¶
func NewBlockManager(piece, buffersCount int) *BlockManager
func (*BlockManager) Buffers ¶
func (b *BlockManager) Buffers() [][]byte
func (*BlockManager) ByteBuffersCount ¶
func (b *BlockManager) ByteBuffersCount() int
func (*BlockManager) HashedSize ¶
func (b *BlockManager) HashedSize() int
func (*BlockManager) PieceHash ¶
func (b *BlockManager) PieceHash() protocol.Hash
func (*BlockManager) PieceIndex ¶
func (b *BlockManager) PieceIndex() int
func (*BlockManager) RegisterBlock ¶
func (b *BlockManager) RegisterBlock(blockIndex int, buffer []byte) [][]byte
type BlockState ¶
type BlockState byte
const ( StateNone BlockState = iota StateRequested StateWriting StateFinished )
type BlocksEnumerator ¶
type BlocksEnumerator struct {
// contains filtered or unexported fields
}
func NewBlocksEnumerator ¶
func NewBlocksEnumerator(pieceCount, blocksInLastPiece int) BlocksEnumerator
func (BlocksEnumerator) BlocksInPiece ¶
func (b BlocksEnumerator) BlocksInPiece(pieceIndex int) int
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) AddDHTBootstrapNodes ¶
func (*Client) AddLink ¶
func (c *Client) AddLink(linkValue, outputDir string) (TransferHandle, string, error)
func (*Client) AddSharedDir ¶
AddSharedDir 见 Session.AddSharedDir。
func (*Client) AddTransfer ¶
func (c *Client) AddTransfer(atp AddTransferParams) (TransferHandle, error)
func (*Client) ConnectSavedServer ¶
func (*Client) ConnectServerLink ¶
func (*Client) ConnectServerMet ¶
func (*Client) ConnectServers ¶
func (*Client) EnableDHT ¶
func (c *Client) EnableDHT() *DHTTracker
func (*Client) FindTransfer ¶
func (c *Client) FindTransfer(hash protocol.Hash) TransferHandle
func (*Client) GetDHTTracker ¶
func (c *Client) GetDHTTracker() *DHTTracker
func (*Client) ImportSharedFile ¶
ImportSharedFile 见 Session.ImportSharedFile。
func (*Client) ListSharedDirs ¶
ListSharedDirs 见 Session.ListSharedDirs。
func (*Client) LoadDHTNodesDat ¶
func (*Client) LoadServerMet ¶
func (c *Client) LoadServerMet(path string) ([]serverproto.ServerMetEntry, error)
func (*Client) PeerStatuses ¶
func (c *Client) PeerStatuses() []ClientPeerSnapshot
func (*Client) PublishDHTKeyword ¶
func (*Client) PublishDHTNotes ¶
func (*Client) PublishDHTSource ¶
func (*Client) RemoveSharedDir ¶
RemoveSharedDir 见 Session.RemoveSharedDir。
func (*Client) RemoveSharedFile ¶
RemoveSharedFile 从共享库移除。
func (*Client) RemoveTransfer ¶
func (*Client) RescanSharedDirs ¶
RescanSharedDirs 见 Session.RescanSharedDirs。
func (*Client) ResumeUpload ¶
func (*Client) SearchDHTKeywords ¶
func (*Client) SearchSnapshot ¶
func (c *Client) SearchSnapshot() SearchSnapshot
func (*Client) ServerAddress ¶
func (*Client) ServerStatuses ¶
func (c *Client) ServerStatuses() []ServerSnapshot
func (*Client) SetAutoSaveInterval ¶
func (*Client) SetDHTStoragePoint ¶
func (*Client) SetDHTTracker ¶
func (c *Client) SetDHTTracker(tracker *DHTTracker)
func (*Client) SetStatePath ¶
func (*Client) SetStateStore ¶
func (c *Client) SetStateStore(store ClientStateStore)
func (*Client) SetTransferUploadPriority ¶
func (c *Client) SetTransferUploadPriority(hash protocol.Hash, priority UploadPriority) error
func (*Client) StartSearch ¶
func (c *Client) StartSearch(params SearchParams) (SearchHandle, error)
func (*Client) StateStore ¶
func (c *Client) StateStore() ClientStateStore
func (*Client) Status ¶
func (c *Client) Status() ClientStatus
func (*Client) StopSearch ¶
func (*Client) SubscribeStatus ¶
func (c *Client) SubscribeStatus() (<-chan ClientStatusEvent, func())
SubscribeStatus registers a non-blocking status listener using the default buffer size.
func (*Client) SubscribeStatusBuffered ¶
func (c *Client) SubscribeStatusBuffered(buffer int) (<-chan ClientStatusEvent, func())
SubscribeStatusBuffered registers a non-blocking status listener.
The returned channel receives snapshots as the client state changes. If the receiver falls behind and the channel buffer is full, newer snapshots may be dropped instead of blocking the client loop.
The returned cancel function unregisters the listener and closes the channel.
func (*Client) SubscribeTransferProgress ¶
func (c *Client) SubscribeTransferProgress() (<-chan TransferProgressEvent, func())
SubscribeTransferProgress subscribes to per-transfer progress changes.
Events are emitted only when a transfer's received bytes, done bytes, state, pause flag, or removal status changes.
func (*Client) SubscribeTransferProgressBuffered ¶
func (c *Client) SubscribeTransferProgressBuffered(buffer int) (<-chan TransferProgressEvent, func())
SubscribeTransferProgressBuffered is the buffered variant of SubscribeTransferProgress.
func (*Client) SuspendUpload ¶
func (*Client) TransferSnapshots ¶
func (c *Client) TransferSnapshots() []TransferSnapshot
func (*Client) Transfers ¶
func (c *Client) Transfers() []TransferHandle
type ClientCreditState ¶
type ClientDHTNodeState ¶
type ClientDHTNodeState struct {
ID protocol.Hash `json:"id,omitempty"`
Addr string `json:"addr"`
TCPPort uint16 `json:"tcp_port,omitempty"`
Version byte `json:"version,omitempty"`
Seed bool `json:"seed,omitempty"`
HelloSent bool `json:"hello_sent,omitempty"`
Pinged bool `json:"pinged,omitempty"`
FailCount int `json:"fail_count,omitempty"`
FirstSeen int64 `json:"first_seen,omitempty"`
LastSeen int64 `json:"last_seen,omitempty"`
}
type ClientDHTState ¶
type ClientDHTState struct {
SelfID protocol.Hash `json:"self_id,omitempty"`
Firewalled bool `json:"firewalled"`
LastBootstrap int64 `json:"last_bootstrap,omitempty"`
LastRefresh int64 `json:"last_refresh,omitempty"`
LastFirewalledCheck int64 `json:"last_firewalled_check,omitempty"`
StoragePoint string `json:"storage_point,omitempty"`
Nodes []ClientDHTNodeState `json:"nodes,omitempty"`
RouterNodes []string `json:"router_nodes,omitempty"`
}
type ClientPeerSnapshot ¶
type ClientSharedFileState ¶
type ClientSharedFileState struct {
}
ClientSharedFileState 持久化的共享文件元数据。
type ClientState ¶
type ClientState struct {
Version int `json:"version"`
ServerAddress string `json:"server_address,omitempty"`
Transfers []ClientTransferState `json:"transfers"`
Credits []ClientCreditState `json:"credits,omitempty"`
FriendSlots []protocol.Hash `json:"friend_slots,omitempty"`
DHT *ClientDHTState `json:"dht,omitempty"`
}
type ClientStateStore ¶
type ClientStateStore interface {
Load() (*ClientState, error)
Save(state *ClientState) error
}
type ClientStatus ¶
type ClientStatus struct {
Servers []ServerSnapshot
Peers []ClientPeerSnapshot
Transfers []TransferSnapshot
TotalDone int64
TotalReceived int64
TotalWanted int64
Upload int64
DownloadRate int
UploadRate int
}
type ClientStatusEvent ¶
type ClientStatusEvent struct {
At time.Time
Status ClientStatus
DHT DHTStatus
}
ClientStatusEvent is a point-in-time snapshot emitted by a Client listener.
func (ClientStatusEvent) TransferSnapshots ¶
func (e ClientStatusEvent) TransferSnapshots() []TransferSnapshot
TransferSnapshots returns the transfer snapshots carried by this event.
func (ClientStatusEvent) TransferState ¶
func (e ClientStatusEvent) TransferState(hash protocol.Hash) (TransferState, bool)
TransferState returns the current state for a transfer hash carried by this event.
func (ClientStatusEvent) TransferStates ¶
func (e ClientStatusEvent) TransferStates() map[protocol.Hash]TransferState
TransferStates returns all transfer states in this event keyed by transfer hash.
type ClientTransferState ¶
type ClientTransferState struct {
Hash protocol.Hash `json:"hash"`
Size int64 `json:"size"`
CreateTime int64 `json:"create_time"`
TargetPath string `json:"target_path"`
Paused bool `json:"paused"`
UploadPrio UploadPriority `json:"upload_prio,omitempty"`
ResumeData *protocol.TransferResumeData `json:"resume_data,omitempty"`
}
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
func NewConnection ¶
func NewConnection(session *Session) Connection
func (*Connection) AppendIncoming ¶
func (c *Connection) AppendIncoming(chunk []byte)
func (*Connection) Close ¶
func (c *Connection) Close(ec BaseErrorCode)
func (*Connection) ConsumeIncoming ¶
func (c *Connection) ConsumeIncoming(limit int) []byte
func (*Connection) DecodeFrames ¶
func (c *Connection) DecodeFrames(combiner *protocol.PacketCombiner) ([]protocol.PacketHeader, []protocol.Serializable, error)
func (*Connection) DisconnectCode ¶
func (c *Connection) DisconnectCode() BaseErrorCode
func (*Connection) DoRead ¶
func (c *Connection) DoRead() error
func (*Connection) DrainIncoming ¶
func (c *Connection) DrainIncoming() []byte
func (*Connection) Endpoint ¶
func (c *Connection) Endpoint() protocol.Endpoint
func (*Connection) FlushOutgoing ¶
func (c *Connection) FlushOutgoing() error
func (*Connection) IncomingBytes ¶
func (c *Connection) IncomingBytes() int
func (*Connection) IncomingChunks ¶
func (c *Connection) IncomingChunks() [][]byte
func (*Connection) IsDisconnectHandled ¶
func (c *Connection) IsDisconnectHandled() bool
func (*Connection) IsDisconnecting ¶
func (c *Connection) IsDisconnecting() bool
func (*Connection) MarkDisconnectHandled ¶
func (c *Connection) MarkDisconnectHandled()
func (*Connection) MillisecondsSinceLastReceive ¶
func (c *Connection) MillisecondsSinceLastReceive() int64
func (*Connection) PendingPackets ¶
func (c *Connection) PendingPackets() [][]byte
func (*Connection) PopOutgoing ¶
func (c *Connection) PopOutgoing() []byte
func (*Connection) QueuePacket ¶
func (c *Connection) QueuePacket(packet []byte)
func (*Connection) QueuePacketWithStats ¶
func (c *Connection) QueuePacketWithStats(packet []byte, protocolBytes, payloadBytes int64)
func (*Connection) ReadFrames ¶
func (c *Connection) ReadFrames() ([]protocol.PacketHeader, [][]byte, error)
func (*Connection) ReadFramesWithCombiner ¶
func (c *Connection) ReadFramesWithCombiner(combiner *protocol.PacketCombiner) ([]protocol.PacketHeader, [][]byte, error)
func (*Connection) SecondTick ¶
func (c *Connection) SecondTick(tickIntervalMS int64)
func (*Connection) Statistics ¶
func (c *Connection) Statistics() Statistics
type DHTTracker ¶
type DHTTracker struct {
// contains filtered or unexported fields
}
func NewDHTTracker ¶
func NewDHTTracker(listenPort int, timeout time.Duration) *DHTTracker
func (*DHTTracker) AddNode ¶
func (t *DHTTracker) AddNode(addr *net.UDPAddr)
func (*DHTTracker) AddNodes ¶
func (t *DHTTracker) AddNodes(addrs ...*net.UDPAddr)
func (*DHTTracker) ApplyNodesDat ¶
func (t *DHTTracker) ApplyNodesDat(nodes *kadproto.NodesDat) error
func (*DHTTracker) ApplyState ¶
func (t *DHTTracker) ApplyState(state *ClientDHTState) error
func (*DHTTracker) Close ¶
func (t *DHTTracker) Close()
func (*DHTTracker) IsFirewalled ¶
func (t *DHTTracker) IsFirewalled() bool
func (*DHTTracker) ListenPort ¶
func (t *DHTTracker) ListenPort() int
func (*DHTTracker) LoadNodesDat ¶
func (t *DHTTracker) LoadNodesDat(path string) error
func (*DHTTracker) PublishKeyword ¶
func (t *DHTTracker) PublishKeyword(keywordHash protocol.Hash, entries ...kadproto.SearchEntry) bool
func (*DHTTracker) PublishNotes ¶
func (t *DHTTracker) PublishNotes(fileHash protocol.Hash, entries ...kadproto.SearchEntry) bool
func (*DHTTracker) PublishSource ¶
func (*DHTTracker) SearchKeywords ¶
func (t *DHTTracker) SearchKeywords(hash protocol.Hash, cb func([]kadproto.SearchEntry)) bool
func (*DHTTracker) SearchSources ¶
func (t *DHTTracker) SearchSources(hash protocol.Hash, size int64, cb func([]kadproto.SearchEntry)) bool
func (*DHTTracker) SetStoragePoint ¶
func (t *DHTTracker) SetStoragePoint(addr *net.UDPAddr)
func (*DHTTracker) SnapshotState ¶
func (t *DHTTracker) SnapshotState() *ClientDHTState
func (*DHTTracker) Start ¶
func (t *DHTTracker) Start() error
func (*DHTTracker) Status ¶
func (t *DHTTracker) Status() DHTStatus
type DownloadingBlock ¶
type DownloadingBlock struct {
// contains filtered or unexported fields
}
func (*DownloadingBlock) Abort ¶
func (b *DownloadingBlock) Abort(p *Peer)
func (*DownloadingBlock) Finish ¶
func (b *DownloadingBlock) Finish()
func (DownloadingBlock) IsFinished ¶
func (b DownloadingBlock) IsFinished() bool
func (DownloadingBlock) IsFree ¶
func (b DownloadingBlock) IsFree() bool
func (DownloadingBlock) IsRequested ¶
func (b DownloadingBlock) IsRequested() bool
func (DownloadingBlock) IsWriting ¶
func (b DownloadingBlock) IsWriting() bool
func (*DownloadingBlock) Request ¶
func (b *DownloadingBlock) Request(p *Peer, speed PeerSpeed)
func (*DownloadingBlock) Write ¶
func (b *DownloadingBlock) Write()
type DownloadingPiece ¶
type DownloadingPiece struct {
PieceIndex int
Blocks []DownloadingBlock
// contains filtered or unexported fields
}
func NewDownloadingPiece ¶
func NewDownloadingPiece(pieceIndex, blocksCount int) DownloadingPiece
func (*DownloadingPiece) AbortDownloading ¶
func (d *DownloadingPiece) AbortDownloading(blockIndex int, p *Peer)
func (DownloadingPiece) BlocksCount ¶
func (d DownloadingPiece) BlocksCount() int
func (DownloadingPiece) DownloadedCount ¶
func (d DownloadingPiece) DownloadedCount() int
func (DownloadingPiece) DownloadingBlocksCount ¶
func (d DownloadingPiece) DownloadingBlocksCount() int
func (*DownloadingPiece) FinishBlock ¶
func (d *DownloadingPiece) FinishBlock(blockIndex int)
func (DownloadingPiece) FinishedBlocksCount ¶
func (d DownloadingPiece) FinishedBlocksCount() int
func (DownloadingPiece) IsDownloaded ¶
func (d DownloadingPiece) IsDownloaded(blockIndex int) bool
func (DownloadingPiece) IsFinished ¶
func (d DownloadingPiece) IsFinished(blockIndex int) bool
func (*DownloadingPiece) PickBlocks ¶
func (d *DownloadingPiece) PickBlocks(rq *[]data.PieceBlock, orderLength int, peer *Peer, speed PeerSpeed, endGame bool) int
func (*DownloadingPiece) RequestBlock ¶
func (d *DownloadingPiece) RequestBlock(blockIndex int, p *Peer, speed PeerSpeed)
func (DownloadingPiece) TotalBlocks ¶
func (d DownloadingPiece) TotalBlocks() int
func (*DownloadingPiece) WriteBlock ¶
func (d *DownloadingPiece) WriteBlock(blockIndex int) bool
func (DownloadingPiece) WritingBlocksCount ¶
func (d DownloadingPiece) WritingBlocksCount() int
type EMuleLink ¶
func ParseEMuleLink ¶
type ErrorCode ¶
type ErrorCode int
const ( NoError ErrorCode = iota ServerConnUnsupportedPacket PeerConnUnsupportedPacket PacketHeaderUndefined InflateError PacketSizeIncorrect PacketSizeOverflow ServerMetHeaderIncorrect GenericInstantiationError GenericIllegalAccess EndOfStream ErrorCode = 10 IOException ErrorCode = 11 NoTransfer ErrorCode = 12 FileNotFound ErrorCode = 13 OutOfParts ErrorCode = 14 ConnectionTimeout ErrorCode = 15 ChannelClosed ErrorCode = 16 QueueRanking ErrorCode = 17 FileIOError ErrorCode = 18 UnableToDeleteFile ErrorCode = 19 InternalError ErrorCode = 20 BufferUnderflowException ErrorCode = 21 BufferGetException ErrorCode = 22 WrongHashSet ErrorCode = 23 HashMismatch ErrorCode = 24 NonWriteableChannel ErrorCode = 25 TagTypeUnknown ErrorCode = 30 TagToStringInvalid ErrorCode = 31 TagToIntInvalid ErrorCode = 32 TagToLongInvalid ErrorCode = 33 TagToFloatInvalid ErrorCode = 34 TagToHashInvalid ErrorCode = 35 TagFromStringInvalidCP ErrorCode = 36 TagToBlobInvalid ErrorCode = 37 TagToBSOBInvalid ErrorCode = 38 DuplicatePeer ErrorCode = 40 DuplicatePeerConnection ErrorCode = 41 PeerLimitExceeded ErrorCode = 42 SecurityException ErrorCode = 43 UnsupportedEncoding ErrorCode = 44 IllegalArgument ErrorCode = 45 TransferFinished ErrorCode = 50 TransferPaused ErrorCode = 51 TransferAborted ErrorCode = 52 NoMemory ErrorCode = 60 SessionStopping ErrorCode = 61 IncomingDirInaccessible ErrorCode = 62 BufferTooLarge ErrorCode = 63 NotConnected ErrorCode = 64 Interrupted ErrorCode = 65 PortMappingAlreadyMapped ErrorCode = 70 PortMappingNoDevice ErrorCode = 71 PortMappingError ErrorCode = 72 PortMappingIOError ErrorCode = 73 PortMappingSAXError ErrorCode = 74 PortMappingConfigError ErrorCode = 75 PortMappingException ErrorCode = 76 PortMappingCommandRejected ErrorCode = 77 DHTRequestAlreadyRunning ErrorCode = 80 DHTTrackerAborted ErrorCode = 81 LinkMailformed ErrorCode = 90 URISyntaxError ErrorCode = 91 NumberFormatError ErrorCode = 92 UnknownLinkType ErrorCode = 93 GithubCfgIPIsNull ErrorCode = 94 GithubCfgPortsAreNull ErrorCode = 95 GithubCfgPortsAreEmpty ErrorCode = 96 InvalidPRParameter ErrorCode = 97 PeerRequestOverflow ErrorCode = 98 Fail ErrorCode = 100 )
func (ErrorCode) Description ¶
type FileClientStateStore ¶
type FileClientStateStore struct {
// contains filtered or unexported fields
}
func NewFileClientStateStore ¶
func NewFileClientStateStore(path string) *FileClientStateStore
func (*FileClientStateStore) Load ¶
func (s *FileClientStateStore) Load() (*ClientState, error)
func (*FileClientStateStore) Path ¶
func (s *FileClientStateStore) Path() string
func (*FileClientStateStore) Save ¶
func (s *FileClientStateStore) Save(state *ClientState) error
type JED2KError ¶
type JED2KError struct {
Cause error
EC BaseErrorCode
}
func NewError ¶
func NewError(ec BaseErrorCode) *JED2KError
func WrapError ¶
func WrapError(cause error, ec BaseErrorCode) *JED2KError
func (*JED2KError) Error ¶
func (e *JED2KError) Error() string
func (*JED2KError) ErrorCode ¶
func (e *JED2KError) ErrorCode() BaseErrorCode
func (*JED2KError) Unwrap ¶
func (e *JED2KError) Unwrap() error
type KadRoutingNode ¶
type KadRoutingNode struct {
ID kadproto.ID
Addr *net.UDPAddr
TCPPort uint16
Version byte
Seed bool
HelloSent bool
Pinged bool
FailCount int
FirstSeen time.Time
LastSeen time.Time
}
func (*KadRoutingNode) Key ¶
func (n *KadRoutingNode) Key() string
func (*KadRoutingNode) KnownID ¶
func (n *KadRoutingNode) KnownID() bool
type MiscOptions ¶
type MiscOptions struct {
AICHVersion int
UnicodeSupport int
UDPVer int
DataCompVer int
SupportSecIdent int
SourceExchange1Ver int
ExtendedRequestsVer int
AcceptCommentVer int
MultiPacket int
SupportsPreview int
}
func (*MiscOptions) Assign ¶
func (m *MiscOptions) Assign(value int)
func (MiscOptions) IntValue ¶
func (m MiscOptions) IntValue() int
type MiscOptions2 ¶
type MiscOptions2 struct {
Value int
}
func (*MiscOptions2) Assign ¶
func (m *MiscOptions2) Assign(value int)
func (*MiscOptions2) SetCaptcha ¶
func (m *MiscOptions2) SetCaptcha()
func (*MiscOptions2) SetExtMultipacket ¶
func (m *MiscOptions2) SetExtMultipacket()
func (*MiscOptions2) SetLargeFiles ¶
func (m *MiscOptions2) SetLargeFiles()
func (*MiscOptions2) SetSourceExt2 ¶
func (m *MiscOptions2) SetSourceExt2()
func (MiscOptions2) SupportCaptcha ¶
func (m MiscOptions2) SupportCaptcha() bool
func (MiscOptions2) SupportExtMultipacket ¶
func (m MiscOptions2) SupportExtMultipacket() bool
func (MiscOptions2) SupportLargeFiles ¶
func (m MiscOptions2) SupportLargeFiles() bool
func (MiscOptions2) SupportSourceExt2 ¶
func (m MiscOptions2) SupportSourceExt2() bool
type Peer ¶
type Peer struct {
LastConnected int64
NextConnection int64
FailCount int
Connectable bool
SourceFlag int
Connection any
Endpoint protocol.Endpoint
// DialAddr 可选;非 nil 时优先用于 TCP 拨号(如 KADV6 纯 IPv6 来源),与 Endpoint 可并存(IPv4 时常同步)。
DialAddr *net.TCPAddr
}
func NewPeerFromTCPAddr ¶
NewPeerFromTCPAddr 从 TCP 地址构造 Peer:IPv4 时填充 Endpoint;IPv6 时仅填 DialAddr(Policy 排序用 DialAddr 字符串键)。
func NewPeerWithSource ¶
func PeerFromKADV6SearchEntry ¶
func PeerFromKADV6SearchEntry(se kadv6.SearchEntry, sourceFlag int) (Peer, bool)
PeerFromKADV6SearchEntry 将 KADV6 SearchEntry 中的 TCP 源转为 Policy 用 Peer(Connectable=true)。 若条目不含有效 IPv6 源地址则返回 false。供 KADV6Tracker 接入后调用。
func (Peer) CanEncodeAnswerSources2 ¶
CanEncodeAnswerSources2 当前 AnswerSources2 v4 条目仅支持 IPv4 hybrid uint32;纯 IPv6 无法编码。
func (Peer) EffectiveEndpointForSX ¶
EffectiveEndpointForSX 返回用于 SX 条目中 UserID 的 IPv4 Endpoint(含 IPv4-mapped IPv6 映射为 IPv4)。
func (Peer) HasDialableAddress ¶
HasDialableAddress 是否具备可尝试 TCP 的地址(IPv4 Endpoint 或 DialAddr)。
type PeerConnection ¶
type PeerConnection struct {
Connection
// contains filtered or unexported fields
}
func NewIncomingPeerConnection ¶
func NewIncomingPeerConnection(session *Session, conn net.Conn) *PeerConnection
func NewPeerConnection ¶
func (*PeerConnection) AbortAllRequests ¶
func (p *PeerConnection) AbortAllRequests()
func (*PeerConnection) ActiveUploadSource ¶
func (p *PeerConnection) ActiveUploadSource() UploadableResource
func (*PeerConnection) AddUploadRequest ¶
func (p *PeerConnection) AddUploadRequest(req data.PeerRequest)
func (*PeerConnection) ClearUploadBlockRequests ¶
func (p *PeerConnection) ClearUploadBlockRequests()
func (*PeerConnection) ClearUploadWaitStart ¶
func (p *PeerConnection) ClearUploadWaitStart()
func (*PeerConnection) CompleteBlock ¶
func (p *PeerConnection) CompleteBlock(pb *PendingBlock) bool
func (*PeerConnection) Connect ¶
func (p *PeerConnection) Connect() error
func (*PeerConnection) Endpoint ¶
func (p *PeerConnection) Endpoint() protocol.Endpoint
func (*PeerConnection) FriendSlot ¶
func (p *PeerConnection) FriendSlot() bool
func (*PeerConnection) GetDownloading ¶
func (p *PeerConnection) GetDownloading(block data.PieceBlock) *PendingBlock
func (*PeerConnection) GetInfo ¶
func (p *PeerConnection) GetInfo() PeerInfo
func (*PeerConnection) GetPeer ¶
func (p *PeerConnection) GetPeer() *Peer
func (*PeerConnection) HandleAnswerSources2 ¶
func (p *PeerConnection) HandleAnswerSources2(ans *clientproto.AnswerSources2)
func (*PeerConnection) HandleClientCancelTransfer ¶
func (p *PeerConnection) HandleClientCancelTransfer()
func (*PeerConnection) HandleClientFileRequest ¶
func (p *PeerConnection) HandleClientFileRequest(value *clientproto.FileRequest)
func (*PeerConnection) HandleClientFileStatusRequest ¶
func (p *PeerConnection) HandleClientFileStatusRequest(value *clientproto.FileStatusRequest)
func (*PeerConnection) HandleClientHashSetRequest ¶
func (p *PeerConnection) HandleClientHashSetRequest(value *clientproto.HashSetRequest)
func (*PeerConnection) HandleClientHello ¶
func (p *PeerConnection) HandleClientHello(value *clientproto.Hello)
func (*PeerConnection) HandleClientRequestParts32 ¶
func (p *PeerConnection) HandleClientRequestParts32(value *clientproto.RequestParts32) error
func (*PeerConnection) HandleClientRequestParts64 ¶
func (p *PeerConnection) HandleClientRequestParts64(value *clientproto.RequestParts64) error
func (*PeerConnection) HandleClientStartUpload ¶
func (p *PeerConnection) HandleClientStartUpload(value *clientproto.StartUpload)
func (*PeerConnection) HandleExtHello ¶
func (p *PeerConnection) HandleExtHello(_ *clientproto.ExtHello)
func (*PeerConnection) HandleFileAnswer ¶
func (p *PeerConnection) HandleFileAnswer(value *clientproto.FileAnswer)
func (*PeerConnection) HandleFileStatusAnswer ¶
func (p *PeerConnection) HandleFileStatusAnswer(value *clientproto.FileStatusAnswer)
func (*PeerConnection) HandleHelloAnswer ¶
func (p *PeerConnection) HandleHelloAnswer(value *clientproto.HelloAnswer)
func (*PeerConnection) HandleRequestSources2 ¶
func (p *PeerConnection) HandleRequestSources2(req *clientproto.RequestSources2)
func (*PeerConnection) HasEndpoint ¶
func (p *PeerConnection) HasEndpoint() bool
func (*PeerConnection) IsRequesting ¶
func (p *PeerConnection) IsRequesting(block data.PieceBlock) bool
func (*PeerConnection) IsUploadConnected ¶
func (p *PeerConnection) IsUploadConnected() bool
func (*PeerConnection) IsUploadLowID ¶
func (p *PeerConnection) IsUploadLowID() bool
func (*PeerConnection) OnConnect ¶
func (p *PeerConnection) OnConnect()
func (*PeerConnection) OnDisconnect ¶
func (p *PeerConnection) OnDisconnect(ec BaseErrorCode)
func (*PeerConnection) PrepareHello ¶
func (p *PeerConnection) PrepareHello() clientproto.Hello
func (*PeerConnection) PrepareHelloAnswer ¶
func (p *PeerConnection) PrepareHelloAnswer() clientproto.HelloAnswer
func (*PeerConnection) ProcessIncoming ¶
func (p *PeerConnection) ProcessIncoming() error
func (*PeerConnection) ReceiveCompressedData ¶
func (p *PeerConnection) ReceiveCompressedData(header protocol.PacketHeader, offset, compressedLength int64, payloadSize int)
func (*PeerConnection) ReceiveData ¶
func (p *PeerConnection) ReceiveData(req data.PeerRequest, compressed bool)
func (*PeerConnection) ReceivePendingData ¶
func (p *PeerConnection) ReceivePendingData()
func (*PeerConnection) RequestBlocks ¶
func (p *PeerConnection) RequestBlocks()
func (*PeerConnection) ResetUploadSession ¶
func (p *PeerConnection) ResetUploadSession()
func (*PeerConnection) SecondTick ¶
func (p *PeerConnection) SecondTick(tickIntervalMS int64)
func (*PeerConnection) SendAcceptUpload ¶
func (p *PeerConnection) SendAcceptUpload()
func (*PeerConnection) SendBlockData ¶
func (p *PeerConnection) SendBlockData()
func (*PeerConnection) SendCancelTransfer ¶
func (p *PeerConnection) SendCancelTransfer()
func (*PeerConnection) SendExtHelloAnswer ¶
func (p *PeerConnection) SendExtHelloAnswer()
func (*PeerConnection) SendFileAnswer ¶
func (p *PeerConnection) SendFileAnswer(res UploadableResource)
func (*PeerConnection) SendFileRequest ¶
func (p *PeerConnection) SendFileRequest(hash protocol.Hash)
func (*PeerConnection) SendFileStatusAnswer ¶
func (p *PeerConnection) SendFileStatusAnswer(res UploadableResource)
func (*PeerConnection) SendFileStatusRequest ¶
func (p *PeerConnection) SendFileStatusRequest(hash protocol.Hash)
func (*PeerConnection) SendHashSetAnswer ¶
func (p *PeerConnection) SendHashSetAnswer(res UploadableResource)
func (*PeerConnection) SendHashSetRequest ¶
func (p *PeerConnection) SendHashSetRequest(hash protocol.Hash)
func (*PeerConnection) SendOutOfPartReqsAndAddToWaitingQueue ¶
func (p *PeerConnection) SendOutOfPartReqsAndAddToWaitingQueue()
func (*PeerConnection) SendOutOfParts ¶
func (p *PeerConnection) SendOutOfParts()
func (*PeerConnection) SendPart ¶
func (p *PeerConnection) SendPart(begin, end int64, payload []byte) error
func (*PeerConnection) SendQueueRanking ¶
func (p *PeerConnection) SendQueueRanking(rank uint16)
func (*PeerConnection) SendRequestParts32 ¶
func (p *PeerConnection) SendRequestParts32(packet *clientproto.RequestParts32)
func (*PeerConnection) SendRequestParts64 ¶
func (p *PeerConnection) SendRequestParts64(packet *clientproto.RequestParts64)
func (*PeerConnection) SendRequestSources2 ¶
func (p *PeerConnection) SendRequestSources2(hash protocol.Hash) error
func (*PeerConnection) SendStartUpload ¶
func (p *PeerConnection) SendStartUpload(hash protocol.Hash)
func (*PeerConnection) SetFriendSlot ¶
func (p *PeerConnection) SetFriendSlot(v bool)
func (*PeerConnection) SetPeer ¶
func (p *PeerConnection) SetPeer(peer *Peer)
func (*PeerConnection) SetTransfer ¶
func (p *PeerConnection) SetTransfer(transfer *Transfer)
func (*PeerConnection) SetUploadAddNextConnect ¶
func (p *PeerConnection) SetUploadAddNextConnect(v bool)
func (*PeerConnection) SetUploadQueueRank ¶
func (p *PeerConnection) SetUploadQueueRank(rank uint16)
func (*PeerConnection) SetUploadResource ¶
func (p *PeerConnection) SetUploadResource(res UploadableResource)
func (*PeerConnection) SetUploadStartTime ¶
func (p *PeerConnection) SetUploadStartTime(ts int64)
func (*PeerConnection) SetUploadState ¶
func (p *PeerConnection) SetUploadState(state UploadState)
func (*PeerConnection) SetUploadWaitStart ¶
func (p *PeerConnection) SetUploadWaitStart(ts int64)
func (*PeerConnection) Speed ¶
func (p *PeerConnection) Speed() PeerSpeed
func (*PeerConnection) UploadAddNextConnect ¶
func (p *PeerConnection) UploadAddNextConnect() bool
func (*PeerConnection) UploadQueueRank ¶
func (p *PeerConnection) UploadQueueRank() uint16
func (*PeerConnection) UploadScore ¶
func (p *PeerConnection) UploadScore() uint32
func (*PeerConnection) UploadSession ¶
func (p *PeerConnection) UploadSession() int64
func (*PeerConnection) UploadStartDelay ¶
func (p *PeerConnection) UploadStartDelay() int64
func (*PeerConnection) UploadState ¶
func (p *PeerConnection) UploadState() UploadState
func (*PeerConnection) UploadWaitStart ¶
func (p *PeerConnection) UploadWaitStart() int64
type PeerCredit ¶
type PeerCreditManager ¶
type PeerCreditManager struct {
// contains filtered or unexported fields
}
func NewPeerCreditManager ¶
func NewPeerCreditManager() *PeerCreditManager
func (*PeerCreditManager) AddDownloaded ¶
func (m *PeerCreditManager) AddDownloaded(hash protocol.Hash, bytes int64)
func (*PeerCreditManager) AddUploaded ¶
func (m *PeerCreditManager) AddUploaded(hash protocol.Hash, bytes int64)
func (*PeerCreditManager) ApplySnapshot ¶
func (m *PeerCreditManager) ApplySnapshot(states []ClientCreditState)
func (*PeerCreditManager) ScoreRatio ¶
func (m *PeerCreditManager) ScoreRatio(hash protocol.Hash) float64
func (*PeerCreditManager) Snapshot ¶
func (m *PeerCreditManager) Snapshot() []ClientCreditState
func (*PeerCreditManager) TotalsForPeer ¶ added in v0.0.2
func (m *PeerCreditManager) TotalsForPeer(hash protocol.Hash) (uploaded, downloaded uint64)
TotalsForPeer 返回与对端用户 Hash 关联的累计上传/下载字节(无记录时为 0)。
type PeerInfo ¶
type PeerInfo struct {
UserHash protocol.Hash
NickName string
Connected bool
TotalUploaded uint64
TotalDownloaded uint64
DownloadSpeed int
PayloadDownloadSpeed int
UploadSpeed int
PayloadUploadSpeed int
RemotePieces protocol.BitField
FailCount int
Endpoint protocol.Endpoint
ModName string
Version int
ModVersion int
StrModVersion string
SourceFlag int
// HelloMisc1 / HelloMisc2 为对端 Hello/HelloAnswer 标签 0xFA / 0xFE 解析后的原始数值(与 eMule Misc 位域一致)。
HelloMisc1 int
HelloMisc2 int
}
func (PeerInfo) SourceLabels ¶
func (PeerInfo) SourceString ¶
type PendingBlock ¶
type PendingBlock struct {
Block data.PieceBlock
DataSize int64
CreateTime int64
Received int64
Buffer []byte
}
func NewPendingBlock ¶
func NewPendingBlock(block data.PieceBlock, totalSize int64) PendingBlock
type PieceManager ¶
type PieceManager struct {
BlocksEnumerator
// contains filtered or unexported fields
}
func NewPieceManager ¶
func NewPieceManager(handler disk.FileHandler, pieceCount, blocksInLastPiece int) *PieceManager
func (*PieceManager) Abort ¶
func (p *PieceManager) Abort() [][]byte
func (*PieceManager) DeleteFile ¶
func (p *PieceManager) DeleteFile() error
func (*PieceManager) GetFile ¶
func (p *PieceManager) GetFile() *os.File
func (*PieceManager) ReleaseFile ¶
func (p *PieceManager) ReleaseFile(deleteFile bool) ([][]byte, error)
func (*PieceManager) RestoreBlock ¶
func (p *PieceManager) RestoreBlock(block data.PieceBlock, fileSize int64) ([][]byte, []byte, error)
func (*PieceManager) WriteBlock ¶
func (p *PieceManager) WriteBlock(block data.PieceBlock, buffer []byte) ([][]byte, error)
type PiecePicker ¶
type PiecePicker struct {
BlocksEnumerator
// contains filtered or unexported fields
}
func NewPiecePicker ¶
func NewPiecePicker(pieceCount, blocksInLastPiece int) PiecePicker
func (*PiecePicker) AbortDownload ¶
func (p *PiecePicker) AbortDownload(b data.PieceBlock, peer *Peer)
func (*PiecePicker) ChooseNextPiece ¶
func (p *PiecePicker) ChooseNextPiece() bool
func (*PiecePicker) ChooseNextPieceWithAvailability ¶
func (p *PiecePicker) ChooseNextPieceWithAvailability(available *protocol.BitField) bool
func (*PiecePicker) DownloadPiece ¶
func (p *PiecePicker) DownloadPiece(pieceIndex int)
func (*PiecePicker) GetDownloadingPiece ¶
func (p *PiecePicker) GetDownloadingPiece(index int) *DownloadingPiece
func (PiecePicker) GetDownloadingQueue ¶
func (p PiecePicker) GetDownloadingQueue() []DownloadingPiece
func (PiecePicker) GetPieceCount ¶
func (p PiecePicker) GetPieceCount() int
func (PiecePicker) HavePiece ¶
func (p PiecePicker) HavePiece(pieceIndex int) bool
func (*PiecePicker) IsBlockDownloaded ¶
func (p *PiecePicker) IsBlockDownloaded(b data.PieceBlock) bool
func (PiecePicker) IsEndGame ¶
func (p PiecePicker) IsEndGame() bool
func (PiecePicker) IsPieceFinished ¶
func (p PiecePicker) IsPieceFinished(pieceIndex int) bool
func (*PiecePicker) MarkAsDownloading ¶
func (p *PiecePicker) MarkAsDownloading(b data.PieceBlock, peer *Peer) bool
func (*PiecePicker) MarkAsFinished ¶
func (p *PiecePicker) MarkAsFinished(b data.PieceBlock) bool
func (*PiecePicker) MarkAsWriting ¶
func (p *PiecePicker) MarkAsWriting(b data.PieceBlock) bool
func (PiecePicker) NumDownloadingPieces ¶
func (p PiecePicker) NumDownloadingPieces() int
func (PiecePicker) NumHave ¶
func (p PiecePicker) NumHave() int
func (PiecePicker) NumPieces ¶
func (p PiecePicker) NumPieces() int
func (*PiecePicker) PickPieces ¶
func (p *PiecePicker) PickPieces(rq *[]data.PieceBlock, orderLength int, peer *Peer, speed PeerSpeed)
func (*PiecePicker) PickPiecesWithAvailability ¶
func (p *PiecePicker) PickPiecesWithAvailability(rq *[]data.PieceBlock, orderLength int, peer *Peer, speed PeerSpeed, available *protocol.BitField)
func (*PiecePicker) RestoreHave ¶
func (p *PiecePicker) RestoreHave(pieceIndex int)
func (*PiecePicker) RestorePiece ¶
func (p *PiecePicker) RestorePiece(pieceIndex int)
func (PiecePicker) TotalPieces ¶
func (p PiecePicker) TotalPieces() int
func (*PiecePicker) WeHave ¶
func (p *PiecePicker) WeHave(pieceIndex int)
func (*PiecePicker) WeHaveBlock ¶
func (p *PiecePicker) WeHaveBlock(b data.PieceBlock)
type PieceSnapshot ¶
type PieceSnapshotState ¶
type PieceSnapshotState string
const ( PieceSnapshotMissing PieceSnapshotState = "MISSING" PieceSnapshotDownloading PieceSnapshotState = "DOWNLOADING" PieceSnapshotFinished PieceSnapshotState = "FINISHED" )
type PieceState ¶
type PieceState byte
const ( PieceNone PieceState = iota PieceDownloading PieceHave )
type Policy ¶
type Policy struct {
// contains filtered or unexported fields
}
func (Policy) ComparePeerErase ¶
func (Policy) ComparePeers ¶
func (*Policy) ConnectionClosed ¶
func (p *Policy) ConnectionClosed(c *PeerConnection, sessionTime int64)
func (*Policy) ErasePeers ¶
func (p *Policy) ErasePeers()
func (*Policy) FindConnectCandidate ¶
func (Policy) GetSourceRank ¶
func (Policy) IsConnectCandidate ¶
func (Policy) IsEraseCandidate ¶
func (*Policy) MergeSourceExchangePeers ¶
MergeSourceExchangePeers 将来源交换得到的 Peer 合并进策略表(按 Endpoint 去重,重复时合并 SourceFlag)。
func (*Policy) NewConnection ¶
func (p *Policy) NewConnection(c *PeerConnection) error
func (Policy) NumConnectCandidates ¶
func (*Policy) PeersForSourceExchange ¶
PeersForSourceExchange 返回用于 OP_ANSWERSOURCES2 的候选来源:可连接、非 exclude 端点、限流。
func (*Policy) SetConnection ¶
func (p *Policy) SetConnection(peer *Peer, c *PeerConnection)
type RemotePeerInfo ¶
type RemotePeerInfo struct {
Point protocol.Endpoint
NickName string
ModName string
Version int
ModVersion string
ModNumber int
Misc1 MiscOptions
Misc2 MiscOptions2
}
type RequestedUploadBlock ¶
type SearchHandle ¶
type SearchHandle struct {
// contains filtered or unexported fields
}
func (SearchHandle) ID ¶
func (h SearchHandle) ID() uint32
func (SearchHandle) IsValid ¶
func (h SearchHandle) IsValid() bool
func (SearchHandle) Snapshot ¶
func (h SearchHandle) Snapshot() SearchSnapshot
func (SearchHandle) Stop ¶
func (h SearchHandle) Stop() error
type SearchParams ¶
type SearchResult ¶
type SearchResult struct {
Hash protocol.Hash
FileName string
FileSize int64
Sources int
CompleteSources int
MediaBitrate int
MediaLength int
MediaCodec string
Extension string
FileType string
Source SearchResultSource
}
func (SearchResult) ED2KLink ¶
func (r SearchResult) ED2KLink() string
type SearchResultSource ¶
type SearchResultSource uint8
const ( SearchResultServer SearchResultSource = 1 << iota SearchResultKAD )
type SearchScope ¶
type SearchScope uint8
const ( SearchScopeServer SearchScope = 1 << iota SearchScopeDHT SearchScopeAll = SearchScopeServer | SearchScopeDHT )
type SearchSnapshot ¶
type SearchSnapshot struct {
ID uint32
Params SearchParams
State SearchState
Results []SearchResult
UpdatedAt int64
StartedAt int64
ServerBusy bool
DHTBusy bool
KadKeyword string
Error string
}
type SearchState ¶
type SearchState string
const ( SearchStateIdle SearchState = "IDLE" SearchStateRunning SearchState = "RUNNING" SearchStateFinished SearchState = "FINISHED" SearchStateStopped SearchState = "STOPPED" SearchStateFailed SearchState = "FAILED" )
type ServerConnection ¶
type ServerConnection struct {
Connection
// contains filtered or unexported fields
}
func NewServerConnection ¶
func NewServerConnection(identifier string, address *net.TCPAddr, session *Session) *ServerConnection
func (*ServerConnection) AuxPort ¶
func (s *ServerConnection) AuxPort() int32
func (*ServerConnection) ClientID ¶
func (s *ServerConnection) ClientID() int32
func (*ServerConnection) Connect ¶
func (s *ServerConnection) Connect() error
func (*ServerConnection) Endpoint ¶
func (s *ServerConnection) Endpoint() protocol.Endpoint
func (*ServerConnection) GetAddress ¶
func (s *ServerConnection) GetAddress() *net.TCPAddr
func (*ServerConnection) GetIdentifier ¶
func (s *ServerConnection) GetIdentifier() string
func (*ServerConnection) IsHandshakeCompleted ¶
func (s *ServerConnection) IsHandshakeCompleted() bool
func (*ServerConnection) OnDisconnect ¶
func (s *ServerConnection) OnDisconnect(ec BaseErrorCode)
func (*ServerConnection) OnServerIDChange ¶
func (s *ServerConnection) OnServerIDChange(clientID, tcpFlags, auxPort int32)
func (*ServerConnection) ProcessIncoming ¶
func (s *ServerConnection) ProcessIncoming() error
func (*ServerConnection) SecondTick ¶
func (s *ServerConnection) SecondTick(currentSessionTime int64)
func (*ServerConnection) SendCallbackRequest ¶
func (s *ServerConnection) SendCallbackRequest(clientID int32)
func (*ServerConnection) SendFileSourcesRequest ¶
func (s *ServerConnection) SendFileSourcesRequest(hash protocol.Hash, size int64)
func (*ServerConnection) SendGetList ¶
func (s *ServerConnection) SendGetList()
func (*ServerConnection) SendLoginRequest ¶
func (s *ServerConnection) SendLoginRequest()
func (*ServerConnection) SendOfferFiles ¶
func (s *ServerConnection) SendOfferFiles(packet *serverproto.OfferFiles)
func (*ServerConnection) SendSearchMore ¶
func (s *ServerConnection) SendSearchMore()
func (*ServerConnection) SendSearchRequest ¶
func (s *ServerConnection) SendSearchRequest(packet *serverproto.SearchRequest)
func (*ServerConnection) TCPFlags ¶
func (s *ServerConnection) TCPFlags() int32
type ServerConnectionPolicy ¶
type ServerConnectionPolicy struct {
// contains filtered or unexported fields
}
func NewServerConnectionPolicy ¶
func NewServerConnectionPolicy(reconnectSecondsTimeout int64, maxReconnects int) ServerConnectionPolicy
func (ServerConnectionPolicy) GetConnectCandidate ¶
func (p ServerConnectionPolicy) GetConnectCandidate(currentSessionTime int64) *ServerConnectionCandidate
func (ServerConnectionPolicy) HasCandidate ¶
func (p ServerConnectionPolicy) HasCandidate() bool
func (ServerConnectionPolicy) HasIterations ¶
func (p ServerConnectionPolicy) HasIterations() bool
func (*ServerConnectionPolicy) RemoveConnectCandidates ¶
func (p *ServerConnectionPolicy) RemoveConnectCandidates()
func (*ServerConnectionPolicy) SetConnectCandidate ¶
func (p *ServerConnectionPolicy) SetConnectCandidate(identifier string, address *net.TCPAddr, currentSessionTime int64)
func (*ServerConnectionPolicy) SetServerConnectionFailed ¶
func (p *ServerConnectionPolicy) SetServerConnectionFailed(identifier string, address *net.TCPAddr, currentSessionTime int64)
type ServerSnapshot ¶
type ServerSnapshot struct {
Identifier string
Address string
Configured bool
Connected bool
HandshakeCompleted bool
Primary bool
Disconnecting bool
ClientID int32
TCPFlags int32
AuxPort int32
MillisecondsSinceLastReceive int64
DownloadRate int
UploadRate int
}
func (ServerSnapshot) IDClass ¶
func (s ServerSnapshot) IDClass() string
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
func NewSession ¶
func (*Session) AddSharedDir ¶
AddSharedDir 注册一个用于扫描的目录(去重)。
func (*Session) AddTransfer ¶
func (*Session) AddTransferParams ¶
func (s *Session) AddTransferParams(atp AddTransferParams) (TransferHandle, error)
func (*Session) AddTransferWithHandler ¶
func (s *Session) AddTransferWithHandler(hash protocol.Hash, size int64, handler disk.FileHandler) (TransferHandle, error)
func (*Session) CloseConnection ¶
func (s *Session) CloseConnection(connection *PeerConnection)
func (*Session) CloseListener ¶
func (s *Session) CloseListener()
func (*Session) ConfigureSession ¶
func (*Session) ConnectNewPeers ¶
func (s *Session) ConnectNewPeers()
func (*Session) ConnectedServerID ¶
func (*Session) ConnectedServerIDs ¶
func (*Session) Credits ¶
func (s *Session) Credits() *PeerCreditManager
func (*Session) DisconnectFrom ¶
func (s *Session) DisconnectFrom()
func (*Session) FindTransfer ¶
func (s *Session) FindTransfer(hash protocol.Hash) TransferHandle
func (*Session) GetAppVersion ¶
func (*Session) GetClientID ¶
func (*Session) GetClientName ¶
func (*Session) GetCompressionVersion ¶
func (*Session) GetCurrentTime ¶
func (*Session) GetDHTTracker ¶
func (s *Session) GetDHTTracker() *DHTTracker
func (*Session) GetListenPort ¶
func (*Session) GetModBuildVersion ¶
func (*Session) GetModMajorVersion ¶
func (*Session) GetModMinorVersion ¶
func (*Session) GetModName ¶
func (*Session) GetTransfers ¶
func (s *Session) GetTransfers() []TransferHandle
func (*Session) GetUDPPort ¶
func (*Session) GetUserAgent ¶
func (*Session) ImportSharedFile ¶
ImportSharedFile 计算 ed2k 哈希并将文件加入共享库。
func (*Session) ListSharedDirs ¶
ListSharedDirs 返回已注册的共享目录副本。
func (*Session) OnServerConnectionClosed ¶
func (s *Session) OnServerConnectionClosed(sc *ServerConnection, ec BaseErrorCode)
func (*Session) OnServerIDChange ¶
func (s *Session) OnServerIDChange(sc *ServerConnection, clientID, tcpFlags, auxPort int32)
func (*Session) OnServerSearchResult ¶
func (s *Session) OnServerSearchResult(sc *ServerConnection, result *serverproto.SearchResult)
func (*Session) PublishTransferToKAD ¶
PublishTransferToKAD 在任务已完成时向 KAD 发布文件源与(可选)关键字索引,需 EnableDHT 且已设置 DHTTracker。
func (*Session) PublishTransferToServer ¶
func (*Session) RefreshUPnPMapping ¶
func (s *Session) RefreshUPnPMapping()
func (*Session) RemoveDiskTask ¶
func (*Session) RemoveSharedDir ¶
RemoveSharedDir 移除扫描目录。
func (*Session) RemoveSharedFile ¶
RemoveSharedFile 从共享库移除指定哈希。
func (*Session) RemoveTransfer ¶
func (*Session) RequestSourcesNow ¶
func (*Session) RescanSharedDirs ¶
RescanSharedDirs 扫描已注册目录下的普通文件并导入。
func (*Session) SearchSnapshot ¶
func (s *Session) SearchSnapshot() SearchSnapshot
func (*Session) SecondTick ¶
func (*Session) SendDHTSourcesRequest ¶
func (*Session) SendSourcesRequest ¶
func (*Session) ServerSnapshots ¶
func (s *Session) ServerSnapshots() []ServerSnapshot
func (*Session) SetDHTTracker ¶
func (s *Session) SetDHTTracker(tracker *DHTTracker)
func (*Session) SharedFiles ¶
func (s *Session) SharedFiles() []*SharedFile
SharedFiles 返回共享文件快照(只读遍历)。
func (*Session) SharedStore ¶
func (s *Session) SharedStore() *SharedStore
SharedStore 返回会话级共享库(非 nil)。
func (*Session) StartSearch ¶
func (s *Session) StartSearch(params SearchParams) (SearchHandle, error)
func (*Session) StopSearch ¶
func (*Session) SubmitDiskTask ¶
func (s *Session) SubmitDiskTask(task TransferCallable)
func (*Session) SyncDHTListenPort ¶
func (s *Session) SyncDHTListenPort()
func (*Session) UploadQueue ¶
func (s *Session) UploadQueue() *UploadQueue
type Settings ¶
type Settings struct {
Logger *slog.Logger
UserAgent protocol.Hash
ModName string
ClientName string
ListenPort int
UDPPort int
EnableDHT bool
EnableUPnP bool
Version int
ModMajor int
ModMinor int
ModBuild int
MaxFailCount int
MaxPeerListSize int
MinPeerReconnectTime int
PeerConnectionTimeout int
SessionConnectionsLimit int
UploadSlots int
MaxUploadRateKB int
SlotAllocationKB int
UploadQueueSize int
BufferPoolSize int
MaxConnectionsPerSecond int
CompressionVersion int
ServerSearchTimeout int
DHTSearchTimeout int
ReconnectToServer bool
ServerPingTimeout int64
}
func NewSettings ¶
func NewSettings() Settings
type SharedFile ¶
type SharedFile struct {
}
SharedFile 表示可共享的文件资源元数据(与下载任务 Transfer 分离)。 FileSize 为字节大小(与 Transfer.Size() 对应,避免与 Size() 方法同名冲突)。
func (*SharedFile) AvailablePieces ¶
func (s *SharedFile) AvailablePieces() protocol.BitField
AvailablePieces 已完成文件视为拥有全部分片。
func (*SharedFile) CanUploadRange ¶
func (s *SharedFile) CanUploadRange(begin, end int64) bool
CanUploadRange 检查请求区间是否完全落在已拥有分片内。
func (*SharedFile) ReadRange ¶
func (s *SharedFile) ReadRange(begin, end int64) ([]byte, error)
ReadRange 从本地路径读取区间数据。
func (*SharedFile) UploadHashSet ¶
func (s *SharedFile) UploadHashSet() []protocol.Hash
UploadHashSet 返回分片哈希列表;与 Transfer 行为一致。
func (*SharedFile) UploadPriority ¶
func (s *SharedFile) UploadPriority() UploadPriority
UploadPriority 导入文件默认普通优先级。
type SharedStore ¶
type SharedStore struct {
// contains filtered or unexported fields
}
SharedStore 内存中的共享文件索引(按 hash 去重)。
func NewSharedStore ¶
func NewSharedStore() *SharedStore
func (*SharedStore) Add ¶
func (st *SharedStore) Add(f *SharedFile) bool
Add 添加共享文件;若 hash 已存在则返回 false 且不覆盖。
func (*SharedStore) Remove ¶
func (st *SharedStore) Remove(hash protocol.Hash) bool
Remove 按 hash 删除。
func (*SharedStore) ReplaceAll ¶
func (st *SharedStore) ReplaceAll(files []*SharedFile)
ReplaceAll 用快照替换整个存储(用于从磁盘恢复)。
type SpeedMonitor ¶
type SpeedMonitor struct {
// contains filtered or unexported fields
}
func NewSpeedMonitor ¶
func NewSpeedMonitor(samplesLimit int) SpeedMonitor
func (*SpeedMonitor) AddSample ¶
func (s *SpeedMonitor) AddSample(speedSample int64)
func (SpeedMonitor) AverageSpeed ¶
func (s SpeedMonitor) AverageSpeed() int64
func (*SpeedMonitor) Clear ¶
func (s *SpeedMonitor) Clear()
func (SpeedMonitor) NumSamples ¶
func (s SpeedMonitor) NumSamples() int
type StatChannel ¶
type StatChannel struct {
// contains filtered or unexported fields
}
func NewStatChannel ¶
func NewStatChannel() StatChannel
func (*StatChannel) Add ¶
func (s *StatChannel) Add(count int64)
func (*StatChannel) AddChannel ¶
func (s *StatChannel) AddChannel(other StatChannel)
func (*StatChannel) Clear ¶
func (s *StatChannel) Clear()
func (*StatChannel) Counter ¶
func (s *StatChannel) Counter() int64
func (*StatChannel) LowPassRate ¶
func (s *StatChannel) LowPassRate() int64
func (*StatChannel) MergeChannel ¶
func (s *StatChannel) MergeChannel(other StatChannel)
func (*StatChannel) Rate ¶
func (s *StatChannel) Rate() int64
func (*StatChannel) SecondTick ¶
func (s *StatChannel) SecondTick(timeIntervalMS int64)
func (*StatChannel) Total ¶
func (s *StatChannel) Total() int64
type Statistics ¶
type Statistics struct {
// contains filtered or unexported fields
}
func NewStatistics ¶
func NewStatistics() Statistics
func (*Statistics) Add ¶
func (s *Statistics) Add(other Statistics) *Statistics
func (*Statistics) Clear ¶
func (s *Statistics) Clear()
func (Statistics) DownloadPayloadRate ¶
func (s Statistics) DownloadPayloadRate() int64
func (Statistics) DownloadRate ¶
func (s Statistics) DownloadRate() int64
func (Statistics) LastDownload ¶
func (s Statistics) LastDownload() int64
func (Statistics) LastUpload ¶
func (s Statistics) LastUpload() int64
func (Statistics) LowPassDownloadRate ¶
func (s Statistics) LowPassDownloadRate() int64
func (Statistics) LowPassUploadRate ¶
func (s Statistics) LowPassUploadRate() int64
func (*Statistics) Merge ¶
func (s *Statistics) Merge(other Statistics) *Statistics
func (*Statistics) ReceiveBytes ¶
func (s *Statistics) ReceiveBytes(protocolBytes, payloadBytes int64)
func (*Statistics) SecondTick ¶
func (s *Statistics) SecondTick(timeIntervalMS int64)
func (*Statistics) SendBytes ¶
func (s *Statistics) SendBytes(protocolBytes, payloadBytes int64)
func (Statistics) TotalPayloadDownload ¶
func (s Statistics) TotalPayloadDownload() int64
func (Statistics) TotalPayloadUpload ¶
func (s Statistics) TotalPayloadUpload() int64
func (Statistics) TotalProtocolDownload ¶
func (s Statistics) TotalProtocolDownload() int64
func (Statistics) TotalProtocolUpload ¶
func (s Statistics) TotalProtocolUpload() int64
func (Statistics) TotalUpload ¶
func (s Statistics) TotalUpload() int64
func (Statistics) UploadPayloadRate ¶
func (s Statistics) UploadPayloadRate() int64
func (Statistics) UploadRate ¶
func (s Statistics) UploadRate() int64
type Transfer ¶
type Transfer struct {
// contains filtered or unexported fields
}
func NewTransfer ¶
func NewTransfer(s *Session, atp AddTransferParams) (*Transfer, error)
func (*Transfer) ActiveConnections ¶
func (*Transfer) AddPeerFromKADV6Search ¶
func (t *Transfer) AddPeerFromKADV6Search(entry kadv6.SearchEntry) (bool, error)
AddPeerFromKADV6Search 将单条 KADV6 搜索结果并入当前任务策略表(去重规则同 AddPeer)。
func (*Transfer) AddStats ¶
func (t *Transfer) AddStats(s Statistics)
func (*Transfer) AsyncRestoreBlock ¶
func (t *Transfer) AsyncRestoreBlock(block data.PieceBlock)
func (*Transfer) AttachIncomingPeer ¶
func (t *Transfer) AttachIncomingPeer(c *PeerConnection) error
func (*Transfer) AttachPeer ¶
func (t *Transfer) AttachPeer(c *PeerConnection) error
func (*Transfer) AvailablePieces ¶
func (*Transfer) CanUploadRange ¶
func (*Transfer) ConnectToPeer ¶
func (t *Transfer) ConnectToPeer(peerInfo *Peer) (*PeerConnection, error)
func (*Transfer) ForceSourceDiscoveryNow ¶
func (t *Transfer) ForceSourceDiscoveryNow()
func (*Transfer) GetCreateTime ¶
func (*Transfer) GetFilePath ¶
func (*Transfer) GetPeersInfo ¶
func (*Transfer) GetPieceManager ¶
func (t *Transfer) GetPieceManager() *PieceManager
func (*Transfer) GetStatus ¶
func (t *Transfer) GetStatus() TransferStatus
func (*Transfer) IsFinished ¶
func (*Transfer) NeedMoreSources ¶
func (*Transfer) NeedResumeDataSave ¶
func (*Transfer) OnBlockRestoreCompleted ¶
func (t *Transfer) OnBlockRestoreCompleted(block data.PieceBlock, ec BaseErrorCode)
func (*Transfer) OnBlockWriteCompleted ¶
func (t *Transfer) OnBlockWriteCompleted(block data.PieceBlock, _ [][]byte, ec BaseErrorCode)
func (*Transfer) OnPieceHashCompleted ¶
func (*Transfer) OnReleaseFile ¶
func (t *Transfer) OnReleaseFile(_ BaseErrorCode, _ [][]byte, _ bool)
func (*Transfer) PauseWithDisconnect ¶
func (t *Transfer) PauseWithDisconnect()
func (*Transfer) PieceSnapshots ¶
func (t *Transfer) PieceSnapshots() []PieceSnapshot
func (*Transfer) QueuePieceHash ¶
func (*Transfer) RemovePeerConnection ¶
func (t *Transfer) RemovePeerConnection(c *PeerConnection)
func (*Transfer) ResumeData ¶
func (t *Transfer) ResumeData() *protocol.TransferResumeData
func (*Transfer) ResumeWithState ¶
func (t *Transfer) ResumeWithState()
func (*Transfer) SecondTick ¶
func (t *Transfer) SecondTick(accumulator *Statistics, tickIntervalMS int64)
func (*Transfer) SetHashSet ¶
func (*Transfer) SetUploadPriority ¶
func (t *Transfer) SetUploadPriority(priority UploadPriority)
func (*Transfer) TryConnectPeer ¶
func (*Transfer) UploadHashSet ¶
func (*Transfer) UploadPriority ¶
func (t *Transfer) UploadPriority() UploadPriority
func (*Transfer) WantMorePeers ¶
type TransferCallable ¶
type TransferCallable interface {
Transfer() *Transfer
Call() AsyncOperationResult
}
type TransferHandle ¶
type TransferHandle struct {
// contains filtered or unexported fields
}
func NewTransferHandle ¶
func NewTransferHandle(s *Session) TransferHandle
func NewTransferHandleWithTransfer ¶
func NewTransferHandleWithTransfer(s *Session, t *Transfer) TransferHandle
func (TransferHandle) ActiveConnections ¶
func (h TransferHandle) ActiveConnections() int
func (TransferHandle) GetCreateTime ¶
func (h TransferHandle) GetCreateTime() int64
func (TransferHandle) GetFile ¶
func (h TransferHandle) GetFile() *os.File
func (TransferHandle) GetFilePath ¶
func (h TransferHandle) GetFilePath() string
func (TransferHandle) GetHash ¶
func (h TransferHandle) GetHash() protocol.Hash
func (TransferHandle) GetPeersInfo ¶
func (h TransferHandle) GetPeersInfo() []PeerInfo
func (TransferHandle) GetResumeData ¶
func (h TransferHandle) GetResumeData() *protocol.TransferResumeData
func (TransferHandle) GetSize ¶
func (h TransferHandle) GetSize() int64
func (TransferHandle) GetStatus ¶
func (h TransferHandle) GetStatus() TransferStatus
func (TransferHandle) IsFinished ¶
func (h TransferHandle) IsFinished() bool
func (TransferHandle) IsPaused ¶
func (h TransferHandle) IsPaused() bool
func (TransferHandle) IsResumed ¶
func (h TransferHandle) IsResumed() bool
func (TransferHandle) IsValid ¶
func (h TransferHandle) IsValid() bool
func (TransferHandle) NeedResumeDataSave ¶
func (h TransferHandle) NeedResumeDataSave() bool
func (TransferHandle) Pause ¶
func (h TransferHandle) Pause()
func (TransferHandle) PieceSnapshots ¶
func (h TransferHandle) PieceSnapshots() []PieceSnapshot
func (TransferHandle) Resume ¶
func (h TransferHandle) Resume()
type TransferProgressEvent ¶
type TransferProgressEvent struct {
At time.Time
Transfers []TransferProgressSnapshot
}
TransferProgressEvent contains only transfers whose progress/state changed.
type TransferProgressSnapshot ¶
type TransferProgressSnapshot struct {
Hash protocol.Hash
FileName string
FilePath string
State TransferState
Paused bool
Removed bool
TotalDone int64
TotalReceived int64
TotalWanted int64
DownloadingPieces int
ActivePeers int
NumPeers int
}
TransferProgressSnapshot is a lightweight per-transfer progress snapshot.
type TransferSnapshot ¶
type TransferSnapshot struct {
Hash protocol.Hash
FileName string
FilePath string
CreateTime int64
Size int64
ActivePeers int
Status TransferStatus
Peers []PeerInfo
Pieces []PieceSnapshot
}
func (TransferSnapshot) ED2KLink ¶
func (t TransferSnapshot) ED2KLink() string
type TransferState ¶
type TransferState string
const ( LoadingResumeData TransferState = "LOADING_RESUME_DATA" Downloading TransferState = "DOWNLOADING" PausedState TransferState = "PAUSED" Verifying TransferState = "VERIFYING" Finished TransferState = "FINISHED" )
type TransferStatus ¶
type TransferStatus struct {
Paused bool
DownloadRate int
Upload int64
UploadRate int
NumPeers int
DownloadingPieces int
TotalDone int64
TotalReceived int64
TotalWanted int64
ETA int64
Pieces protocol.BitField
NumPieces int
State TransferState
}
func (TransferStatus) String ¶
func (s TransferStatus) String() string
type UploadPriority ¶
type UploadPriority int
const ( UploadPriorityVeryLow UploadPriority = iota UploadPriorityLow UploadPriorityNormal UploadPriorityHigh UploadPriorityVeryHigh )
func (UploadPriority) ScoreFactor ¶
func (p UploadPriority) ScoreFactor() float64
type UploadQueue ¶
type UploadQueue struct {
// contains filtered or unexported fields
}
func NewUploadQueue ¶
func NewUploadQueue(session *Session) *UploadQueue
func (*UploadQueue) AddClientToQueue ¶
func (q *UploadQueue) AddClientToQueue(client *PeerConnection)
func (*UploadQueue) CheckForTimeOver ¶
func (q *UploadQueue) CheckForTimeOver(client *PeerConnection) bool
func (*UploadQueue) IsOnUploadQueue ¶
func (q *UploadQueue) IsOnUploadQueue(client *PeerConnection) bool
func (*UploadQueue) IsUploading ¶
func (q *UploadQueue) IsUploading(client *PeerConnection) bool
func (*UploadQueue) Process ¶
func (q *UploadQueue) Process()
func (*UploadQueue) RemoveFromUploadQueue ¶
func (q *UploadQueue) RemoveFromUploadQueue(client *PeerConnection) bool
func (*UploadQueue) RemoveFromWaitingQueue ¶
func (q *UploadQueue) RemoveFromWaitingQueue(client *PeerConnection) bool
func (*UploadQueue) ResumeUpload ¶
func (q *UploadQueue) ResumeUpload(hash protocol.Hash)
func (*UploadQueue) SuspendUpload ¶
func (q *UploadQueue) SuspendUpload(hash protocol.Hash, terminate bool) uint16
type UploadState ¶
type UploadState int
const ( UploadStateNone UploadState = iota UploadStateOnQueue UploadStateUploading UploadStateConnecting )
type UploadableResource ¶
type UploadableResource interface {
GetHash() protocol.Hash
FileLabel() string
Size() int64
UploadPriority() UploadPriority
AvailablePieces() protocol.BitField
UploadHashSet() []protocol.Hash
CanUpload() bool
CanUploadRange(begin, end int64) bool
ReadRange(begin, end int64) ([]byte, error)
}
UploadableResource 上传所需的最小能力(Transfer 与 SharedFile 均实现)。
Source Files
¶
- add_transfer_params.go
- async_disk.go
- block_manager.go
- blocks_enumerator.go
- client.go
- client_credits.go
- client_listener.go
- client_progress_listener.go
- client_shared.go
- client_state.go
- client_status.go
- connection.go
- constants.go
- dht_status.go
- dht_tracker.go
- doc.go
- downloading_piece.go
- ed2k_file_hash.go
- emule_link.go
- error.go
- error_code.go
- kad_node.go
- kad_routing.go
- kad_rpc.go
- kad_traversal.go
- peer.go
- peer_connection.go
- peer_info.go
- peer_kadv6.go
- piece_manager.go
- piece_picker.go
- piece_snapshot.go
- policy.go
- policy_source_exchange.go
- search.go
- server_connection.go
- server_connection_policy.go
- session.go
- session_kad_publish.go
- session_shared.go
- settings.go
- shared_file.go
- shared_import.go
- shared_publish.go
- shared_store.go
- speed_monitor.go
- stat_channel.go
- statistics.go
- time.go
- transfer.go
- transfer_handle.go
- transfer_status.go
- upload_priority.go
- upload_queue.go
- uploadable.go
- upnp.go
- util.go
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
goed2k
command
|
|
|
examples
|
|
|
basic
command
|
|
|
multi
command
|
|
|
state_store
command
|
|
|
status
command
|
|
|
internal
|
|
|
upnp
Package upnp implements UPnP InternetGatewayDevice discovery, querying, and port mapping.
|
Package upnp implements UPnP InternetGatewayDevice discovery, querying, and port mapping. |
