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