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

Function handle_onion_message

connectd/onion_message.c:137–179  ·  view source on GitHub ↗

Peer sends an onion msg. */

Source from the content-addressed store, hash-verified

135
136/* Peer sends an onion msg. */
137void handle_onion_message(struct daemon *daemon,
138 struct peer *peer, const u8 *msg)
139{
140 struct pubkey path_key;
141 u8 *onion;
142 u64 msec;
143 struct timemono now = time_mono();
144
145 /* Ignore unless explicitly turned on. */
146 if (!feature_offered(daemon->our_features->bits[NODE_ANNOUNCE_FEATURE],
147 OPT_ONION_MESSAGES))
148 return;
149
150 /* Adjust tokens if they're entitled to more */
151 msec = time_to_msec(timemono_between(now, peer->onionmsg_last_incoming));
152 peer->onionmsg_incoming_tokens += msec;
153 if (peer->onionmsg_incoming_tokens > ONION_MSG_TOKENS_MAX)
154 peer->onionmsg_incoming_tokens = ONION_MSG_TOKENS_MAX;
155 peer->onionmsg_last_incoming = now;
156
157 /* No tokens left? Limit it */
158 if (peer->onionmsg_incoming_tokens < ONION_MSG_MSEC) {
159 /* Warn once, for debugging */
160 if (!peer->onionmsg_limit_warned) {
161 inject_peer_msg(peer,
162 take(towire_warningfmt(NULL, NULL,
163 "Ratelimited onion_message: exceeded one per %umsec",
164 ONION_MSG_MSEC)));
165 peer->onionmsg_limit_warned = true;
166 }
167 return;
168 }
169 peer->onionmsg_incoming_tokens -= ONION_MSG_MSEC;
170
171 if (!fromwire_onion_message(msg, msg, &path_key, &onion)) {
172 inject_peer_msg(peer,
173 take(towire_warningfmt(NULL, NULL,
174 "Bad onion_message")));
175 return;
176 }
177
178 handle_onion(tmpctx, daemon, &peer->id, &path_key, onion);
179}
180
181void inject_onionmsg_req(struct daemon *daemon, const u8 *msg)
182{

Callers 2

handle_message_locallyFunction · 0.85
runFunction · 0.85

Calls 7

time_monoFunction · 0.85
feature_offeredFunction · 0.85
time_to_msecFunction · 0.85
timemono_betweenFunction · 0.85
handle_onionFunction · 0.85
inject_peer_msgFunction · 0.70
towire_warningfmtFunction · 0.50

Tested by

no test coverage detected