Skip to content

Commit

Permalink
gossipd: remove peer-related fields and wire messages.
Browse files Browse the repository at this point in the history
This completes the removal of peer-related messages.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Jul 25, 2018
1 parent 0d442b5 commit 7b2641e
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 200 deletions.
44 changes: 6 additions & 38 deletions gossipd/gossip.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ struct daemon {

u32 broadcast_interval;

/* Local and global features to offer to peers. */
u8 *localfeatures, *globalfeatures;
/* Global features to list in node_announcement. */
u8 *globalfeatures;

u8 alias[33];
u8 rgb[3];
Expand Down Expand Up @@ -1872,29 +1872,17 @@ static struct io_plan *gossip_init(struct daemon_conn *master,
struct bitcoin_blkid chain_hash;
u32 update_channel_interval;

/* FIXME: Remove these from init msg */
bool dev_allow_localhost;
struct wireaddr_internal *proposed_wireaddr;
enum addr_listen_announce *proposed_listen_announce;
struct wireaddr *proxyaddr;
bool reconnect, use_proxy_always, use_dns;
char *tor_password;

if (!fromwire_gossipctl_init(
daemon, msg, &daemon->broadcast_interval, &chain_hash,
&daemon->id, &daemon->globalfeatures,
&daemon->localfeatures, &proposed_wireaddr,
&proposed_listen_announce, daemon->rgb,
daemon->alias, &update_channel_interval, &reconnect,
&proxyaddr, &use_proxy_always,
&dev_allow_localhost, &use_dns,
&tor_password, &daemon->announcable)) {
daemon->rgb,
daemon->alias, &update_channel_interval,
&daemon->announcable)) {
master_badmsg(WIRE_GOSSIPCTL_INIT, msg);
}
/* Prune time is twice update time */
daemon->rstate = new_routing_state(daemon, &chain_hash, &daemon->id,
update_channel_interval * 2,
dev_allow_localhost);
update_channel_interval * 2);

/* Load stored gossip messages */
gossip_store_load(daemon->rstate, daemon->rstate->store);
Expand Down Expand Up @@ -2118,40 +2106,20 @@ static struct io_plan *recv_req(struct io_conn *conn, struct daemon_conn *master
break;
#endif /* !DEVELOPER */

/* These are handled by channeld */
case WIRE_GOSSIPCTL_ACTIVATE:
case WIRE_GOSSIPCTL_RELEASE_PEER:
case WIRE_GOSSIPCTL_HAND_BACK_PEER:
case WIRE_GOSSIPCTL_CONNECT_TO_PEER:
case WIRE_GOSSIPCTL_PEER_ADDRHINT:
case WIRE_GOSSIPCTL_PEER_IMPORTANT:
case WIRE_GOSSIPCTL_PEER_DISCONNECTED:
case WIRE_GOSSIP_GETPEERS_REQUEST:
case WIRE_GOSSIPCTL_PEER_DISCONNECT:
break;

/* We send these, we don't receive them */
case WIRE_GOSSIPCTL_RELEASE_PEER_REPLY:
case WIRE_GOSSIPCTL_RELEASE_PEER_REPLYFAIL:
case WIRE_GOSSIP_GETNODES_REPLY:
case WIRE_GOSSIP_GETROUTE_REPLY:
case WIRE_GOSSIP_GETCHANNELS_REPLY:
case WIRE_GOSSIP_GETPEERS_REPLY:
case WIRE_GOSSIP_PING_REPLY:
case WIRE_GOSSIP_SCIDS_REPLY:
case WIRE_GOSSIP_QUERY_CHANNEL_RANGE_REPLY:
case WIRE_GOSSIP_RESOLVE_CHANNEL_REPLY:
case WIRE_GOSSIP_PEER_CONNECTED:
case WIRE_GOSSIPCTL_CONNECT_TO_PEER_RESULT:
case WIRE_GOSSIP_PEER_NONGOSSIP:
case WIRE_GOSSIP_GET_UPDATE:
case WIRE_GOSSIP_GET_UPDATE_REPLY:
case WIRE_GOSSIP_SEND_GOSSIP:
case WIRE_GOSSIP_LOCAL_ADD_CHANNEL:
case WIRE_GOSSIP_LOCAL_CHANNEL_UPDATE:
case WIRE_GOSSIP_GET_TXOUT:
case WIRE_GOSSIPCTL_PEER_DISCONNECT_REPLY:
case WIRE_GOSSIPCTL_PEER_DISCONNECT_REPLYFAIL:
break;
}

Expand Down
109 changes: 0 additions & 109 deletions gossipd/gossip_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -9,100 +9,12 @@ gossipctl_init,,chain_hash,struct bitcoin_blkid
gossipctl_init,,id,struct pubkey
gossipctl_init,,gflen,u16
gossipctl_init,,gfeatures,gflen*u8
gossipctl_init,,lflen,u16
gossipctl_init,,lfeatures,lflen*u8
gossipctl_init,,num_wireaddrs,u16
gossipctl_init,,wireaddrs,num_wireaddrs*struct wireaddr_internal
gossipctl_init,,listen_announce,num_wireaddrs*enum addr_listen_announce
gossipctl_init,,rgb,3*u8
gossipctl_init,,alias,32*u8
gossipctl_init,,update_channel_interval,u32
gossipctl_init,,reconnect,bool
gossipctl_init,,tor_proxyaddr,?struct wireaddr
gossipctl_init,,use_tor_proxy_always,bool
gossipctl_init,,dev_allow_localhost,bool
gossipctl_init,,use_dns,bool
gossipctl_init,,tor_password,wirestring
gossipctl_init,,num_announcable,u16
gossipctl_init,,announcable,num_announcable*struct wireaddr

# Activate the gossip daemon, so others can connect.
gossipctl_activate,3025
# Do we listen?
gossipctl_activate,,listen,bool

# Master -> gossipd: Optional hint for where to find peer.
gossipctl_peer_addrhint,3014
gossipctl_peer_addrhint,,id,struct pubkey
gossipctl_peer_addrhint,,addr,struct wireaddr_internal

# Master -> gossipd: connect to a peer.
gossipctl_connect_to_peer,3001
gossipctl_connect_to_peer,,id,struct pubkey

# Gossipd->master: result (not a reply since it can be out-of-order, but
# you will get one reply for every request).
gossipctl_connect_to_peer_result,3020
gossipctl_connect_to_peer_result,,id,struct pubkey
# True it connected.
gossipctl_connect_to_peer_result,,connected,bool
# Otherwise, why we can't reach them.
gossipctl_connect_to_peer_result,,failreason,wirestring

# Master -> gossipd: try to always maintain connection to this peer (or not)
gossipctl_peer_important,3010
gossipctl_peer_important,,id,struct pubkey
gossipctl_peer_important,,important,bool

# Gossipd -> master: we got a peer. Two fds: peer and gossip
gossip_peer_connected,3002
gossip_peer_connected,,id,struct pubkey
gossip_peer_connected,,addr,struct wireaddr_internal
gossip_peer_connected,,crypto_state,struct crypto_state
gossip_peer_connected,,gflen,u16
gossip_peer_connected,,gfeatures,gflen*u8
gossip_peer_connected,,lflen,u16
gossip_peer_connected,,lfeatures,lflen*u8

# Gossipd -> master: peer sent non-gossip packet. Two fds: peer and gossip
gossip_peer_nongossip,3003
gossip_peer_nongossip,,id,struct pubkey
gossip_peer_nongossip,,addr,struct wireaddr_internal
gossip_peer_nongossip,,crypto_state,struct crypto_state
gossip_peer_nongossip,,gflen,u16
gossip_peer_nongossip,,gfeatures,gflen*u8
gossip_peer_nongossip,,lflen,u16
gossip_peer_nongossip,,lfeatures,lflen*u8
gossip_peer_nongossip,,len,u16
gossip_peer_nongossip,,msg,len*u8

# Master -> gossipd: release a peer (so we can open a channel)
gossipctl_release_peer,3004
gossipctl_release_peer,,id,struct pubkey

# Gossipd -> master: reply to gossip_release_peer. Two fds: peer and gossip.
gossipctl_release_peer_reply,3104
gossipctl_release_peer_reply,,addr,struct wireaddr_internal
gossipctl_release_peer_reply,,crypto_state,struct crypto_state
gossipctl_release_peer_reply,,gflen,u16
gossipctl_release_peer_reply,,gfeatures,gflen*u8
gossipctl_release_peer_reply,,lflen,u16
gossipctl_release_peer_reply,,lfeatures,lflen*u8

# Gossipd -> master: reply to gossip_release_peer if we couldn't find the peer.
gossipctl_release_peer_replyfail,3204

# master -> gossipd: take back peer, with optional msg. (+peer fd, +gossip fd)
gossipctl_hand_back_peer,3013
gossipctl_hand_back_peer,,id,struct pubkey
gossipctl_hand_back_peer,,crypto_state,struct crypto_state
gossipctl_hand_back_peer,,len,u16
gossipctl_hand_back_peer,,msg,len*u8

# master -> gossipd: peer has disconnected.
gossipctl_peer_disconnected,3015
gossipctl_peer_disconnected,,id,struct pubkey

# Pass JSON-RPC getnodes call through
gossip_getnodes_request,3005
gossip_getnodes_request,,id,?struct pubkey
Expand Down Expand Up @@ -188,16 +100,6 @@ gossip_resolve_channel_reply,3109
gossip_resolve_channel_reply,,num_keys,u16
gossip_resolve_channel_reply,,keys,num_keys*struct pubkey

# The main daemon asks for peers
gossip_getpeers_request,3011
gossip_getpeers_request,,id,?struct pubkey

gossip_getpeers_reply,3111
gossip_getpeers_reply,,num,u16
gossip_getpeers_reply,,id,num*struct pubkey
gossip_getpeers_reply,,addr,num*struct wireaddr_internal
gossip_getpeers_reply,,nodes,num*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!
gossip_get_update,3012
Expand Down Expand Up @@ -255,17 +157,6 @@ gossip_routing_failure,,channel_update,len*u8
gossip_mark_channel_unroutable,3022
gossip_mark_channel_unroutable,,channel,struct short_channel_id

# master->gossipd: Request to disconnect from a peer.
gossipctl_peer_disconnect,3023
gossipctl_peer_disconnect,,id,struct pubkey

# Gossipd -> master: reply to gossip_peer_disconnect with peer id.
gossipctl_peer_disconnect_reply,3123

# Gossipd -> master: reply to gossip_peer_disconnect if we couldn't find the peer.
gossipctl_peer_disconnect_replyfail,3223
gossipctl_peer_disconnect_replyfail,,isconnected,bool

# master -> gossipd: a potential funding outpoint was spent, please forget the eventual channel
gossip_outpoint_spent,3024
gossip_outpoint_spent,,short_channel_id,struct short_channel_id
4 changes: 1 addition & 3 deletions gossipd/routing.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ static struct node_map *empty_node_map(const tal_t *ctx)
struct routing_state *new_routing_state(const tal_t *ctx,
const struct bitcoin_blkid *chain_hash,
const struct pubkey *local_id,
u32 prune_timeout,
bool dev_allow_localhost)
u32 prune_timeout)
{
struct routing_state *rstate = tal(ctx, struct routing_state);
rstate->nodes = empty_node_map(rstate);
Expand All @@ -96,7 +95,6 @@ struct routing_state *new_routing_state(const tal_t *ctx,
rstate->local_id = *local_id;
rstate->prune_timeout = prune_timeout;
rstate->store = gossip_store_new(rstate, rstate, rstate->broadcasts);
rstate->dev_allow_localhost = dev_allow_localhost;
rstate->local_channel_announced = false;
list_head_init(&rstate->pending_cannouncement);
uintmap_init(&rstate->chanmap);
Expand Down
6 changes: 1 addition & 5 deletions gossipd/routing.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,6 @@ struct routing_state {
* restarts */
struct gossip_store *store;

/* For testing, we announce and accept localhost */
bool dev_allow_localhost;

/* A map of channels indexed by short_channel_ids */
UINTMAP(struct chan *) chanmap;

Expand All @@ -204,8 +201,7 @@ struct route_hop {
struct routing_state *new_routing_state(const tal_t *ctx,
const struct bitcoin_blkid *chain_hash,
const struct pubkey *local_id,
u32 prune_timeout,
bool dev_allow_localhost);
u32 prune_timeout);

struct chan *new_chan(struct routing_state *rstate,
const struct short_channel_id *scid,
Expand Down
2 changes: 1 addition & 1 deletion gossipd/test/run-bench-find_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ int main(int argc, char *argv[])
| SECP256K1_CONTEXT_SIGN);
setup_tmpctx();

rstate = new_routing_state(tmpctx, &zerohash, &me, 0, false);
rstate = new_routing_state(tmpctx, &zerohash, &me, 0);
opt_register_noarg("--perfme", opt_set_bool, &perfme,
"Run perfme-start and perfme-stop around benchmark");

Expand Down
2 changes: 1 addition & 1 deletion gossipd/test/run-find_route-specific.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ int main(void)
strlen("02ea622d5c8d6143f15ed3ce1d501dd0d3d09d3b1c83a44d0034949f8a9ab60f06"),
&c);

rstate = new_routing_state(tmpctx, &zerohash, &a, 0, false);
rstate = new_routing_state(tmpctx, &zerohash, &a, 0);

/* [{'active': True, 'short_id': '6990:2:1/1', 'fee_per_kw': 10, 'delay': 5, 'flags': 1, 'destination': '0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae', 'source': '02ea622d5c8d6143f15ed3ce1d501dd0d3d09d3b1c83a44d0034949f8a9ab60f06', 'last_update': 1504064344}, */
nc = get_or_make_connection(rstate, &c, &b, "6990:2:1");
Expand Down
2 changes: 1 addition & 1 deletion gossipd/test/run-find_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ int main(void)

memset(&tmp, 'a', sizeof(tmp));
pubkey_from_privkey(&tmp, &a);
rstate = new_routing_state(tmpctx, &zerohash, &a, 0, false);
rstate = new_routing_state(tmpctx, &zerohash, &a, 0);

new_node(rstate, &a);

Expand Down
44 changes: 2 additions & 42 deletions lightningd/gossip_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,26 +130,6 @@ static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds)
case WIRE_GOSSIP_LOCAL_CHANNEL_CLOSE:
break;

/* These are handled by connectd */
case WIRE_GOSSIPCTL_ACTIVATE:
case WIRE_GOSSIP_GETPEERS_REQUEST:
case WIRE_GOSSIPCTL_CONNECT_TO_PEER:
case WIRE_GOSSIPCTL_HAND_BACK_PEER:
case WIRE_GOSSIPCTL_RELEASE_PEER:
case WIRE_GOSSIPCTL_PEER_ADDRHINT:
case WIRE_GOSSIPCTL_PEER_DISCONNECT:
case WIRE_GOSSIPCTL_PEER_IMPORTANT:
case WIRE_GOSSIPCTL_PEER_DISCONNECTED:
case WIRE_GOSSIP_GETPEERS_REPLY:
case WIRE_GOSSIPCTL_RELEASE_PEER_REPLY:
case WIRE_GOSSIPCTL_RELEASE_PEER_REPLYFAIL:
case WIRE_GOSSIPCTL_PEER_DISCONNECT_REPLY:
case WIRE_GOSSIPCTL_PEER_DISCONNECT_REPLYFAIL:
case WIRE_GOSSIP_PEER_CONNECTED:
case WIRE_GOSSIP_PEER_NONGOSSIP:
case WIRE_GOSSIPCTL_CONNECT_TO_PEER_RESULT:
break;

case WIRE_GOSSIP_GET_TXOUT:
get_txout(gossip, msg);
break;
Expand All @@ -164,13 +144,6 @@ void gossip_init(struct lightningd *ld, int connectd_fd)
u8 *msg;
int hsmfd;
u64 capabilities = HSM_CAP_SIGN_GOSSIP;
struct wireaddr_internal *wireaddrs = ld->proposed_wireaddr;
enum addr_listen_announce *listen_announce = ld->proposed_listen_announce;
bool allow_localhost = false;
#if DEVELOPER
if (ld->dev_allow_localhost)
allow_localhost = true;
#endif

msg = towire_hsm_client_hsmfd(tmpctx, &ld->id, 0, capabilities);
if (!wire_sync_write(ld->hsm_fd, msg))
Expand All @@ -190,25 +163,12 @@ void gossip_init(struct lightningd *ld, int connectd_fd)
if (!ld->gossip)
err(1, "Could not subdaemon gossip");

/* If no addr specified, hand wildcard to gossipd */
if (tal_count(wireaddrs) == 0 && ld->autolisten) {
wireaddrs = tal_arrz(tmpctx, struct wireaddr_internal, 1);
listen_announce = tal_arr(tmpctx, enum addr_listen_announce, 1);
wireaddrs->itype = ADDR_INTERNAL_ALLPROTO;
wireaddrs->u.port = ld->portnum;
*listen_announce = ADDR_LISTEN_AND_ANNOUNCE;
}

msg = towire_gossipctl_init(
tmpctx, ld->config.broadcast_interval,
&get_chainparams(ld)->genesis_blockhash, &ld->id,
get_offered_global_features(tmpctx),
get_offered_local_features(tmpctx), wireaddrs,
listen_announce, ld->rgb,
ld->alias, ld->config.channel_update_interval, ld->reconnect,
ld->proxyaddr, ld->use_proxy_always || ld->pure_tor_setup,
allow_localhost, ld->config.use_dns,
ld->tor_service_password ? ld->tor_service_password : "",
ld->rgb,
ld->alias, ld->config.channel_update_interval,
ld->announcable);
subd_send_msg(ld->gossip, msg);
}
Expand Down

0 comments on commit 7b2641e

Please sign in to comment.