aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/nat.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-01-04 21:20:16 +0800
committerobscuren <geffobscura@gmail.com>2015-01-04 21:20:16 +0800
commit09841b1c9b2553a4572590128580df37c8fa83ad (patch)
tree42a846801bde7d8f7edc5ec07ccbba7806261128 /p2p/nat.go
parentbd0c267cbe9db805b5a272d29ef8860c62ddafe5 (diff)
downloadgo-tangerine-09841b1c9b2553a4572590128580df37c8fa83ad.tar
go-tangerine-09841b1c9b2553a4572590128580df37c8fa83ad.tar.gz
go-tangerine-09841b1c9b2553a4572590128580df37c8fa83ad.tar.bz2
go-tangerine-09841b1c9b2553a4572590128580df37c8fa83ad.tar.lz
go-tangerine-09841b1c9b2553a4572590128580df37c8fa83ad.tar.xz
go-tangerine-09841b1c9b2553a4572590128580df37c8fa83ad.tar.zst
go-tangerine-09841b1c9b2553a4572590128580df37c8fa83ad.zip
Cleaned up some of that util
Diffstat (limited to 'p2p/nat.go')
-rw-r--r--p2p/nat.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/p2p/nat.go b/p2p/nat.go
new file mode 100644
index 000000000..9b771c3e8
--- /dev/null
+++ b/p2p/nat.go
@@ -0,0 +1,23 @@
+package p2p
+
+import (
+ "fmt"
+ "net"
+)
+
+func ParseNAT(natType string, gateway string) (nat NAT, err error) {
+ switch natType {
+ case "UPNP":
+ nat = UPNP()
+ case "PMP":
+ ip := net.ParseIP(gateway)
+ if ip == nil {
+ return nil, fmt.Errorf("cannot resolve PMP gateway IP %s", gateway)
+ }
+ nat = PMP(ip)
+ case "":
+ default:
+ return nil, fmt.Errorf("unrecognised NAT type '%s'", natType)
+ }
+ return
+}