dht

package
v0.0.0-...-c899e52 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2015 License: GPL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BOOTSTRAP []string = []string{
	"router.magnets.im:6881",
	"router.bittorrent.com:6881",
	"dht.transmissionbt.com:6881",
}

Functions

This section is empty.

Types

type Bucket

type Bucket struct {
	Nodes []*ContactInfo
	// contains filtered or unexported fields
}

DHT bucket

func NewBucket

func NewBucket() *Bucket

New bucket

func (*Bucket) Add

func (b *Bucket) Add(n *ContactInfo)

add node to bucket

func (*Bucket) FindNode

func (b *Bucket) FindNode(id ID) (*ContactInfo, error)

find node in bucket

func (*Bucket) Len

func (b *Bucket) Len() int

bucket len

func (*Bucket) UpdateTime

func (b *Bucket) UpdateTime(n *ContactInfo)

update bucket lastchange time.

type ContactInfo

type ContactInfo struct {
	IP   net.IP // ip address
	Port int    // UDP port
	Id   ID     // node ID
	// contains filtered or unexported fields
}

node contact info.

type ErrorMsg

type ErrorMsg struct {
	Errors []interface{}
	// contains filtered or unexported fields
}

KRPC Error message

type ID

type ID []byte

func GenerateNodeId

func GenerateNodeId() ID

Generate Node ID

func (ID) String

func (i ID) String() string

Convert ID to string

func (ID) Sum

func (id ID) Sum() int

ID sum

type KRPC

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

KRPC Protocol

func NewKRPC

func NewKRPC() *KRPC

New KRPC

func (*KRPC) DecodePackage

func (k *KRPC) DecodePackage(b []byte) (interface{}, error)

Decode KRPC Package

func (*KRPC) EncodeQueryPackage

func (k *KRPC) EncodeQueryPackage(methodName string, args map[string]interface{}) ([]byte, error)

Encode KRPC Query package

func (*KRPC) EncodeResponsePackage

func (k *KRPC) EncodeResponsePackage(tid string, response map[string]string) ([]byte, error)

Encode KRPC response package

func (*KRPC) GenerateTID

func (k *KRPC) GenerateTID() uint32
type tidStorage struct {
	id        uint32
	container map[uint32]string
	lock      sync.Mutex
}

// tid gc

func (ts *tidStorage) GC() {
	for {
		now := time.Now()
		d, _ := time.ParseDuration("-10s")
		t := now.Add(d)

		for k, v := range ts.container {
			kTime, _ := time.Parse(time.RFC3339, v)
			if kTime.Before(t) {
				ts.lock.Lock()
				delete(ts.container, k)
				ts.lock.Unlock()
			}
		}
	}
}

// is transaction id in tid container?

func (ts *tidStorage) Have(tid uint32) bool {
	ts.lock.Lock()
	defer ts.lock.Unlock()

	if _, ok := ts.container[tid]; ok {
		return true
	}
	return false
}

Generate transaction id

type Msg

type Msg struct {
	T string // transaction id
	Y string // the type of the message
}

KRPC message

type Network

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

network

type Node

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

DHT node

func NewDHTNode

func NewDHTNode(outputChan chan string, port int) *Node

func (*Node) CreateTable

func (n *Node) CreateTable() error

create routing table

func (*Node) Find_Node

func (n *Node) Find_Node(queryingNodeInfo *ContactInfo, target ID) error

find_node

func (*Node) GenerateToken

func (n *Node) GenerateToken(sender *ContactInfo) string

Generate token

func (*Node) GetInformation

func (n *Node) GetInformation()

get response/request from other node

func (*Node) Run

func (n *Node) Run()

run

type QueryMsg

type QueryMsg struct {
	Q string                 // method name of the query.
	A map[string]interface{} // method arguments.
	// contains filtered or unexported fields
}

KRPC queries message

type ResponseMsg

type ResponseMsg struct {
	R map[string]interface{} // return values.
	// contains filtered or unexported fields
}

KRPC response message

type Routing

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

dht routing

func NewRouting

func NewRouting(node *Node) *Routing

new routing

func (*Routing) InsertNode

func (r *Routing) InsertNode(node *ContactInfo) error

Insert Node

Jump to

Keyboard shortcuts

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