multi: ensure addresses are no longer assumed to be TCP addresses only
In this commit, we go through the codebase looking for TCP address assumptions and modifying them to include the recently introduced onion addresses. This enables us to fully support onion addresses within the daemon.
This commit is contained in:
parent
08f80b6cf3
commit
2e0484be19
@ -54,8 +54,6 @@ type LinkNode struct {
|
||||
// Addresses is a list of IP address in which either we were able to
|
||||
// reach the node over in the past, OR we received an incoming
|
||||
// authenticated connection for the stored identity public key.
|
||||
//
|
||||
// TODO(roasbeef): also need to support hidden service addrs
|
||||
Addresses []net.Addr
|
||||
|
||||
db *DB
|
||||
@ -85,7 +83,7 @@ func (l *LinkNode) UpdateLastSeen(lastSeen time.Time) error {
|
||||
|
||||
// AddAddress appends the specified TCP address to the list of known addresses
|
||||
// this node is/was known to be reachable at.
|
||||
func (l *LinkNode) AddAddress(addr *net.TCPAddr) error {
|
||||
func (l *LinkNode) AddAddress(addr net.Addr) error {
|
||||
for _, a := range l.Addresses {
|
||||
if a.String() == addr.String() {
|
||||
return nil
|
||||
|
@ -165,12 +165,12 @@ func (c *ChannelGraphBootstrapper) SampleNodeAddrs(numAddrs uint32,
|
||||
// If we haven't yet reached our limit, then
|
||||
// we'll copy over the details of this node
|
||||
// into the set of addresses to be returned.
|
||||
tcpAddr, ok := nodeAddr.(*net.TCPAddr)
|
||||
if !ok {
|
||||
// If this isn't a valid TCP address,
|
||||
// then we'll ignore it as currently
|
||||
// we'll only attempt to connect out to
|
||||
// TCP peers.
|
||||
switch nodeAddr.(type) {
|
||||
case *net.TCPAddr, *tor.OnionAddr:
|
||||
default:
|
||||
// If this isn't a valid address
|
||||
// supported by the protocol, then we'll
|
||||
// skip this node.
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -179,7 +179,7 @@ func (c *ChannelGraphBootstrapper) SampleNodeAddrs(numAddrs uint32,
|
||||
// error.
|
||||
a = append(a, &lnwire.NetAddress{
|
||||
IdentityKey: node.PubKey(),
|
||||
Address: tcpAddr,
|
||||
Address: nodeAddr,
|
||||
})
|
||||
}
|
||||
|
||||
|
17
pilot.go
17
pilot.go
@ -7,6 +7,7 @@ import (
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/lightningnetwork/lnd/autopilot"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/tor"
|
||||
"github.com/roasbeef/btcd/btcec"
|
||||
"github.com/roasbeef/btcd/wire"
|
||||
"github.com/roasbeef/btcutil"
|
||||
@ -49,18 +50,12 @@ func (c *chanController) OpenChannel(target *btcec.PublicKey,
|
||||
// advertised IP addresses, or have made a connection.
|
||||
var connected bool
|
||||
for _, addr := range addrs {
|
||||
// If the address doesn't already have a port, then
|
||||
// we'll assume the current default port.
|
||||
tcpAddr, ok := addr.(*net.TCPAddr)
|
||||
if !ok {
|
||||
return fmt.Errorf("TCP address required instead "+
|
||||
"have %T", addr)
|
||||
switch addr.(type) {
|
||||
case *net.TCPAddr, *tor.OnionAddr:
|
||||
lnAddr.Address = addr
|
||||
default:
|
||||
return fmt.Errorf("unknown address type %T", addr)
|
||||
}
|
||||
if tcpAddr.Port == 0 {
|
||||
tcpAddr.Port = defaultPeerPort
|
||||
}
|
||||
|
||||
lnAddr.Address = tcpAddr
|
||||
|
||||
// TODO(roasbeef): make perm connection in server after
|
||||
// chan open?
|
||||
|
38
server.go
38
server.go
@ -1016,17 +1016,7 @@ func (s *server) establishPersistentConnections() error {
|
||||
return err
|
||||
}
|
||||
for _, node := range linkNodes {
|
||||
for _, address := range node.Addresses {
|
||||
switch addr := address.(type) {
|
||||
case *net.TCPAddr:
|
||||
if addr.Port == 0 {
|
||||
addr.Port = defaultPeerPort
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
pubStr := string(node.IdentityPub.SerializeCompressed())
|
||||
|
||||
nodeAddrs := &nodeAddresses{
|
||||
pubKey: node.IdentityPub,
|
||||
addresses: node.Addresses,
|
||||
@ -1059,17 +1049,29 @@ func (s *server) establishPersistentConnections() error {
|
||||
linkNodeAddrs, ok := nodeAddrsMap[pubStr]
|
||||
if ok {
|
||||
for _, lnAddress := range linkNodeAddrs.addresses {
|
||||
lnAddrTCP, ok := lnAddress.(*net.TCPAddr)
|
||||
if !ok {
|
||||
var addrHost string
|
||||
switch addr := lnAddress.(type) {
|
||||
case *net.TCPAddr:
|
||||
addrHost = addr.IP.String()
|
||||
case *tor.OnionAddr:
|
||||
addrHost = addr.OnionService
|
||||
default:
|
||||
continue
|
||||
}
|
||||
|
||||
var addrMatched bool
|
||||
for _, polAddress := range policy.Node.Addresses {
|
||||
polTCPAddr, ok := polAddress.(*net.TCPAddr)
|
||||
if ok && polTCPAddr.IP.Equal(lnAddrTCP.IP) {
|
||||
switch addr := polAddress.(type) {
|
||||
case *net.TCPAddr:
|
||||
if addr.IP.String() == addrHost {
|
||||
addrMatched = true
|
||||
addrs = append(addrs, polTCPAddr)
|
||||
addrs = append(addrs, addr)
|
||||
}
|
||||
case *tor.OnionAddr:
|
||||
if addr.OnionService == addrHost {
|
||||
addrMatched = true
|
||||
addrs = append(addrs, addr)
|
||||
}
|
||||
}
|
||||
}
|
||||
if !addrMatched {
|
||||
@ -1078,9 +1080,9 @@ func (s *server) establishPersistentConnections() error {
|
||||
}
|
||||
} else {
|
||||
for _, addr := range policy.Node.Addresses {
|
||||
polTCPAddr, ok := addr.(*net.TCPAddr)
|
||||
if ok {
|
||||
addrs = append(addrs, polTCPAddr)
|
||||
switch addr.(type) {
|
||||
case *net.TCPAddr, *tor.OnionAddr:
|
||||
addrs = append(addrs, addr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user