MCPcopy Create free account
hub / github.com/ElementsProject/lightning / peer_spoke

Function peer_spoke

lightningd/peer_control.c:1437–1582  ·  view source on GitHub ↗

connectd tells us a peer has a message and we've not already attached * a subd. Normally this is a race, but it happens for real when opening * a new channel, or referring to a channel we no longer want to talk to * it about. */

Source from the content-addressed store, hash-verified

1435 * a new channel, or referring to a channel we no longer want to talk to
1436 * it about. */
1437void peer_spoke(struct lightningd *ld, const u8 *msg)
1438{
1439 struct node_id id;
1440 u16 msgtype;
1441 u64 connectd_counter;
1442 struct channel *channel;
1443 struct channel_id channel_id;
1444 struct peer *peer;
1445 bool dual_fund;
1446 u8 *error;
1447 int fds[2];
1448
1449 if (!fromwire_connectd_peer_spoke(msg, &id, &connectd_counter, &msgtype, &channel_id))
1450 fatal("Connectd gave bad CONNECTD_PEER_SPOKE message %s",
1451 tal_hex(msg, msg));
1452
1453 /* We must know it, and it must be the right connectd_id */
1454 peer = peer_by_id(ld, &id);
1455 assert(peer->connectd_counter == connectd_counter);
1456
1457 /* Do we know what channel they're talking about? */
1458 channel = find_channel_by_id(peer, &channel_id);
1459 if (channel) {
1460 /* If we have a canned error for this channel, send it now */
1461 if (channel->error) {
1462 error = channel->error;
1463 goto send_error;
1464 }
1465
1466 /* If channel is active, we raced, so ignore this:
1467 * subd will get it soon. */
1468 if (channel_active(channel))
1469 return;
1470
1471 if (msgtype == WIRE_CHANNEL_REESTABLISH) {
1472 log_debug(channel->log,
1473 "Reestablish on %s channel: using channeld to reply",
1474 channel_state_name(channel));
1475 if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fds) != 0) {
1476 log_broken(channel->log,
1477 "Failed to create socketpair: %s",
1478 strerror(errno));
1479 error = towire_warningfmt(tmpctx, &channel->cid,
1480 "Trouble in paradise?");
1481 goto send_error;
1482 }
1483 if (peer_start_channeld(channel, new_peer_fd(tmpctx, fds[0]), NULL, true, true)) {
1484 goto tell_connectd;
1485 }
1486 /* FIXME: Send informative error? */
1487 close(fds[1]);
1488 return;
1489 }
1490
1491 /* Send generic error. */
1492 error = towire_errorfmt(tmpctx, &channel_id,
1493 "channel in state %s",
1494 channel_state_name(channel));

Callers 1

connectd_msgFunction · 0.85

Calls 15

tal_hexFunction · 0.85
peer_by_idFunction · 0.85
channel_activeFunction · 0.85
fatalFunction · 0.70
find_channel_by_idFunction · 0.70
channel_state_nameFunction · 0.70
peer_start_channeldFunction · 0.70
new_peer_fdFunction · 0.70
new_uncommitted_channelFunction · 0.70
peer_start_openingdFunction · 0.70
new_unsaved_channelFunction · 0.70
peer_start_dualopendFunction · 0.70

Tested by

no test coverage detected