dht

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2016 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectIP

func DetectIP() string

Types

type DHTClient

type DHTClient struct {
	Routers          string
	FailedRouters    []string
	Connection       []*net.UDPConn
	NetworkHash      string
	NetworkPeers     []string
	P2PPort          int
	LastCatch        []string
	ID               string
	Peers            []PeerIP
	Forwarders       []Forwarder
	ResponseHandlers map[string]DHTResponseCallback
	Mode             OperatingMode
	Shutdown         bool
}

func (*DHTClient) AddConnection

func (dht *DHTClient) AddConnection(connections []*net.UDPConn, conn *net.UDPConn) []*net.UDPConn

AddConnection adds new UDP Connection reference onto list of DHT node connections

func (*DHTClient) Compose

func (dht *DHTClient) Compose(command, id, hash string, port string) string

Returns a bencoded representation of a DHTRequest

func (*DHTClient) ConnectAndHandshake

func (dht *DHTClient) ConnectAndHandshake(router string, ips []net.IP) (*net.UDPConn, error)

ConnectAndHandshake sends an initial packet to a DHT bootstrap node

func (*DHTClient) DHTClientConfig

func (dht *DHTClient) DHTClientConfig() *DHTClient

func (*DHTClient) EncodeRequest

func (dht *DHTClient) EncodeRequest(req commons.DHTRequest) string

func (*DHTClient) Extract

func (dht *DHTClient) Extract(b []byte) (response commons.DHTResponse, err error)

Extracts DHTRequest from received packet

func (*DHTClient) HandleConn

func (dht *DHTClient) HandleConn(data commons.DHTResponse, conn *net.UDPConn)

func (*DHTClient) HandleCp

func (dht *DHTClient) HandleCp(data commons.DHTResponse, conn *net.UDPConn)

func (*DHTClient) HandleFind

func (dht *DHTClient) HandleFind(data commons.DHTResponse, conn *net.UDPConn)

func (*DHTClient) HandleNode

func (dht *DHTClient) HandleNode(data commons.DHTResponse, conn *net.UDPConn)

func (*DHTClient) HandleNotify

func (dht *DHTClient) HandleNotify(data commons.DHTResponse, conn *net.UDPConn)

func (*DHTClient) HandlePing

func (dht *DHTClient) HandlePing(data commons.DHTResponse, conn *net.UDPConn)

func (*DHTClient) HandleRegCp

func (dht *DHTClient) HandleRegCp(data commons.DHTResponse, conn *net.UDPConn)

func (*DHTClient) HandleStop

func (dht *DHTClient) HandleStop(data commons.DHTResponse, conn *net.UDPConn)

func (*DHTClient) Initialize

func (dht *DHTClient) Initialize(config *DHTClient, ips []net.IP) *DHTClient

This method initializes DHT by splitting list of routers and connect to each one

func (*DHTClient) ListenDHT

func (dht *DHTClient) ListenDHT(conn *net.UDPConn) string

Listens for packets received from DHT bootstrap node Every packet is unmarshaled and turned into Request structure which we should analyze and respond

func (*DHTClient) RegisterControlPeer

func (dht *DHTClient) RegisterControlPeer()

This method register control peer on a Bootstrap node

func (*DHTClient) ReportControlPeerLoad

func (dht *DHTClient) ReportControlPeerLoad(amount int)

func (*DHTClient) RequestControlPeer

func (dht *DHTClient) RequestControlPeer(id string)

This method request a new control peer for particular host

func (*DHTClient) RequestPeerIPs

func (dht *DHTClient) RequestPeerIPs(id string)

This function sends a request to DHT bootstrap node with ID of target node we want to connect to

func (*DHTClient) Stop

func (dht *DHTClient) Stop()

func (*DHTClient) UpdateLastCatch

func (dht *DHTClient) UpdateLastCatch(catch string)

After receiving a list of peers from DHT we will parse the list and add every new peer into list of peers

func (*DHTClient) UpdatePeers

func (dht *DHTClient) UpdatePeers()

UpdatePeers sends "find" request to a DHT Bootstrap node, so it can respond with a list of peers that we can connect to This method should be called periodically in case any new peers was discovered

type DHTResponseCallback

type DHTResponseCallback func(data commons.DHTResponse, conn *net.UDPConn)

type Forwarder

type Forwarder struct {
	Addr          *net.UDPAddr
	DestinationID string
}

type OperatingMode

type OperatingMode int
const (
	MODE_CLIENT OperatingMode = 1
	MODE_CP     OperatingMode = 2
)

type PeerIP

type PeerIP struct {
	ID  string
	Ips []string
}

Jump to

Keyboard shortcuts

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