lnwire: update NodeAnnouncement to handle multiple addresses

This commit modifies address handling in the NodeAnnouncement struct,
switching from net.TCPAddr to []net.Addr. This enables more flexible
address handling with multiple types and multiple addresses for each
node. This commit addresses the first part of issue #131 .
This commit is contained in:
bryanvu authored and Olaoluwa Osuntokun committed 2017-03-29 12:03:43 -07:00
1 parent 65c15c4cb0
commit 9ffac9eae1
16 files changed
+594 -397

No files matched your search

+1 -1
View File
@@ -285,7 +285,7 @@ func addToTopologyChange(graph *channeldb.ChannelGraph, update *TopologyChange,
// No further data munging or db queries are required.
case *lnwire.NodeAnnouncement:
nodeUpdate := &NetworkNodeUpdate{
Addresses: []net.Addr{m.Address},
Addresses: m.Addresses,
IdentityKey: m.NodeID,
Alias: m.Alias.String(),
}
+7 -5
View File
@@ -20,7 +20,9 @@ import (
)
var (
testAddr, _ = net.ResolveTCPAddr("tcp", "10.0.0.1:9000")
testAddr = &net.TCPAddr{IP: (net.IP)([]byte{0xA, 0x0, 0x0, 0x1}),
Port: 9000}
testAddrs = []net.Addr{testAddr}
testHash = [32]byte{
0xb7, 0x94, 0x38, 0x5f, 0x2d, 0x1e, 0xf7, 0xab,
@@ -41,7 +43,7 @@ func createGraphNode() (*channeldb.LightningNode, error) {
pub := priv.PubKey().SerializeCompressed()
return &channeldb.LightningNode{
LastUpdate: time.Unix(updateTime, 0),
Address: testAddr,
Addresses: testAddrs,
PubKey: priv.PubKey(),
Color: color.RGBA{1, 2, 3, 0},
Alias: "kek" + string(pub[:]),
@@ -63,7 +65,7 @@ func createTestWireNode() (*lnwire.NodeAnnouncement, error) {
return &lnwire.NodeAnnouncement{
Timestamp: uint32(prand.Int31()),
Address: testAddr,
Addresses: testAddrs,
NodeID: priv.PubKey(),
Alias: alias,
}, nil
@@ -444,9 +446,9 @@ func TestNodeUpdateNotification(t *testing.T) {
// The notification received should directly map the
// announcement originally sent.
nodeNtfn := ntfns[0]
if nodeNtfn.Addresses[0] != ann.Address {
if nodeNtfn.Addresses[0] != ann.Addresses[0] {
t.Fatalf("node address doesn't match: expected %v, got %v",
nodeNtfn.Addresses[0], ann.Address)
nodeNtfn.Addresses[0], ann.Addresses[0])
}
if !nodeNtfn.IdentityKey.IsEqual(ann.NodeID) {
t.Fatalf("node identity keys don't match: expected %x, "+
+3 -1
View File
@@ -135,10 +135,12 @@ func parseTestGraph(path string) (*channeldb.ChannelGraph, func(), aliasMap, err
// We'll use this fake address for the IP address of all the nodes in
// our tests. This value isn't needed for path finding so it doesn't
// need to be unique.
var testAddrs []net.Addr
testAddr, err := net.ResolveTCPAddr("tcp", "192.0.0.1:8888")
if err != nil {
return nil, nil, nil, err
}
testAddrs = append(testAddrs, testAddr)
// Next, create a temporary graph database for usage within the test.
graph, cleanUp, err := makeTestGraph()
@@ -162,7 +164,7 @@ func parseTestGraph(path string) (*channeldb.ChannelGraph, func(), aliasMap, err
dbNode := &channeldb.LightningNode{
LastUpdate: time.Now(),
Address: testAddr,
Addresses: testAddrs,
PubKey: pub,
Alias: node.Alias,
}
+2 -2
View File
@@ -693,7 +693,7 @@ func (r *ChannelRouter) processNetworkAnnouncement(msg lnwire.Message) bool {
node := &channeldb.LightningNode{
LastUpdate: msgTimestamp,
Address: msg.Address,
Addresses: msg.Addresses,
PubKey: msg.NodeID,
Alias: msg.Alias.String(),
}
@@ -945,7 +945,7 @@ func (r *ChannelRouter) syncChannelGraph(syncReq *syncRequest) error {
ann := &lnwire.NodeAnnouncement{
Signature: r.fakeSig,
Timestamp: uint32(node.LastUpdate.Unix()),
Address: node.Address,
Addresses: node.Addresses,
NodeID: node.PubKey,
Alias: alias,
}