Merge pull request #1185 from fjl/p2p-nat-timeouts
p2p/nat: request timeouts for UPnP discovery
This commit is contained in:
commit
067e66b348
2
Godeps/Godeps.json
generated
2
Godeps/Godeps.json
generated
@ -31,7 +31,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/huin/goupnp",
|
"ImportPath": "github.com/huin/goupnp",
|
||||||
"Rev": "c57ae84388ab59076fd547f1abeab71c2edb0a21"
|
"Rev": "5cff77a69fb22f5f1774c4451ea2aab63d4d2f20"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/jackpal/go-nat-pmp",
|
"ImportPath": "github.com/jackpal/go-nat-pmp",
|
||||||
|
9
Godeps/_workspace/src/github.com/huin/goupnp/goupnp.go
generated
vendored
9
Godeps/_workspace/src/github.com/huin/goupnp/goupnp.go
generated
vendored
@ -19,7 +19,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"time"
|
||||||
"golang.org/x/net/html/charset"
|
"golang.org/x/net/html/charset"
|
||||||
|
|
||||||
"github.com/huin/goupnp/httpu"
|
"github.com/huin/goupnp/httpu"
|
||||||
@ -64,7 +64,6 @@ func DiscoverDevices(searchTarget string) ([]MaybeRootDevice, error) {
|
|||||||
maybe := &results[i]
|
maybe := &results[i]
|
||||||
loc, err := response.Location()
|
loc, err := response.Location()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
maybe.Err = ContextError{"unexpected bad location from search", err}
|
maybe.Err = ContextError{"unexpected bad location from search", err}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -93,7 +92,11 @@ func DiscoverDevices(searchTarget string) ([]MaybeRootDevice, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func requestXml(url string, defaultSpace string, doc interface{}) 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,8 @@ import (
|
|||||||
"github.com/huin/goupnp/dcps/internetgateway2"
|
"github.com/huin/goupnp/dcps/internetgateway2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const soapRequestTimeout = 3 * time.Second
|
||||||
|
|
||||||
type upnp struct {
|
type upnp struct {
|
||||||
dev *goupnp.RootDevice
|
dev *goupnp.RootDevice
|
||||||
service string
|
service string
|
||||||
@ -131,6 +133,7 @@ func discover(out chan<- *upnp, target string, matcher func(*goupnp.RootDevice,
|
|||||||
}
|
}
|
||||||
// check for a matching IGD service
|
// check for a matching IGD service
|
||||||
sc := goupnp.ServiceClient{service.NewSOAPClient(), devs[i].Root, service}
|
sc := goupnp.ServiceClient{service.NewSOAPClient(), devs[i].Root, service}
|
||||||
|
sc.SOAPClient.HTTPClient.Timeout = soapRequestTimeout
|
||||||
upnp := matcher(devs[i].Root, sc)
|
upnp := matcher(devs[i].Root, sc)
|
||||||
if upnp == nil {
|
if upnp == nil {
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user