@cryptotaxi247 / kubo / commits / 5ebf962b2

cache nat port mappings for a short period of time

License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>

Jeromy committed Sep 10, 2015 at 12:58 UTC 5ebf962b2d62c1ebc2b450237c54b83c13ed9a57
1 file changed -6
p2p/nat/nat.go
-6
@@ -35,11 +35,9 @@ const CacheTime = time.Second * 15
35 // DiscoverNAT looks for a NAT device in the network and
36 // returns an object that can manage port mappings.
37 func DiscoverNAT() *NAT {
38 - log.Error("DISCOVER NAT")
38 nat, err := nat.DiscoverGateway()
39 if err != nil {
40 log.Debug("DiscoverGateway error:", err)
42 - log.Error("DISCOVER GATEWAY ERROR: ", err)
41 return nil
42 }
43 addr, err := nat.GetDeviceAddress()
@@ -48,7 +46,6 @@ func DiscoverNAT() *NAT {
46 } else {
47 log.Debug("DiscoverGateway address:", addr)
48 }
51 - log.Error("NEW NAT!")
49 return newNAT(nat)
50 }
51
@@ -282,7 +279,6 @@ func (nat *NAT) rmMapping(m *mapping) {
279 // Clients should not store the mapped results, but rather always
280 // poll our object for the latest mappings.
281 func (nat *NAT) NewMapping(maddr ma.Multiaddr) (Mapping, error) {
285 - log.Error("NEW MAPPING!")
282 if nat == nil {
283 return nil, fmt.Errorf("no nat available")
284 }
@@ -330,7 +326,6 @@ func (nat *NAT) NewMapping(maddr ma.Multiaddr) (Mapping, error) {
326 }
327
328 func (nat *NAT) establishMapping(m *mapping) {
333 - log.Error("establishMapping!")
329 oldport := m.ExternalPort()
330 log.Debugf("Attempting port map: %s/%d", m.Protocol(), m.InternalPort())
331 newport, err := nat.nat.AddPortMapping(m.Protocol(), m.InternalPort(), "http", MappingDuration)
@@ -431,7 +426,6 @@ func (nat *NAT) MappedAddrs() map[ma.Multiaddr]ma.Multiaddr {
426 // This set of mappings _may not_ be correct, as NAT devices are finicky.
427 // Consider this with _best effort_ semantics.
428 func (nat *NAT) ExternalAddrs() []ma.Multiaddr {
434 - log.Error("EXTERNAL ADDRS")
429 mappings := nat.Mappings()
430 addrs := make([]ma.Multiaddr, 0, len(mappings))
431 for _, m := range mappings {