From 05875d7f357fdaccfad7efd1981c40e6c50bc305 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 23 May 2017 21:26:04 +0930 Subject: [PATCH] opening: handle gossip. We don't send out gossip, but we do relay it to the gossip daemon if we get some. Signed-off-by: Rusty Russell --- lightningd/opening/opening.c | 15 ++++++++++----- lightningd/peer_control.c | 20 ++++++++++++-------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/lightningd/opening/opening.c b/lightningd/opening/opening.c index fcd802c5c..3b93ed61d 100644 --- a/lightningd/opening/opening.c +++ b/lightningd/opening/opening.c @@ -1,4 +1,3 @@ -/* FIXME: Handle incoming gossip messages! */ #include #include #include @@ -29,9 +28,10 @@ #include #include -/* stdin == requests, 3 == peer */ +/* stdin == requests, 3 == peer, 4 == gossip */ #define REQ_FD STDIN_FILENO #define PEER_FD 3 +#define GOSSIP_FD 4 struct state { struct crypto_state cs; @@ -186,7 +186,11 @@ static u8 *read_next_peer_msg(struct state *state, const tal_t *ctx) "Sending pong"); tal_free(pong); } else if (gossip_msg(msg)) { - /* FIXME: Send to gossip daemon! */ + /* We relay gossip to gossipd, but don't relay from */ + if (!wire_sync_write(GOSSIP_FD, msg)) + peer_failed(PEER_FD, &state->cs, NULL, + WIRE_OPENING_PEER_WRITE_FAILED, + "Relaying gossip message"); } else { return msg; } @@ -734,10 +738,11 @@ int main(int argc, char *argv[]) minimum_depth, min_feerate, max_feerate, peer_msg); - /* Write message and hand back the fd. */ + /* Write message and hand back the peer fd ang gossip fd. */ wire_sync_write(REQ_FD, msg); fdpass_send(REQ_FD, PEER_FD); - status_trace("Sent %s with fd", + fdpass_send(REQ_FD, GOSSIP_FD); + status_trace("Sent %s with 2 fds", opening_wire_type_name(fromwire_peektype(msg))); tal_free(state); return 0; diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 2310e32ce..ff8fd4597 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -1388,8 +1388,9 @@ static bool opening_funder_finished(struct subd *opening, const u8 *resp, struct pubkey changekey; struct pubkey remote_fundingkey, local_fundingkey; - assert(tal_count(fds) == 1); + assert(tal_count(fds) == 2); fc->peer->fd = fds[0]; + fc->peer->gossip_client_fd = fds[1]; fc->peer->cs = tal(fc->peer, struct crypto_state); if (!fromwire_opening_funder_reply(resp, NULL, @@ -1496,8 +1497,9 @@ static bool opening_fundee_finished(struct subd *opening, u8 *initmsg; log_debug(peer->log, "Got opening_fundee_finish_response"); - assert(tal_count(fds) == 1); + assert(tal_count(fds) == 2); peer->fd = fds[0]; + peer->gossip_client_fd = fds[1]; peer->cs = tal(peer, struct crypto_state); peer->funding_txid = tal(peer, struct sha256_double); @@ -1629,14 +1631,15 @@ void peer_fundee_open(struct peer *peer, const u8 *from_peer) peer->owner = new_subd(ld, ld, "lightningd_opening", peer, opening_wire_type_name, NULL, peer_owner_finished, - peer->fd, -1); + peer->fd, peer->gossip_client_fd, -1); if (!peer->owner) { peer_fail(peer, "Failed to subdaemon opening: %s", strerror(errno)); return; } - /* We handed off peer fd */ + /* We handed off peer fd and gossip fd */ peer->fd = -1; + peer->gossip_client_fd = -1; /* They will open channel. */ peer->funder = REMOTE; @@ -1669,7 +1672,7 @@ void peer_fundee_open(struct peer *peer, const u8 *from_peer) peer_fail(peer, "Unacceptably long open_channel"); return; } - subd_req(peer, peer->owner, take(msg), -1, 1, + subd_req(peer, peer->owner, take(msg), -1, 2, opening_fundee_finished, peer); } @@ -1706,7 +1709,7 @@ static bool gossip_peer_released(struct subd *gossip, "lightningd_opening", fc->peer, opening_wire_type_name, NULL, peer_owner_finished, - fc->peer->fd, -1); + fc->peer->fd, fc->peer->gossip_client_fd, -1); if (!opening) { peer_fail(fc->peer, "Failed to subdaemon opening: %s", strerror(errno)); @@ -1714,8 +1717,9 @@ static bool gossip_peer_released(struct subd *gossip, } fc->peer->owner = opening; - /* They took our fd. */ + /* They took our fds. */ fc->peer->fd = -1; + fc->peer->gossip_client_fd = -1; /* We will fund channel */ fc->peer->funder = LOCAL; @@ -1747,7 +1751,7 @@ static bool gossip_peer_released(struct subd *gossip, 15000, max_minimum_depth, fc->change, fc->change_keyindex, utxos, bip32_base); - subd_req(fc, opening, take(msg), -1, 1, opening_funder_finished, fc); + subd_req(fc, opening, take(msg), -1, 2, opening_funder_finished, fc); return true; }