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 (*Bucket) FindNode ¶
func (b *Bucket) FindNode(id ID) (*ContactInfo, error)
find node in bucket
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 KRPC ¶
type KRPC struct {
// contains filtered or unexported fields
}
KRPC Protocol
func (*KRPC) DecodePackage ¶
Decode KRPC Package
func (*KRPC) EncodeQueryPackage ¶
Encode KRPC Query package
func (*KRPC) EncodeResponsePackage ¶
Encode KRPC response package
func (*KRPC) GenerateTID ¶
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 Node ¶
type Node struct {
// contains filtered or unexported fields
}
DHT node
func NewDHTNode ¶
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
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
Click to show internal directories.
Click to hide internal directories.