aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-02-03 02:44:47 +0800
committerobscuren <geffobscura@gmail.com>2014-02-03 02:44:47 +0800
commit48b41862ef89e3d694b71d452e7f67bfb34ca17f (patch)
treec03b0164c386d427aba38b0f2a7094823713a067
parent3f503ffc7f85287fc3716afb704f90a1a4e7b21b (diff)
downloadgo-tangerine-48b41862ef89e3d694b71d452e7f67bfb34ca17f.tar
go-tangerine-48b41862ef89e3d694b71d452e7f67bfb34ca17f.tar.gz
go-tangerine-48b41862ef89e3d694b71d452e7f67bfb34ca17f.tar.bz2
go-tangerine-48b41862ef89e3d694b71d452e7f67bfb34ca17f.tar.lz
go-tangerine-48b41862ef89e3d694b71d452e7f67bfb34ca17f.tar.xz
go-tangerine-48b41862ef89e3d694b71d452e7f67bfb34ca17f.tar.zst
go-tangerine-48b41862ef89e3d694b71d452e7f67bfb34ca17f.zip
UPnP Support
-rw-r--r--ethereum.go32
1 files changed, 14 insertions, 18 deletions
diff --git a/ethereum.go b/ethereum.go
index 83243e23c..b178644cf 100644
--- a/ethereum.go
+++ b/ethereum.go
@@ -54,24 +54,19 @@ type Ethereum struct {
nat NAT
}
-func New(caps Caps) (*Ethereum, error) {
- //db, err := ethdb.NewLDBDatabase()
+func New(caps Caps, usePnp bool) (*Ethereum, error) {
db, err := ethdb.NewMemDatabase()
if err != nil {
return nil, err
}
- /*
- gateway := net.ParseIP("192.168.192.1")
- nat := NewNatPMP(gateway)
- port, err := nat.AddPortMapping("tcp", 30303, 30303, "", 60)
- log.Println(port, err)
- */
-
- nat, err := Discover()
- if err != nil {
- log.Println("UPnP failed", err)
- return nil, err
+ var nat NAT
+ if usePnp {
+ nat, err = Discover()
+ if err != nil {
+ log.Println("UPnP failed", err)
+ return nil, err
+ }
}
ethutil.Config.Db = db
@@ -229,14 +224,15 @@ func (s *Ethereum) Start() {
if err != nil {
log.Println("Connection listening disabled. Acting as client")
} else {
- s.Addr = ln.Addr()
// Starting accepting connections
log.Println("Ready and accepting connections")
// Start the peer handler
go s.peerHandler(ln)
}
- go s.upnpUpdateThread()
+ if s.nat != nil {
+ go s.upnpUpdateThread()
+ }
// Start the reaping processes
go s.ReapDeadPeerHandler()
@@ -288,18 +284,18 @@ out:
for {
select {
case <-timer.C:
- listenPort, err := s.nat.AddPortMapping("TCP", int(lport), int(lport), "eth listen port", 20*60)
+ var err error
+ _, err = s.nat.AddPortMapping("TCP", int(lport), int(lport), "eth listen port", 20*60)
if err != nil {
log.Println("can't add UPnP port mapping:", err)
break out
}
if first && err == nil {
- externalip, err := s.nat.GetExternalAddress()
+ _, err = s.nat.GetExternalAddress()
if err != nil {
log.Println("UPnP can't get external address:", err)
continue out
}
- log.Println("Successfully bound via UPnP to", externalip, listenPort)
first = false
}
timer.Reset(time.Minute * 15)