kademila

package
v0.0.0-...-0f45eb8 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2021 License: GPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	INIT         = iota
	GOOD         = iota
	QUESTIONABLE = iota
	BAD          = iota
)
View Source
const (
	Running  = iota
	Suspend  = iota
	Finished = iota
)
View Source
const APPNAME = "DHTRobot"
View Source
const BucketLastChangedTimeLimit = 15 // minutes
View Source
const FindNodeTimeLimit = 120 // seconds
View Source
const FinderNum = 2
View Source
const K int = 8

Bucket size

View Source
const MAXSIZE = 2048
View Source
const MaxBitsLength = 160
View Source
const MaxUnchangedCount = 5000
View Source
const NodeRefreshnessTimeLimit = 60 // seconds
View Source
const PingNodeTimeLimit = 30 // seconds
View Source
const RequestTimeout = 10 // seconds
View Source
const TokenTimeLimit = 300 // seconds
View Source
const UndefinedWorker = -1
View Source
const VERSION = "0.1.0"

Variables

View Source
var BOOTSTRAP = []string{
	"router.bittorrent.com:6881",
	"dht.transmissionbt.com:6881",
	"service.ygrek.org.ua:6881",
	"router.utorrent.com:6881",
	"router.transmission.com:6881",
}

Bootstrap nodes

View Source
var ErrorDefinitions = map[int]string{
	GenericError:  "Generic Error",
	ServerError:   "Server Error",
	ProtocolError: "Protocol Error",
	MethodUnknown: "Method Unknown",
}
View Source
var FilteredClients = map[string]bool{
	"LT(0.17)": true,
}
View Source
var GenericError = 201
View Source
var MethodUnknown = 204
View Source
var ProtocolError = 203
View Source
var ServerError = 202

Functions

func BitsInByte

func BitsInByte(b byte) int

func ConvertNodeToBytes

func ConvertNodeToBytes(nodes []Node) []byte

func ConvertPeerToBytes

func ConvertPeerToBytes(peers []*Peer) []string

func Distance

func Distance(src, dst NodeID) int

func GNUAddHistory

func GNUAddHistory(line string)

func GNUReadLine

func GNUReadLine(prompt string) (string, bool)

func GoReadLine

func GoReadLine(prompt string) (string, bool)

func KRPCEncode

func KRPCEncode(m *Message) (string, error)

func KRPCEncodeAnnouncePeer

func KRPCEncodeAnnouncePeer(tid string, local string, infoHash string, port int, token string, impliedPort bool) (string, error)

func KRPCEncodeAnnouncePeerResponse

func KRPCEncodeAnnouncePeerResponse(tid string, local string) (string, error)

func KRPCEncodeError

func KRPCEncodeError(tid string, code int, desc string) (string, error)

func KRPCEncodeFindNode

func KRPCEncodeFindNode(tid string, local string, target string) (string, error)

func KRPCEncodeFindNodeResponse

func KRPCEncodeFindNodeResponse(tid string, local string, nodes []Node) (string, error)

func KRPCEncodeGetPeers

func KRPCEncodeGetPeers(tid string, local string, infoHash string) (string, error)

func KRPCEncodeGetPeersResponse

func KRPCEncodeGetPeersResponse(tid string, local string, token string, nodes []Node, values []*Peer) (string, error)

func KRPCEncodePing

func KRPCEncodePing(tid string, local string) (string, error)

func KRPCEncodePingResponse

func KRPCEncodePingResponse(tid string, local string) (string, error)

func KRPCValidate

func KRPCValidate(data []byte) bool

func RunClient

func RunClient(ctx context.Context, master chan string, logger *logrus.Logger)

Types

type AnnouncePeerQuery

type AnnouncePeerQuery struct {
	ID          string
	ImpliedPort bool
	InfoHash    string
	Port        int
	Token       string
}

func (*AnnouncePeerQuery) String

func (q *AnnouncePeerQuery) String() string

type AnnouncePeerResponse

type AnnouncePeerResponse struct {
	ID string
}

func (*AnnouncePeerResponse) String

func (r *AnnouncePeerResponse) String() string

type DecodeError

type DecodeError struct {
	What string
}

func (DecodeError) Error

func (e DecodeError) Error() string

type EncodeError

type EncodeError struct {
	What string
}

func (EncodeError) Error

func (e EncodeError) Error() string

type Err

type Err struct {
	Code int
	Desc string
}

func (*Err) String

func (e *Err) String() string

type FindNodeQuery

type FindNodeQuery struct {
	ID     string
	Target string
}

func (*FindNodeQuery) String

func (q *FindNodeQuery) String() string

type FindNodeResponse

type FindNodeResponse struct {
	ID    string
	Nodes []Node
}

func (*FindNodeResponse) String

func (r *FindNodeResponse) String() string

type GetPeersQuery

type GetPeersQuery struct {
	ID       string
	InfoHash string
}

func (*GetPeersQuery) String

func (q *GetPeersQuery) String() string

type GetPeersResponse

type GetPeersResponse struct {
	ID     string
	Token  string
	Values []*Peer
	Nodes  []Node
}

func (*GetPeersResponse) String

func (r *GetPeersResponse) String() string

type Kademila

type Kademila struct {
	Chan chan string
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, master chan string, logger *logrus.Logger) (*Kademila, error)

func Restore

func Restore(master chan string, id NodeID, routing []byte) *Kademila

func (*Kademila) AnnouncePeers

func (k *Kademila) AnnouncePeers(impliedPort bool, infoHash string, port int, token string)

func (*Kademila) Close

func (k *Kademila) Close()

func (*Kademila) GetPeers

func (k *Kademila) GetPeers(infoHash string)

type Message

type Message struct {
	N Node
	//The transaction ID should be encoded as a short string of binary numbers,
	//typically 2 characters are enough as they cover 2^16 outstanding queries.
	T string
	//Every message also has a key "y" with a single character value describing the type of message. [q|r|e]
	Y string
	//The string should be a two character client identifier registered in BEP 20 [3] followed by a two character version identifier.
	//Not all implementations include a "v" key so clients should not assume its presence.
	V string
	Q string
	W int
	A interface{}
}

func KRPCDecode

func KRPCDecode(raw *RawData) (*Message, error)

func KRPCNewAnnouncePeer

func KRPCNewAnnouncePeer(local NodeID, infoHash string, port int, token string, impliedPort bool, worker int) *Message

func KRPCNewAnnouncePeerResponse

func KRPCNewAnnouncePeerResponse(tid string, local NodeID) *Message

func KRPCNewError

func KRPCNewError(tid string, q string, code int) *Message

func KRPCNewFindNode

func KRPCNewFindNode(local NodeID, target NodeID, worker int) *Message

func KRPCNewFindNodeResponse

func KRPCNewFindNodeResponse(tid string, local NodeID, nodes []Node) *Message

func KRPCNewGetPeers

func KRPCNewGetPeers(local NodeID, infoHash NodeID, worker int) *Message

func KRPCNewGetPeersResponse

func KRPCNewGetPeersResponse(tid string, local NodeID, token string, nodes []Node, values []*Peer) *Message

func KRPCNewPing

func KRPCNewPing(local NodeID, worker int) *Message

func KRPCNewPingResponse

func KRPCNewPingResponse(tid string, local NodeID) *Message

func (*Message) String

func (m *Message) String() string

type Node

type Node struct {
	ID       NodeID
	Addr     net.Addr
	Status   uint8
	LastSeen time.Time
}

func ParseNodes

func ParseNodes(sn string) []Node

func (*Node) Clone

func (node *Node) Clone() *Node

func (Node) IP

func (node Node) IP() []byte

func (Node) Port

func (node Node) Port() int

func (Node) SStatus

func (node Node) SStatus() string

func (Node) String

func (node Node) String() string

type NodeContext

type NodeContext struct {
	Local    Node
	Log      *logrus.Logger
	Conn     net.PacketConn
	Master   chan string
	Outgoing chan *Message
	Incoming chan RawData
	Writer   io.Writer
	// contains filtered or unexported fields
}

func FromContext

func FromContext(ctx context.Context) (*NodeContext, bool)

type NodeID

type NodeID []byte

func GenerateID

func GenerateID() NodeID

func HexToID

func HexToID(hex string) NodeID

func (NodeID) Distance

func (id NodeID) Distance(dst NodeID) int

func (NodeID) HexString

func (id NodeID) HexString() string

func (NodeID) Int

func (id NodeID) Int() *big.Int

func (NodeID) String

func (id NodeID) String() string

type ParseError

type ParseError struct {
	What string
}

func (ParseError) Error

func (e ParseError) Error() string

type Peer

type Peer struct {
	Port int
	IP   net.IP
}

func ParsePeers

func ParsePeers(peers []string) ([]*Peer, error)

func (Peer) String

func (peer Peer) String() string

type PingQuery

type PingQuery struct {
	ID string
}

func (*PingQuery) String

func (q *PingQuery) String() string

type PingResponse

type PingResponse struct {
	ID string
}

func (*PingResponse) String

func (r *PingResponse) String() string

type RawData

type RawData struct {
	Addr net.Addr
	Data []byte
}

type TokenBuilder

type TokenBuilder struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL