Print node alias when listing peers

This commit is contained in:
John Barboza 2018-02-27 00:08:34 -05:00 committed by Rusty Russell
parent ca4603455b
commit b50912d8b1
4 changed files with 38 additions and 3 deletions

View File

@ -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);
}

View File

@ -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!

1 #include <common/cryptomsg.h>
153 gossip_local_add_channel,,flags,u16 gossip_local_add_channel,,chain_hash,struct bitcoin_blkid
154 gossip_local_add_channel,,cltv_expiry_delta,u16 gossip_local_add_channel,,remote_node_id,struct pubkey
155 gossip_local_add_channel,,htlc_minimum_msat,u64 gossip_local_add_channel,,flags,u16
156 gossip_local_add_channel,,cltv_expiry_delta,u16
157 gossip_local_add_channel,,htlc_minimum_msat,u64
158 gossip_local_add_channel,,fee_base_msat,u32
159 gossip_local_add_channel,,fee_proportional_millionths,u32
160 # Gossipd->master get this tx output please.

View File

@ -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,

View File

@ -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