/godht

A very simple and fast DHT crawler in Golang.

Primary LanguageGoMIT LicenseMIT

godht

A very simple and fast DHT crawler in Golang.

Install

go get github.com/imajeason/godht

Usage

package main

import (
	"fmt"

	"github.com/imajeason/godht"
)

func main() {
	laddr, maxFriendsPerSec := "0.0.0.0:6331", 500
	dht, err := godht.New(laddr, godht.MaxFriendsPerSec(maxFriendsPerSec))
	if err != nil {
		panic(err)
	}
	for announce := range dht.Announce {
		fmt.Println(fmt.Sprintf("link: magnet:?xt=urn:btih:%v\nnode: %s\npeer: %s\n",
			announce.InfohashHex,
			announce.From.String(),
			announce.Peer.String(),
		))
	}
}

API

func Bootstraps

func Bootstraps(addr []string) option

func LocalID

func LocalID(id []byte) option

func MaxFriendsPerSec

func MaxFriendsPerSec(n int) option

func Secret

func Secret(s string) option

type Announce

type Announce struct {
	Raw         map[string]interface{}
	From        *net.UDPAddr
	Peer        *net.TCPAddr
	Infohash    []byte
	InfohashHex string
}

type GoDHT

type GoDHT struct {
	Announce chan *Announce
}

func New

func New(laddr string, options ...option) (*GoDHT, error)