Documentation
¶
Overview ¶
Package dht implements the bittorrent dht protocol. For more information see http://www.bittorrent.org/beps/bep_0005.html.
Index ¶
- Constants
- func Decode(data []byte) (result interface{}, err error)
- func DecodeDict(data []byte, start int) (result interface{}, index int, err error)
- func DecodeInt(data []byte, start int) (result interface{}, index int, err error)
- func DecodeList(data []byte, start int) (result interface{}, index int, err error)
- func DecodeString(data []byte, start int) (result interface{}, index int, err error)
- func Encode(data interface{}) string
- func EncodeDict(data map[string]interface{}) string
- func EncodeInt(data int) string
- func EncodeList(data []interface{}) string
- func EncodeString(data string) string
- type Config
- type DHT
- type Peer
- type Request
- type Response
- type Wire
Constants ¶
const ( // StandardMode follows the standard protocol StandardMode = iota // CrawlMode for crawling the dht network. CrawlMode )
const ( // REQUEST represents request message type REQUEST = iota // DATA represents data message type DATA // REJECT represents reject message type REJECT )
const ( // BLOCK is 2 ^ 14 BLOCK = 16384 // MaxMetadataSize represents the max medata it can accept MaxMetadataSize = BLOCK * 1000 // EXTENDED represents it is a extended message EXTENDED = 20 // HANDSHAKE represents handshake bit HANDSHAKE = 0 )
Variables ¶
This section is empty.
Functions ¶
func DecodeDict ¶
DecodeDict decodes a map value.
func DecodeList ¶
DecodeList decodes a list value.
func DecodeString ¶
DecodeString decodes a string in the data. It returns a tuple (decoded result, the end position, error).
func Encode ¶
func Encode(data interface{}) string
Encode encodes a string, int, dict or list value to a bencoded string.
func EncodeDict ¶
EncodeDict encodes a dict value.
Types ¶
type Config ¶
type Config struct {
K int
KBucketSize int
Network string
Address string
PrimeNodes []string
KBucketExpiredAfter time.Duration
NodeExpriedAfter time.Duration
CheckKBucketPeriod time.Duration
TokenExpiredAfter time.Duration
MaxTransactionCursor uint64
MaxNodes int
OnGetPeers func(string, string, int)
OnAnnouncePeer func(string, string, int)
BlockedIPs []string
BlackListMaxSize int
Mode int
Try int
}
Config represents the configure of dht.
func NewCrawlConfig ¶
func NewCrawlConfig() *Config
NewCrawlConfig returns a config in crawling mode.
func NewStandardConfig ¶
func NewStandardConfig() *Config
NewStandardConfig returns a Config pointer with default values.
type DHT ¶
DHT represents a DHT node.
func New ¶
New returns a DHT pointer. If config is nil, then config will be set to the default config.
func (*DHT) IsCrawlMode ¶
IsCrawlMode returns whether mode is CrawlMode.
func (*DHT) IsStandardMode ¶
IsStandardMode returns whether mode is StandardMode.
type Peer ¶
Peer represents a peer contact.
func (*Peer) CompactIPPortInfo ¶
CompactIPPortInfo returns "Compact node info". See http://www.bittorrent.org/beps/bep_0005.html.
