Browse Source

gossip: Returning a gossip-client upon peer_ready

This fd is handed to the owner of the peer so that it can talk to the
gossip daemon.
ppa-0.6.1
Christian Decker 8 years ago
parent
commit
3045e25624
  1. 21
      lightningd/gossip/gossip.c
  2. 9
      lightningd/gossip_control.c
  3. 3
      lightningd/peer_control.h

21
lightningd/gossip/gossip.c

@ -62,6 +62,9 @@ struct peer {
u8 **msg_out; u8 **msg_out;
/* Is it time to continue the staggered broadcast? */ /* Is it time to continue the staggered broadcast? */
bool gossip_sync; bool gossip_sync;
/* The peer owner will use this to talk to gossipd */
int proxy_fd;
}; };
static void destroy_peer(struct peer *peer) static void destroy_peer(struct peer *peer)
@ -227,10 +230,21 @@ static bool has_even_bit(const u8 *bitmap)
return false; return false;
} }
static int peer_create_gossip_client(struct peer *peer)
{
int fds[2];
if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fds) != 0) {
return -1;
}
peer->proxy_fd = fds[0];
return fds[1];
}
static struct io_plan *peer_parse_init(struct io_conn *conn, static struct io_plan *peer_parse_init(struct io_conn *conn,
struct peer *peer, u8 *msg) struct peer *peer, u8 *msg)
{ {
u8 *gfeatures, *lfeatures; u8 *gfeatures, *lfeatures;
int client_fd;
if (!fromwire_init(msg, msg, NULL, &gfeatures, &lfeatures)) { if (!fromwire_init(msg, msg, NULL, &gfeatures, &lfeatures)) {
peer->error = tal_fmt(msg, "Bad init: %s", tal_hex(msg, msg)); peer->error = tal_fmt(msg, "Bad init: %s", tal_hex(msg, msg));
@ -255,12 +269,19 @@ static struct io_plan *peer_parse_init(struct io_conn *conn,
return io_close(conn); return io_close(conn);
} }
client_fd = peer_create_gossip_client(peer);
if (client_fd == -1) {
peer->error = tal_fmt(msg, "Internal error");
return io_close(conn);
}
/* BOLT #1: /* BOLT #1:
* *
* Each node MUST wait to receive `init` before sending any other * Each node MUST wait to receive `init` before sending any other
* messages. * messages.
*/ */
status_send(towire_gossipstatus_peer_ready(msg, peer->unique_id)); status_send(towire_gossipstatus_peer_ready(msg, peer->unique_id));
status_send_fd(client_fd);
/* Need to go duplex here, otherwise backpressure would mean /* Need to go duplex here, otherwise backpressure would mean
* we both wait indefinitely */ * we both wait indefinitely */

9
lightningd/gossip_control.c

@ -71,7 +71,7 @@ static void peer_nongossip(struct subd *gossip, const u8 *msg, int fd)
peer_accept_open(peer, &cs, inner); peer_accept_open(peer, &cs, inner);
} }
static void peer_ready(struct subd *gossip, const u8 *msg) static void peer_ready(struct subd *gossip, const u8 *msg, int fd)
{ {
u64 unique_id; u64 unique_id;
struct peer *peer; struct peer *peer;
@ -98,6 +98,8 @@ static void peer_ready(struct subd *gossip, const u8 *msg)
peer->connect_cmd = NULL; peer->connect_cmd = NULL;
} }
peer->gossip_client_fd = fd;
peer_set_condition(peer, "Exchanging gossip"); peer_set_condition(peer, "Exchanging gossip");
} }
@ -128,7 +130,10 @@ static enum subd_msg_ret gossip_msg(struct subd *gossip,
peer_nongossip(gossip, msg, fd); peer_nongossip(gossip, msg, fd);
break; break;
case WIRE_GOSSIPSTATUS_PEER_READY: case WIRE_GOSSIPSTATUS_PEER_READY:
peer_ready(gossip, msg); if (fd == -1) {
return SUBD_NEED_FD;
}
peer_ready(gossip, msg, fd);
break; break;
} }
return SUBD_COMPLETE; return SUBD_COMPLETE;

3
lightningd/peer_control.h

@ -52,6 +52,9 @@ struct peer {
/* Secret seed (FIXME: Move to hsm!) */ /* Secret seed (FIXME: Move to hsm!) */
struct privkey *seed; struct privkey *seed;
/* Gossip client fd, forwarded to the respective owner */
int gossip_client_fd;
}; };
struct peer *peer_by_unique_id(struct lightningd *ld, u64 unique_id); struct peer *peer_by_unique_id(struct lightningd *ld, u64 unique_id);

Loading…
Cancel
Save