Browse Source

Merge pull request #665 from tendermint/no-internet

p2p: allow listener with no external connection
pull/675/head
Ethan Buchman 7 years ago
committed by GitHub
parent
commit
628791e5a5
5 changed files with 22 additions and 20 deletions
  1. +12
    -3
      glide.lock
  2. +1
    -1
      glide.yaml
  3. +1
    -12
      node/node.go
  4. +7
    -4
      p2p/listener.go
  5. +1
    -0
      rpc/lib/types/types.go

+ 12
- 3
glide.lock View File

@ -1,5 +1,5 @@
hash: 41581813ff97225a7feb86b5accb0fe4acb3e198b64592d7452240e9473c479f
updated: 2017-08-03T19:17:16.410522485Z
hash: 06ac555971ac41296cf6c869dfdf659ae911652d419e1a8c841aa791ff990556
updated: 2017-09-22T10:13:57.706322194-04:00
imports:
- name: github.com/btcsuite/btcd
version: b8df516b4b267acf2de46be593a9d948d1d2c420
@ -19,6 +19,12 @@ imports:
- log/term
- name: github.com/go-logfmt/logfmt
version: 390ab7935ee28ec6b286364bba9b4dd6410cb3d5
- name: github.com/go-playground/locales
version: 1e5f1161c6416a5ff48840eb8724a394e48cc534
subpackages:
- currency
- name: github.com/go-playground/universal-translator
version: 71201497bace774495daed26a3874fd339e0b538
- name: github.com/go-stack/stack
version: 100eb0c0a9c5b306ca2fb4f165df21d80ada4b82
- name: github.com/gogo/protobuf
@ -120,7 +126,7 @@ imports:
- iavl
- testutil
- name: github.com/tendermint/tmlibs
version: 7ce4da1eee6004d627e780c8fe91e96d9b99e459
version: 2130c329eb56aca8509ee1fec40d766f6541d8e7
subpackages:
- autofile
- cli
@ -128,6 +134,7 @@ imports:
- clist
- common
- db
- events
- flowrate
- log
- merkle
@ -184,6 +191,8 @@ imports:
- status
- tap
- transport
- name: gopkg.in/go-playground/validator.v9
version: d529ee1b0f30352444f507cc6cdac96bfd12decc
- name: gopkg.in/yaml.v2
version: cd8b52f8269e0feb286dfeef29f8fe4d5b397e0b
testImports:


+ 1
- 1
glide.yaml View File

@ -26,7 +26,7 @@ import:
subpackages:
- data
- package: github.com/tendermint/tmlibs
version: ~0.2.2
version: ~0.3.0
subpackages:
- autofile
- cli


+ 1
- 12
node/node.go View File

@ -309,7 +309,7 @@ func NewNode(config *cfg.Config,
// OnStart starts the Node. It implements cmn.Service.
func (n *Node) OnStart() error {
// Create & add listener
protocol, address := ProtocolAndAddress(n.config.P2P.ListenAddress)
protocol, address := cmn.ProtocolAndAddress(n.config.P2P.ListenAddress)
l := p2p.NewDefaultListener(protocol, address, n.config.P2P.SkipUPNP, n.Logger.With("module", "p2p"))
n.sw.AddListener(l)
@ -535,15 +535,4 @@ func (n *Node) DialSeeds(seeds []string) error {
return n.sw.DialSeeds(n.addrBook, seeds)
}
// ProtocolAndAddress returns the transport protocol
// and the ip address from the given string. Defaults to tcp.
func ProtocolAndAddress(listenAddr string) (string, string) {
protocol, address := "tcp", listenAddr
parts := strings.SplitN(address, "://", 2)
if len(parts) == 2 {
protocol, address = parts[0], parts[1]
}
return protocol, address
}
//------------------------------------------------------------------------------

+ 7
- 4
p2p/listener.go View File

@ -87,7 +87,7 @@ func NewDefaultListener(protocol string, lAddr string, skipUPNP bool, logger log
}
// Otherwise just use the local address...
if extAddr == nil {
extAddr = getNaiveExternalAddress(listenerPort)
extAddr = getNaiveExternalAddress(listenerPort, false, logger)
}
if extAddr == nil {
cmn.PanicCrisis("Could not determine external address!")
@ -197,7 +197,7 @@ func getUPNPExternalAddress(externalPort, internalPort int, logger log.Logger) *
}
// TODO: use syscalls: http://pastebin.com/9exZG4rh
func getNaiveExternalAddress(port int) *NetAddress {
func getNaiveExternalAddress(port int, settleForLocal bool, logger log.Logger) *NetAddress {
addrs, err := net.InterfaceAddrs()
if err != nil {
cmn.PanicCrisis(cmn.Fmt("Could not fetch interface addresses: %v", err))
@ -209,10 +209,13 @@ func getNaiveExternalAddress(port int) *NetAddress {
continue
}
v4 := ipnet.IP.To4()
if v4 == nil || v4[0] == 127 {
if v4 == nil || (!settleForLocal && v4[0] == 127) {
continue
} // loopback
return NewNetAddressIPPort(ipnet.IP, uint16(port))
}
return nil
// try again, but settle for local
logger.Info("Node may not be connected to internet. Settling for local address")
return getNaiveExternalAddress(port, true, logger)
}

+ 1
- 0
rpc/lib/types/types.go View File

@ -144,6 +144,7 @@ type WSRPCContext struct {
//
// Determine if its a unix or tcp socket.
// If tcp, must specify the port; `0.0.0.0` will return incorrectly as "unix" since there's no port
// TODO: deprecate
func SocketType(listenAddr string) string {
socketType := "unix"
if len(strings.Split(listenAddr, ":")) >= 2 {


Loading…
Cancel
Save