Skip to content

Commit 8e4b589

Browse files
committed
connectd: message to tell lightningd if we couldn't forward an onion message.
Signed-off-by: Rusty Russell <[email protected]>
1 parent d196b9b commit 8e4b589

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed

connectd/connectd.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2441,6 +2441,7 @@ static struct io_plan *recv_req(struct io_conn *conn,
24412441
case WIRE_CONNECTD_PEER_DISCONNECT_DONE:
24422442
case WIRE_CONNECTD_START_SHUTDOWN_REPLY:
24432443
case WIRE_CONNECTD_INJECT_ONIONMSG_REPLY:
2444+
case WIRE_CONNECTD_ONIONMSG_FORWARD_FAIL:
24442445
break;
24452446
}
24462447

connectd/connectd_wire.csv

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,13 @@ msgtype,connectd_dev_exhaust_fds,2036
193193
# master -> connect: set artificial maximum reply_channel_range size.
194194
msgtype,connectd_dev_set_max_scids_encode_size,2035
195195
msgdata,connectd_dev_set_max_scids_encode_size,max,u32,
196+
197+
# connectd->master I couldn't forward this onionmessage
198+
msgtype,connectd_onionmsg_forward_fail,2012
199+
msgdata,connectd_onionmsg_forward_fail,source,node_id,
200+
msgdata,connectd_onionmsg_forward_fail,incoming_len,u16,
201+
msgdata,connectd_onionmsg_forward_fail,incoming,u8,incoming_len,
202+
msgdata,connectd_onionmsg_forward_fail,path_key,pubkey,
203+
msgdata,connectd_onionmsg_forward_fail,outgoing_len,u16,
204+
msgdata,connectd_onionmsg_forward_fail,outgoing,u8,outgoing_len,
205+
msgdata,connectd_onionmsg_forward_fail,next_node,?sciddir_or_pubkey,

connectd/onion_message.c

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ void onionmsg_req(struct daemon *daemon, const u8 *msg)
3636
}
3737
}
3838

39+
/* Source is NULL if we're injecting, otherwise it's a forward */
3940
static const char *handle_onion(const tal_t *ctx,
4041
struct daemon *daemon,
42+
const struct node_id *source,
4143
const struct pubkey *path_key,
4244
const u8 *onion)
4345
{
@@ -53,6 +55,15 @@ static const char *handle_onion(const tal_t *ctx,
5355
&next_onion_msg, &next_node,
5456
&final_om, &final_alias, &final_path_id);
5557
if (err) {
58+
if (source) {
59+
daemon_conn_send(daemon->master,
60+
take(towire_connectd_onionmsg_forward_fail(NULL,
61+
source,
62+
onion,
63+
path_key,
64+
NULL,
65+
NULL)));
66+
}
5667
return tal_steal(ctx, err);
5768
}
5869

@@ -90,6 +101,15 @@ static const char *handle_onion(const tal_t *ctx,
90101

91102
scid_to_node_id = scid_htable_get(daemon->scid_htable, next_node.scidd.scid);
92103
if (!scid_to_node_id) {
104+
if (source) {
105+
daemon_conn_send(daemon->master,
106+
take(towire_connectd_onionmsg_forward_fail(NULL,
107+
source,
108+
onion,
109+
path_key,
110+
next_onion_msg,
111+
&next_node)));
112+
}
93113
return tal_fmt(ctx, "onion msg: unknown next scid %s",
94114
fmt_short_channel_id(tmpctx, next_node.scidd.scid));
95115
}
@@ -100,6 +120,15 @@ static const char *handle_onion(const tal_t *ctx,
100120

101121
next_peer = peer_htable_get(daemon->peers, &next_node_id);
102122
if (!next_peer) {
123+
if (source) {
124+
daemon_conn_send(daemon->master,
125+
take(towire_connectd_onionmsg_forward_fail(NULL,
126+
source,
127+
onion,
128+
path_key,
129+
next_onion_msg,
130+
&next_node)));
131+
}
103132
return tal_fmt(ctx, "onion msg: unknown next peer %s",
104133
fmt_sciddir_or_pubkey(tmpctx, &next_node));
105134
}
@@ -109,7 +138,7 @@ static const char *handle_onion(const tal_t *ctx,
109138
}
110139

111140

112-
/* Peer sends an onion msg, or (if peer NULL) lightningd injects one. */
141+
/* Peer sends an onion msg. */
113142
void handle_onion_message(struct daemon *daemon,
114143
struct peer *peer, const u8 *msg)
115144
{
@@ -151,7 +180,7 @@ void handle_onion_message(struct daemon *daemon,
151180
return;
152181
}
153182

154-
handle_onion(tmpctx, daemon, &path_key, onion);
183+
handle_onion(tmpctx, daemon, &peer->id, &path_key, onion);
155184
}
156185

157186
void inject_onionmsg_req(struct daemon *daemon, const u8 *msg)
@@ -163,7 +192,7 @@ void inject_onionmsg_req(struct daemon *daemon, const u8 *msg)
163192
if (!fromwire_connectd_inject_onionmsg(msg, msg, &path_key, &onionmsg))
164193
master_badmsg(WIRE_CONNECTD_INJECT_ONIONMSG, msg);
165194

166-
err = handle_onion(tmpctx, daemon, &path_key, onionmsg);
195+
err = handle_onion(tmpctx, daemon, NULL, &path_key, onionmsg);
167196
daemon_conn_send(daemon->master,
168197
take(towire_connectd_inject_onionmsg_reply(NULL, err ? err : "")));
169198
}

lightningd/connect_control.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,11 @@ static void handle_custommsg_in(struct lightningd *ld, const u8 *msg)
367367
plugin_hook_call_custommsg(ld, NULL, p);
368368
}
369369

370+
static void handle_onionmsg_forward_fail(struct lightningd *ld, const u8 *msg)
371+
{
372+
/* FIXME: Do something! */
373+
}
374+
370375
static void connectd_start_shutdown_reply(struct subd *connectd,
371376
const u8 *reply,
372377
const int *fds UNUSED,
@@ -487,6 +492,10 @@ static unsigned connectd_msg(struct subd *connectd, const u8 *msg, const int *fd
487492
case WIRE_CONNECTD_CUSTOMMSG_IN:
488493
handle_custommsg_in(connectd->ld, msg);
489494
break;
495+
496+
case WIRE_CONNECTD_ONIONMSG_FORWARD_FAIL:
497+
handle_onionmsg_forward_fail(connectd->ld, msg);
498+
break;
490499
}
491500
return 0;
492501
}

0 commit comments

Comments
 (0)