]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Possibility to change UPnP ID (#354)
authordavtoro <35560260+davtoro@users.noreply.github.com>
Mon, 16 Dec 2019 02:22:24 +0000 (03:22 +0100)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 16 Dec 2019 02:22:24 +0000 (13:22 +1100)
config.go
portfwd.go

index 7f1b47382883a6a3e755dc3cb07c093f3a5a36f5..e40ce30cc017af4df0010ef1d3cad3e0613bb54a 100644 (file)
--- a/config.go
+++ b/config.go
@@ -32,6 +32,7 @@ type ClientConfig struct {
        ListenHost              func(network string) string
        ListenPort              int
        NoDefaultPortForwarding bool
+       UpnpID                  string
        // Don't announce to trackers. This only leaves DHT to discover peers.
        DisableTrackers bool `long:"disable-trackers"`
        DisablePEX      bool `long:"disable-pex"`
@@ -151,6 +152,7 @@ func NewDefaultClientConfig() *ClientConfig {
                HTTPUserAgent:                  DefaultHTTPUserAgent,
                ExtendedHandshakeClientVersion: "go.torrent dev 20181121",
                Bep20:                          "-GT0002-",
+               UpnpID:                         "anacrolix/torrent",
                NominalDialTimeout:             20 * time.Second,
                MinDialTimeout:                 3 * time.Second,
                EstablishedConnsPerTorrent:     50,
index 5cca34e2d8e269f79cd94470684b531746b0c7d5..db5bb7df570c6002e4a16a58f438ea1c94d307ef 100644 (file)
@@ -7,8 +7,8 @@ import (
        "github.com/anacrolix/upnp"
 )
 
-func (cl *Client) addPortMapping(d upnp.Device, proto upnp.Protocol, internalPort int) {
-       externalPort, err := d.AddPortMapping(proto, internalPort, internalPort, "anacrolix/torrent", 0)
+func (cl *Client) addPortMapping(d upnp.Device, proto upnp.Protocol, internalPort int, upnpID string) {
+       externalPort, err := d.AddPortMapping(proto, internalPort, internalPort, upnpID, 0)
        if err != nil {
                cl.logger.WithValues(log.Warning).Printf("error adding %s port mapping: %s", proto, err)
        } else if externalPort != internalPort {
@@ -29,10 +29,11 @@ func (cl *Client) forwardPort() {
        cl.lock()
        cl.logger.Printf("discovered %d upnp devices", len(ds))
        port := cl.incomingPeerPort()
+       id := cl.config.UpnpID
        cl.unlock()
        for _, d := range ds {
-               go cl.addPortMapping(d, upnp.TCP, port)
-               go cl.addPortMapping(d, upnp.UDP, port)
+               go cl.addPortMapping(d, upnp.TCP, port, id)
+               go cl.addPortMapping(d, upnp.UDP, port, id)
        }
        cl.lock()
 }