From 019ba86b91cfca0b0d391dd03a8f20477491cec8 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 9 Jul 2018 20:47:49 +0930 Subject: [PATCH] gossipd: use optional fields. Signed-off-by: Rusty Russell --- gossipd/gossip.c | 17 +++++++---------- gossipd/gossip_wire.csv | 16 ++++------------ 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/gossipd/gossip.c b/gossipd/gossip.c index 9b034ff62..582237568 100644 --- a/gossipd/gossip.c +++ b/gossipd/gossip.c @@ -2269,18 +2269,15 @@ static struct io_plan *getnodes(struct io_conn *conn, struct daemon *daemon, u8 *out; struct node *n; const struct gossip_getnodes_entry **nodes; - struct pubkey *ids; + struct pubkey *id; - fromwire_gossip_getnodes_request(tmpctx, msg, &ids); + fromwire_gossip_getnodes_request(tmpctx, msg, &id); nodes = tal_arr(tmpctx, const struct gossip_getnodes_entry *, 0); - if (ids) { - for (size_t i = 0; i < tal_count(ids); i++) { - n = get_node(daemon->rstate, &ids[i]); - if (n) - append_node(&nodes, &ids[i], n->gfeatures, - NULL, n); - } + if (id) { + n = get_node(daemon->rstate, id); + if (n) + append_node(&nodes, id, n->gfeatures, NULL, n); } else { struct node_map_iter i; n = node_map_first(daemon->rstate->nodes, &i); @@ -3556,7 +3553,7 @@ static struct io_plan *get_peers(struct io_conn *conn, struct pubkey *id = tal_arr(conn, struct pubkey, n); struct wireaddr_internal *wireaddr = tal_arr(conn, struct wireaddr_internal, n); const struct gossip_getnodes_entry **nodes = tal_arr(conn, const struct gossip_getnodes_entry *, n); - struct pubkey *specific_id = NULL; + struct pubkey *specific_id; if (!fromwire_gossip_getpeers_request(msg, msg, &specific_id)) master_badmsg(WIRE_GOSSIPCTL_PEER_ADDRHINT, msg); diff --git a/gossipd/gossip_wire.csv b/gossipd/gossip_wire.csv index 1738b0491..edfc5723f 100644 --- a/gossipd/gossip_wire.csv +++ b/gossipd/gossip_wire.csv @@ -18,9 +18,7 @@ gossipctl_init,,rgb,3*u8 gossipctl_init,,alias,32*u8 gossipctl_init,,update_channel_interval,u32 gossipctl_init,,reconnect,bool -# This is 0 or 1. -gossipctl_init,,num_tor_proxyaddrs,u16 -gossipctl_init,,tor_proxyaddr,num_tor_proxyaddrs*struct wireaddr +gossipctl_init,,tor_proxyaddr,?struct wireaddr gossipctl_init,,use_tor_proxy_always,bool gossipctl_init,,dev_allow_localhost,bool gossipctl_init,,use_dns,bool @@ -112,9 +110,7 @@ gossipctl_peer_disconnected,,id,struct pubkey # Pass JSON-RPC getnodes call through gossip_getnodes_request,3005 -# Can be 0 or 1 currently -gossip_getnodes_request,,num,u16 -gossip_getnodes_request,,id,num*struct pubkey +gossip_getnodes_request,,id,?struct pubkey #include gossip_getnodes_reply,3105 @@ -136,9 +132,7 @@ gossip_getroute_reply,,num_hops,u16 gossip_getroute_reply,,hops,num_hops*struct route_hop gossip_getchannels_request,3007 -# In practice, 0 or 1. -gossip_getchannels_request,,num,u16 -gossip_getchannels_request,,short_channel_id,num*struct short_channel_id +gossip_getchannels_request,,short_channel_id,?struct short_channel_id gossip_getchannels_reply,3107 gossip_getchannels_reply,,num_channels,u16 @@ -201,9 +195,7 @@ gossip_resolve_channel_reply,,keys,num_keys*struct pubkey # The main daemon asks for peers gossip_getpeers_request,3011 -# 0 or 1 -gossip_getpeers_request,,num,u16 -gossip_getpeers_request,,id,num*struct pubkey +gossip_getpeers_request,,id,?struct pubkey gossip_getpeers_reply,3111 gossip_getpeers_reply,,num,u16