@@ -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 */
3940static 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. */
113142void 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
157186void 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}
0 commit comments