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

Function peer_connected_hook_deserialize

lightningd/peer_control.c:1655–1698  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1653}
1654
1655static bool
1656peer_connected_hook_deserialize(struct peer_connected_hook_payload *payload,
1657 const char *buffer,
1658 const jsmntok_t *toks)
1659{
1660 struct lightningd *ld = payload->ld;
1661
1662 /* already rejected by prior plugin hook in the chain */
1663 if (payload->error != NULL)
1664 return true;
1665
1666 if (!toks || !buffer)
1667 return true;
1668
1669 /* If we had a hook, interpret result. */
1670 const jsmntok_t *t_res = json_get_member(buffer, toks, "result");
1671 const jsmntok_t *t_err = json_get_member(buffer, toks, "error_message");
1672
1673 /* fail */
1674 if (!t_res)
1675 fatal("Plugin returned an invalid response to the "
1676 "peer_connected hook: %s", buffer);
1677
1678 /* reject */
1679 if (json_tok_streq(buffer, t_res, "disconnect")) {
1680 payload->error = (u8*)"";
1681 if (t_err) {
1682 payload->error = towire_warningfmt(tmpctx, NULL, "%.*s",
1683 t_err->end - t_err->start,
1684 buffer + t_err->start);
1685 }
1686 log_debug(ld->log, "peer_connected hook rejects and says '%s'",
1687 payload->error);
1688 /* At this point we suppress other plugins in the chain and
1689 * directly move to final */
1690 peer_connected_hook_final(payload);
1691 return false;
1692 } else if (!json_tok_streq(buffer, t_res, "continue"))
1693 fatal("Plugin returned an invalid response to the "
1694 "peer_connected hook: %s", buffer);
1695
1696 /* call next hook */
1697 return true;
1698}
1699
1700/* Have they/we committed funds to the channel? */
1701static bool channel_state_relationship(enum channel_state state)

Callers

nothing calls this directly

Calls 5

json_get_memberFunction · 0.85
json_tok_streqFunction · 0.85
fatalFunction · 0.70
towire_warningfmtFunction · 0.50

Tested by

no test coverage detected