From 11fc7503837cb7bfa3660514c30d755cbdb767ac Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Thu, 9 Mar 2017 16:56:04 +0100 Subject: [PATCH] gossip: Handle incoming client requests asynchronously --- lightningd/gossip/gossip.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lightningd/gossip/gossip.c b/lightningd/gossip/gossip.c index b07539b47..c5115f21d 100644 --- a/lightningd/gossip/gossip.c +++ b/lightningd/gossip/gossip.c @@ -65,6 +65,8 @@ struct peer { /* The peer owner will use this to talk to gossipd */ int proxy_fd; + struct io_conn *proxy_conn; + u8 *proxy_in; }; static void destroy_peer(struct peer *peer) @@ -230,6 +232,23 @@ static bool has_even_bit(const u8 *bitmap) return false; } +static struct io_plan *recv_client_req(struct io_conn *conn, struct peer *peer); +static struct io_plan *client_req_in(struct io_conn *conn, struct peer *peer) +{ + /* Handle incoming requests */ + return recv_client_req(conn, peer); +} + +static struct io_plan *recv_client_req(struct io_conn *conn, struct peer *peer) +{ + return io_read_wire(conn, peer, &peer->proxy_in, client_req_in, peer); +} + +static struct io_plan *peer_proxy_init(struct io_conn *conn, struct peer *peer) +{ + return recv_client_req(conn, peer); +} + static int peer_create_gossip_client(struct peer *peer) { int fds[2]; @@ -237,6 +256,7 @@ static int peer_create_gossip_client(struct peer *peer) return -1; } peer->proxy_fd = fds[0]; + peer->proxy_conn = io_new_conn(peer, fds[0], peer_proxy_init, peer); return fds[1]; }