diff --git a/gossipd/gossip.c b/gossipd/gossip.c index fd2d17bf4..5427daa99 100644 --- a/gossipd/gossip.c +++ b/gossipd/gossip.c @@ -1765,11 +1765,14 @@ static struct io_plan *get_peers(struct io_conn *conn, size_t n = 0; struct pubkey *id = tal_arr(conn, struct pubkey, n); struct wireaddr *wireaddr = tal_arr(conn, struct wireaddr, n); + const struct gossip_getnodes_entry **nodes; struct pubkey *specific_id = NULL; + struct node_map_iter it; if (!fromwire_gossip_getpeers_request(msg, msg, &specific_id)) master_badmsg(WIRE_GOSSIPCTL_PEER_ADDRHINT, msg); + nodes = tal_arr(conn, const struct gossip_getnodes_entry*, 0); list_for_each(&daemon->peers, peer, list) { if (specific_id && !pubkey_eq(specific_id, &peer->id)) continue; @@ -1778,11 +1781,19 @@ static struct io_plan *get_peers(struct io_conn *conn, id[n] = peer->id; wireaddr[n] = peer->addr; + + struct node* nd = NULL; + for (nd = node_map_first(daemon->rstate->nodes, &it); nd; nd = node_map_next(daemon->rstate->nodes, &it)) { + if (pubkey_eq(&nd->id, &peer->id)) { + append_node(&nodes, nd); + break; + } + } n++; } daemon_conn_send(&daemon->master, - take(towire_gossip_getpeers_reply(conn, id, wireaddr))); + take(towire_gossip_getpeers_reply(conn, id, wireaddr, nodes))); return daemon_conn_read_next(conn, &daemon->master); } diff --git a/gossipd/gossip_wire.csv b/gossipd/gossip_wire.csv index 53b455bfb..979aa930f 100644 --- a/gossipd/gossip_wire.csv +++ b/gossipd/gossip_wire.csv @@ -153,6 +153,8 @@ gossip_getpeers_reply,3111 gossip_getpeers_reply,,num,u16 gossip_getpeers_reply,,id,num*struct pubkey gossip_getpeers_reply,,addr,num*struct wireaddr +gossip_getpeers_reply,,numnodes,u16 +gossip_getpeers_reply,,nodes,numnodes*struct gossip_getnodes_entry # Channel daemon can ask for updates for a specific channel, for sending # errors. Must be distinct from WIRE_CHANNEL_ANNOUNCEMENT etc. gossip msgs! diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 4ef62c26e..287b45e1b 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -588,10 +588,11 @@ static void gossipd_getpeers_complete(struct subd *gossip, const u8 *msg, /* This is a little sneaky... */ struct pubkey *ids; struct wireaddr *addrs; + struct gossip_getnodes_entry **nodes; struct json_result *response = new_json_result(gpa->cmd); struct peer *p; - if (!fromwire_gossip_getpeers_reply(msg, msg, &ids, &addrs)) { + if (!fromwire_gossip_getpeers_reply(msg, msg, &ids, &addrs, &nodes)) { command_fail(gpa->cmd, "Bad response from gossipd"); return; } @@ -622,6 +623,17 @@ static void gossipd_getpeers_complete(struct subd *gossip, const u8 *msg, json_array_end(response); } + for (size_t i = 0; i < tal_count(nodes); i++) { + /* If no addresses, then this node announcement hasn't been recieved yet + * So no alias information either. + */ + if (nodes[i]->addresses != NULL && pubkey_eq(&nodes[i]->nodeid, &p->id)) { + json_add_string_escape(response, "alias", (char*)nodes[i]->alias); + json_add_hex(response, "color", nodes[i]->color, ARRAY_SIZE(nodes[i]->color)); + break; + } + } + json_array_start(response, "channels"); json_add_uncommitted_channel(response, p->uncommitted_channel); @@ -690,6 +702,13 @@ static void gossipd_getpeers_complete(struct subd *gossip, const u8 *msg, /* Fake state. */ json_add_string(response, "state", "GOSSIPING"); json_add_pubkey(response, "id", ids+i); + for (size_t j = 0; j < tal_count(nodes); j++) { + if (nodes[j]->addresses != NULL && pubkey_eq(&nodes[j]->nodeid, ids+i)) { + json_add_string_escape(response, "alias", (char*)nodes[j]->alias); + json_add_hex(response, "color", nodes[j]->color, ARRAY_SIZE(nodes[j]->color)); + break; + } + } json_array_start(response, "netaddr"); if (addrs[i].type != ADDR_TYPE_PADDING) json_add_string(response, NULL, diff --git a/wallet/test/run-wallet.c b/wallet/test/run-wallet.c index d0cc2f4d7..d28360c8f 100644 --- a/wallet/test/run-wallet.c +++ b/wallet/test/run-wallet.c @@ -74,7 +74,7 @@ bool derive_basepoints(const struct privkey *seed UNNEEDED, bool extract_channel_id(const u8 *in_pkt UNNEEDED, struct channel_id *channel_id UNNEEDED) { fprintf(stderr, "extract_channel_id called!\n"); abort(); } /* Generated stub for fromwire_gossip_getpeers_reply */ -bool fromwire_gossip_getpeers_reply(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct pubkey **id UNNEEDED, struct wireaddr **addr UNNEEDED) +bool fromwire_gossip_getpeers_reply(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct pubkey **id UNNEEDED, struct wireaddr **addr UNNEEDED, struct gossip_getnodes_entry ***nodes UNNEEDED) { fprintf(stderr, "fromwire_gossip_getpeers_reply called!\n"); abort(); } /* Generated stub for fromwire_gossip_peer_connected */ bool fromwire_gossip_peer_connected(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct pubkey *id UNNEEDED, struct wireaddr *addr UNNEEDED, struct crypto_state *crypto_state UNNEEDED, u64 *gossip_index UNNEEDED, u8 **gfeatures UNNEEDED, u8 **lfeatures UNNEEDED) @@ -362,6 +362,9 @@ struct txowatch *watch_txo(const tal_t *ctx UNNEEDED, size_t input_num UNNEEDED, const struct block *block)) { fprintf(stderr, "watch_txo called!\n"); abort(); } +/* Generated stub for json_add_string_escape */ +void json_add_string_escape(struct json_result *result UNNEEDED, const char *fieldname UNNEEDED, const char *value UNNEEDED) +{ fprintf(stderr, "json_add_string_escape called!\n"); abort(); } /* AUTOGENERATED MOCKS END */ #if DEVELOPER