Peer sends an onion msg. */
| 135 | |
| 136 | /* Peer sends an onion msg. */ |
| 137 | void 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 | |
| 181 | void inject_onionmsg_req(struct daemon *daemon, const u8 *msg) |
| 182 | { |
no test coverage detected