2
0
mirror of synced 2025-02-24 14:48:27 +00:00
torrent/tracker/peer.go

29 lines
479 B
Go
Raw Normal View History

package tracker
import (
"net"
2018-02-19 16:19:18 +11:00
2019-08-10 18:46:07 +10:00
"github.com/anacrolix/dht/v2/krpc"
)
type Peer struct {
IP net.IP
Port int
ID []byte
}
// Set from the non-compact form in BEP 3.
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))
}
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
}