| 1229 | } |
| 1230 | |
| 1231 | static bool |
| 1232 | peer_connected_hook_deserialize(struct peer_connected_hook_payload *payload, |
| 1233 | const char *buffer, |
| 1234 | const jsmntok_t *toks) |
| 1235 | { |
| 1236 | struct lightningd *ld = payload->ld; |
| 1237 | |
| 1238 | /* already rejected by prior plugin hook in the chain */ |
| 1239 | if (payload->error != NULL) |
| 1240 | return true; |
| 1241 | |
| 1242 | if (!toks || !buffer) |
| 1243 | return true; |
| 1244 | |
| 1245 | /* If we had a hook, interpret result. */ |
| 1246 | const jsmntok_t *t_res = json_get_member(buffer, toks, "result"); |
| 1247 | const jsmntok_t *t_err = json_get_member(buffer, toks, "error_message"); |
| 1248 | |
| 1249 | /* fail */ |
| 1250 | if (!t_res) |
| 1251 | fatal("Plugin returned an invalid response to the " |
| 1252 | "peer_connected hook: %s", buffer); |
| 1253 | |
| 1254 | /* reject */ |
| 1255 | if (json_tok_streq(buffer, t_res, "disconnect")) { |
| 1256 | payload->error = (u8*)""; |
| 1257 | if (t_err) { |
| 1258 | payload->error = towire_warningfmt(tmpctx, NULL, "%.*s", |
| 1259 | t_err->end - t_err->start, |
| 1260 | buffer + t_err->start); |
| 1261 | } |
| 1262 | log_debug(ld->log, "peer_connected hook rejects and says '%s'", |
| 1263 | payload->error); |
| 1264 | /* At this point we suppress other plugins in the chain and |
| 1265 | * directly move to final */ |
| 1266 | peer_connected_hook_final(payload); |
| 1267 | return false; |
| 1268 | } else if (!json_tok_streq(buffer, t_res, "continue")) |
| 1269 | fatal("Plugin returned an invalid response to the " |
| 1270 | "peer_connected hook: %s", buffer); |
| 1271 | |
| 1272 | /* call next hook */ |
| 1273 | return true; |
| 1274 | } |
| 1275 | |
| 1276 | /* Compare and store `remote_addr` and the `peer_id` that reported it. |
| 1277 | * If new address was reported by at least one other, do node_announcement */ |
nothing calls this directly
no test coverage detected