2016-11-22 15:40:46 +11:00
|
|
|
package tracker
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
2018-02-19 16:19:18 +11:00
|
|
|
|
|
|
|
"github.com/anacrolix/dht/krpc"
|
2016-11-22 15:40:46 +11:00
|
|
|
)
|
|
|
|
|
2018-02-12 23:49:33 +11:00
|
|
|
type Peer struct {
|
|
|
|
IP net.IP
|
|
|
|
Port int
|
|
|
|
ID []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set from the non-compact form in BEP 3.
|
2016-11-22 15:40:46 +11:00
|
|
|
func (p *Peer) fromDictInterface(d map[string]interface{}) {
|
|
|
|
p.IP = net.ParseIP(d["ip"].(string))
|
2019-04-13 15:25:19 +02:00
|
|
|
if _, ok := d["peer id"]; ok {
|
|
|
|
p.ID = []byte(d["peer id"].(string))
|
|
|
|
}
|
2016-11-22 15:40:46 +11:00
|
|
|
p.Port = int(d["port"].(int64))
|
|
|
|
}
|
2018-02-19 16:19:18 +11:00
|
|
|
|
|
|
|
func (p Peer) FromNodeAddr(na krpc.NodeAddr) Peer {
|
|
|
|
p.IP = na.IP
|
|
|
|
p.Port = na.Port
|
|
|
|
return p
|
|
|
|
}
|