diff --git a/gossipd/gossip.c b/gossipd/gossip.c index bf3793c77..55248a036 100644 --- a/gossipd/gossip.c +++ b/gossipd/gossip.c @@ -1101,7 +1101,15 @@ static void append_node(struct gossip_getnodes_entry **nodes, size_t num_nodes = tal_count(*nodes); tal_resize(nodes, num_nodes + 1); (*nodes)[num_nodes].nodeid = n->id; + (*nodes)[num_nodes].last_timestamp = n->last_timestamp; + if (n->last_timestamp < 0) { + (*nodes)[num_nodes].addresses = NULL; + return; + } + (*nodes)[num_nodes].addresses = n->addresses; + (*nodes)[num_nodes].alias = n->alias; + memcpy((*nodes)[num_nodes].color, n->rgb_color, 3); } static struct io_plan *getnodes(struct io_conn *conn, struct daemon *daemon, diff --git a/lightningd/gossip_control.c b/lightningd/gossip_control.c index 53dfb3003..3d5beada9 100644 --- a/lightningd/gossip_control.c +++ b/lightningd/gossip_control.c @@ -4,6 +4,7 @@ #include "lightningd.h" #include "peer_control.h" #include "subd.h" +#include #include #include #include @@ -199,6 +200,17 @@ static void json_getnodes_reply(struct subd *gossip, const u8 *reply, for (i = 0; i < tal_count(nodes); i++) { json_object_start(response, NULL); json_add_pubkey(response, "nodeid", &nodes[i].nodeid); + if (nodes[i].last_timestamp < 0) { + json_object_end(response); + continue; + } + json_add_string(response, "alias", + tal_strndup(response, (char *)nodes[i].alias, + tal_len(nodes[i].alias))); + json_add_hex(response, "color", + nodes[i].color, ARRAY_SIZE(nodes[i].color)); + json_add_u64(response, "last_timestamp", + nodes[i].last_timestamp); json_array_start(response, "addresses"); for (j=0; jnodeid); + entry->last_timestamp = fromwire_u64(pptr, max); + + if (entry->last_timestamp < 0) { + entry->addresses = NULL; + entry->alias = NULL; + return; + } numaddresses = fromwire_u8(pptr, max); entry->addresses = tal_arr(ctx, struct wireaddr, numaddresses); @@ -16,16 +23,26 @@ void fromwire_gossip_getnodes_entry(const tal_t *ctx, const u8 **pptr, size_t *m return; } } + entry->alias = tal_arr(ctx, u8, fromwire_u8(pptr, max)); + fromwire(pptr, max, entry->alias, tal_len(entry->alias)); + fromwire(pptr, max, entry->color, sizeof(entry->color)); } void towire_gossip_getnodes_entry(u8 **pptr, const struct gossip_getnodes_entry *entry) { u8 i, numaddresses = tal_count(entry->addresses); towire_pubkey(pptr, &entry->nodeid); - towire_u8(pptr, numaddresses); + towire_u64(pptr, entry->last_timestamp); + if (entry->last_timestamp < 0) + return; + + towire_u8(pptr, numaddresses); for (i=0; iaddresses[i]); } + towire_u8(pptr, tal_len(entry->alias)); + towire(pptr, entry->alias, tal_len(entry->alias)); + towire(pptr, entry->color, sizeof(entry->color)); } void fromwire_route_hop(const u8 **pptr, size_t *max, struct route_hop *entry) diff --git a/lightningd/gossip_msg.h b/lightningd/gossip_msg.h index d7ffbd856..49ee8544d 100644 --- a/lightningd/gossip_msg.h +++ b/lightningd/gossip_msg.h @@ -6,7 +6,10 @@ struct gossip_getnodes_entry { struct pubkey nodeid; + s64 last_timestamp; /* -1 means never: following fields ignored */ struct wireaddr *addresses; + u8 *alias; + u8 color[3]; }; struct gossip_getchannels_entry { diff --git a/tests/test_lightningd.py b/tests/test_lightningd.py index 7a65f121e..3bd6af896 100644 --- a/tests/test_lightningd.py +++ b/tests/test_lightningd.py @@ -1421,6 +1421,16 @@ class LightningDTests(BaseLightningDTests): assert n1['nodeid'] == l1.info['id'] assert n2['nodeid'] == l2.info['id'] + # Might not have seen other node-announce yet. + assert n1['alias'] == 'JUNIORBEAM' + assert n1['color'] == '0266e4' + if not 'alias' in n2: + assert not 'color' in n2 + assert not 'addresses' in n2 + else: + assert n2['alias'] == 'SILENTARTIST' + assert n2['color'] == '022d22' + assert [c['active'] for c in l1.rpc.getchannels()['channels']] == [True, True] assert [c['public'] for c in l1.rpc.getchannels()['channels']] == [True, True] assert [c['active'] for c in l2.rpc.getchannels()['channels']] == [True, True]