connectd: message to tell lightningd if we couldn't forward an onion message.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2024-12-05 13:44:31 +10:30
parent d196b9bb53
commit 8e4b589a9e
4 changed files with 52 additions and 3 deletions

View File

@@ -2441,6 +2441,7 @@ static struct io_plan *recv_req(struct io_conn *conn,
case WIRE_CONNECTD_PEER_DISCONNECT_DONE:
case WIRE_CONNECTD_START_SHUTDOWN_REPLY:
case WIRE_CONNECTD_INJECT_ONIONMSG_REPLY:
case WIRE_CONNECTD_ONIONMSG_FORWARD_FAIL:
break;
}

View File

@@ -193,3 +193,13 @@ msgtype,connectd_dev_exhaust_fds,2036
# master -> connect: set artificial maximum reply_channel_range size.
msgtype,connectd_dev_set_max_scids_encode_size,2035
msgdata,connectd_dev_set_max_scids_encode_size,max,u32,
# connectd->master I couldn't forward this onionmessage
msgtype,connectd_onionmsg_forward_fail,2012
msgdata,connectd_onionmsg_forward_fail,source,node_id,
msgdata,connectd_onionmsg_forward_fail,incoming_len,u16,
msgdata,connectd_onionmsg_forward_fail,incoming,u8,incoming_len,
msgdata,connectd_onionmsg_forward_fail,path_key,pubkey,
msgdata,connectd_onionmsg_forward_fail,outgoing_len,u16,
msgdata,connectd_onionmsg_forward_fail,outgoing,u8,outgoing_len,
msgdata,connectd_onionmsg_forward_fail,next_node,?sciddir_or_pubkey,
1 #include <bitcoin/block.h>
193
194
195
196
197
198
199
200
201
202
203
204
205

View File

@@ -36,8 +36,10 @@ void onionmsg_req(struct daemon *daemon, const u8 *msg)
}
}
/* Source is NULL if we're injecting, otherwise it's a forward */
static const char *handle_onion(const tal_t *ctx,
struct daemon *daemon,
const struct node_id *source,
const struct pubkey *path_key,
const u8 *onion)
{
@@ -53,6 +55,15 @@ static const char *handle_onion(const tal_t *ctx,
&next_onion_msg, &next_node,
&final_om, &final_alias, &final_path_id);
if (err) {
if (source) {
daemon_conn_send(daemon->master,
take(towire_connectd_onionmsg_forward_fail(NULL,
source,
onion,
path_key,
NULL,
NULL)));
}
return tal_steal(ctx, err);
}
@@ -90,6 +101,15 @@ static const char *handle_onion(const tal_t *ctx,
scid_to_node_id = scid_htable_get(daemon->scid_htable, next_node.scidd.scid);
if (!scid_to_node_id) {
if (source) {
daemon_conn_send(daemon->master,
take(towire_connectd_onionmsg_forward_fail(NULL,
source,
onion,
path_key,
next_onion_msg,
&next_node)));
}
return tal_fmt(ctx, "onion msg: unknown next scid %s",
fmt_short_channel_id(tmpctx, next_node.scidd.scid));
}
@@ -100,6 +120,15 @@ static const char *handle_onion(const tal_t *ctx,
next_peer = peer_htable_get(daemon->peers, &next_node_id);
if (!next_peer) {
if (source) {
daemon_conn_send(daemon->master,
take(towire_connectd_onionmsg_forward_fail(NULL,
source,
onion,
path_key,
next_onion_msg,
&next_node)));
}
return tal_fmt(ctx, "onion msg: unknown next peer %s",
fmt_sciddir_or_pubkey(tmpctx, &next_node));
}
@@ -109,7 +138,7 @@ static const char *handle_onion(const tal_t *ctx,
}
/* Peer sends an onion msg, or (if peer NULL) lightningd injects one. */
/* Peer sends an onion msg. */
void handle_onion_message(struct daemon *daemon,
struct peer *peer, const u8 *msg)
{
@@ -151,7 +180,7 @@ void handle_onion_message(struct daemon *daemon,
return;
}
handle_onion(tmpctx, daemon, &path_key, onion);
handle_onion(tmpctx, daemon, &peer->id, &path_key, onion);
}
void inject_onionmsg_req(struct daemon *daemon, const u8 *msg)
@@ -163,7 +192,7 @@ void inject_onionmsg_req(struct daemon *daemon, const u8 *msg)
if (!fromwire_connectd_inject_onionmsg(msg, msg, &path_key, &onionmsg))
master_badmsg(WIRE_CONNECTD_INJECT_ONIONMSG, msg);
err = handle_onion(tmpctx, daemon, &path_key, onionmsg);
err = handle_onion(tmpctx, daemon, NULL, &path_key, onionmsg);
daemon_conn_send(daemon->master,
take(towire_connectd_inject_onionmsg_reply(NULL, err ? err : "")));
}

View File

@@ -367,6 +367,11 @@ static void handle_custommsg_in(struct lightningd *ld, const u8 *msg)
plugin_hook_call_custommsg(ld, NULL, p);
}
static void handle_onionmsg_forward_fail(struct lightningd *ld, const u8 *msg)
{
/* FIXME: Do something! */
}
static void connectd_start_shutdown_reply(struct subd *connectd,
const u8 *reply,
const int *fds UNUSED,
@@ -487,6 +492,10 @@ static unsigned connectd_msg(struct subd *connectd, const u8 *msg, const int *fd
case WIRE_CONNECTD_CUSTOMMSG_IN:
handle_custommsg_in(connectd->ld, msg);
break;
case WIRE_CONNECTD_ONIONMSG_FORWARD_FAIL:
handle_onionmsg_forward_fail(connectd->ld, msg);
break;
}
return 0;
}