From 6a831ca015c746472589e9039b41d0fd6d4a9af0 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Thu, 4 Jun 2015 14:04:57 +0200 Subject: [PATCH 1/2] Godeps: update github.com/huin/goupnp to 5cff77a69fb22f5 This includes a fix adding a timeout to router discovery requests. --- Godeps/Godeps.json | 2 +- Godeps/_workspace/src/github.com/huin/goupnp/goupnp.go | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index bc049d1aa6..4cbc73defe 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -31,7 +31,7 @@ }, { "ImportPath": "github.com/huin/goupnp", - "Rev": "c57ae84388ab59076fd547f1abeab71c2edb0a21" + "Rev": "5cff77a69fb22f5f1774c4451ea2aab63d4d2f20" }, { "ImportPath": "github.com/jackpal/go-nat-pmp", diff --git a/Godeps/_workspace/src/github.com/huin/goupnp/goupnp.go b/Godeps/_workspace/src/github.com/huin/goupnp/goupnp.go index 8cd20c2f44..7799a32ce7 100644 --- a/Godeps/_workspace/src/github.com/huin/goupnp/goupnp.go +++ b/Godeps/_workspace/src/github.com/huin/goupnp/goupnp.go @@ -19,7 +19,7 @@ import ( "fmt" "net/http" "net/url" - + "time" "golang.org/x/net/html/charset" "github.com/huin/goupnp/httpu" @@ -64,7 +64,6 @@ func DiscoverDevices(searchTarget string) ([]MaybeRootDevice, error) { maybe := &results[i] loc, err := response.Location() if err != nil { - maybe.Err = ContextError{"unexpected bad location from search", err} continue } @@ -93,7 +92,11 @@ func DiscoverDevices(searchTarget string) ([]MaybeRootDevice, error) { } func requestXml(url string, defaultSpace string, doc interface{}) error { - resp, err := http.Get(url) + timeout := time.Duration(3 * time.Second) + client := http.Client{ + Timeout: timeout, + } + resp, err := client.Get(url) if err != nil { return err } From fc6a5ae3ec7990d5c78649b0af46c46f31b88040 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Thu, 4 Jun 2015 14:05:52 +0200 Subject: [PATCH 2/2] p2p/nat: add timeout for UPnP SOAP requests --- p2p/nat/natupnp.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/p2p/nat/natupnp.go b/p2p/nat/natupnp.go index ef7765e8de..21a9cf8b13 100644 --- a/p2p/nat/natupnp.go +++ b/p2p/nat/natupnp.go @@ -12,6 +12,8 @@ import ( "github.com/huin/goupnp/dcps/internetgateway2" ) +const soapRequestTimeout = 3 * time.Second + type upnp struct { dev *goupnp.RootDevice service string @@ -131,6 +133,7 @@ func discover(out chan<- *upnp, target string, matcher func(*goupnp.RootDevice, } // check for a matching IGD service sc := goupnp.ServiceClient{service.NewSOAPClient(), devs[i].Root, service} + sc.SOAPClient.HTTPClient.Timeout = soapRequestTimeout upnp := matcher(devs[i].Root, sc) if upnp == nil { return