Send port on announces when possible
This commit is contained in:
parent
1b2a85600f
commit
a1b95d499d
18
client.go
18
client.go
|
@ -976,10 +976,28 @@ func (me *Client) AddTorrent(metaInfo *metainfo.MetaInfo) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (cl *Client) listenerAnnouncePort() (port int16) {
|
||||
l := cl.Listener
|
||||
if l == nil {
|
||||
return
|
||||
}
|
||||
addr := l.Addr()
|
||||
switch data := addr.(type) {
|
||||
case *net.TCPAddr:
|
||||
return int16(data.Port)
|
||||
case *net.UDPAddr:
|
||||
return int16(data.Port)
|
||||
default:
|
||||
log.Printf("unknown listener addr type: %T", addr)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (cl *Client) announceTorrent(t *Torrent) {
|
||||
req := tracker.AnnounceRequest{
|
||||
Event: tracker.Started,
|
||||
NumWant: -1,
|
||||
Port: cl.listenerAnnouncePort(),
|
||||
}
|
||||
req.PeerId = cl.PeerId
|
||||
req.InfoHash = t.InfoHash
|
||||
|
|
Loading…
Reference in New Issue