package module
Version: v0.0.0-...-01918fd Latest Latest

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

Go to latest
Published: Oct 20, 2016 License: GPL-3.0 Imports: 20 Imported by: 0



a dht network crawler



http://www.bittorrent.org/beps/bep_0009.html http://www.bittorrent.org/beps/bep_0010.html



View Source
const (
	// REQUEST represents request message type
	REQUEST = iota
	// DATA represents data message type
	// REJECT represents reject message type
View Source
const (
	// BLOCK is 2 ^ 14
	// The metadata is handled in blocks of 16KiB (16384 Bytes). The metadata blocks are indexed starting at 0. All blocks are 16KiB except the last block which may be smaller.
	BLOCK = 16384
	// MaxMetadataSize represents the max medata it can accept
	MaxMetadataSize = BLOCK * 1000
	// EXTENDED represents it is a extended message
	// HANDSHAKE represents handshake bit


This section is empty.


func Atoi64

func Atoi64(b []byte) uint64

Atoi64 converts bytes to integer

func Decode

func Decode(data []byte, v interface{}) error

Decode reads the Becode-encoded text from data,stores in the value pointed to by v

func Encode

func Encode(data interface{}) (string, error)

Encode returns the Becode encoding text of data.

func ErrStr

func ErrStr(e error) string

ErrStr returns error's string or "nil"

func GetProcAbsDir

func GetProcAbsDir() (string, error)

GetProcAbsDir returns the current process's folder path

func GetRandString

func GetRandString(size int) string

GetRandString returns a size length random string

func I64toA

func I64toA(i uint64) []byte

I64toA converts integer to bytes


type Config

type Config struct {
	// the size of nodes in response
	K int

Config defines the configuration of a dht listener.

type DHT

type DHT struct {
	K int

	Try           int
	EntranceAddrs []string

	OnGetPeers     func(string, string, int)
	OnAnnouncePeer func(string, string, int)
	// contains filtered or unexported fields

func NewDht

func NewDht(addr string) *DHT

func (*DHT) GetPeers

func (dht *DHT) GetPeers(infoHash string) ([]*Peer, error)

func (*DHT) Run

func (dht *DHT) Run()

type Peer

type Peer struct {
	IP   net.IP
	Port int
	// contains filtered or unexported fields

Peer represents a peer contact.

func (*Peer) CompactIPPortInfo

func (p *Peer) CompactIPPortInfo() string

CompactIPPortInfo returns "Compact node info". See http://www.bittorrent.org/beps/bep_0005.html.

type Request

type Request struct {
	InfoHash []byte
	IP       string
	Port     int

Request represents the request context.

type Response

type Response struct {
	MetadataInfo []byte

Response contains the request context and the metadata info.

type Wire

type Wire struct {
	// contains filtered or unexported fields

Wire represents the wire protocol.

func NewWire

func NewWire(requestQueueSize, workerQueueSize int) *Wire

NewWire returns a Wire pointer.

- requestQueueSize: the max requests it can buffers
- workerQueueSize: the max goroutine downloading workers

func (*Wire) Request

func (wire *Wire) Request(infoHash []byte, ip string, port int)

Request pushes the request to the queue.

func (*Wire) Response

func (wire *Wire) Response() <-chan Response

Response returns a chan of Response.

func (*Wire) Run

func (wire *Wire) Run()

Run starts the peer wire protocol.


Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL