mirror of
https://github.com/libp2p/go-libp2p.git
synced 2025-09-26 20:21:26 +08:00
Extracted from gogotelehash
This commit is contained in:
@@ -6,7 +6,7 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/telehash/gogotelehash/util/nat"
|
||||
"github.com/fd/go-nat"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
22
nat.go
22
nat.go
@@ -1,3 +1,4 @@
|
||||
// Package nat implements NAT handling facilities
|
||||
package nat
|
||||
|
||||
import (
|
||||
@@ -8,22 +9,33 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
var ErrNoExternalAddress = errors.New("nat: no external address")
|
||||
var ErrNoInternalAddress = errors.New("nat: no internal address")
|
||||
var ErrNoNATFound = errors.New("nat: no NAT found")
|
||||
var ErrNoExternalAddress = errors.New("no external address")
|
||||
var ErrNoInternalAddress = errors.New("no internal address")
|
||||
var ErrNoNATFound = errors.New("no NAT found")
|
||||
|
||||
// protocol is either "udp" or "tcp"
|
||||
type NAT interface {
|
||||
// Type returns the kind of NAT port mapping service that is used
|
||||
Type() string
|
||||
|
||||
// GetDeviceAddress returns the internal address of the gateway device.
|
||||
GetDeviceAddress() (addr net.IP, err error)
|
||||
GetInternalAddress() (addr net.IP, err error)
|
||||
|
||||
// GetExternalAddress returns the external address of the gateway device.
|
||||
GetExternalAddress() (addr net.IP, err error)
|
||||
|
||||
// GetInternalAddress returns the address of the local host.
|
||||
GetInternalAddress() (addr net.IP, err error)
|
||||
|
||||
// AddPortMapping maps a port on the local host to an external port.
|
||||
AddPortMapping(protocol string, internalPort int, description string, timeout time.Duration) (mappedExternalPort int, err error)
|
||||
|
||||
// DeletePortMapping removes a port mapping.
|
||||
DeletePortMapping(protocol string, internalPort int) (err error)
|
||||
}
|
||||
|
||||
func Discover() (NAT, error) {
|
||||
// DiscoverGateway attempts to find a gateway device.
|
||||
func DiscoverGateway() (NAT, error) {
|
||||
select {
|
||||
case nat := <-discoverUPNP_IG1():
|
||||
return nat, nil
|
||||
|
@@ -4,7 +4,7 @@ import (
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/telehash/gogotelehash/Godeps/_workspace/src/github.com/jackpal/go-nat-pmp"
|
||||
"github.com/jackpal/go-nat-pmp"
|
||||
)
|
||||
|
||||
var (
|
||||
|
6
upnp.go
6
upnp.go
@@ -4,9 +4,9 @@ import (
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/telehash/gogotelehash/Godeps/_workspace/src/github.com/huin/goupnp"
|
||||
"github.com/telehash/gogotelehash/Godeps/_workspace/src/github.com/huin/goupnp/dcps/internetgateway1"
|
||||
"github.com/telehash/gogotelehash/Godeps/_workspace/src/github.com/huin/goupnp/dcps/internetgateway2"
|
||||
"github.com/huin/goupnp"
|
||||
"github.com/huin/goupnp/dcps/internetgateway1"
|
||||
"github.com/huin/goupnp/dcps/internetgateway2"
|
||||
)
|
||||
|
||||
var (
|
||||
|
Reference in New Issue
Block a user