| 429 | } |
| 430 | |
| 431 | static struct command_result *handle_incmd(struct command *cmd, |
| 432 | struct node_id *peer, |
| 433 | u64 idnum, |
| 434 | const u8 *msg, size_t msglen, |
| 435 | bool terminal) |
| 436 | { |
| 437 | struct commando *incmd; |
| 438 | |
| 439 | incmd = find_commando(incoming_commands, peer, NULL); |
| 440 | /* Don't let them buffer multiple commands: discard old. */ |
| 441 | if (incmd && incmd->id != idnum) { |
| 442 | plugin_log(plugin, LOG_DBG, "New cmd from %s, replacing old", |
| 443 | fmt_node_id(tmpctx, peer)); |
| 444 | incmd = tal_free(incmd); |
| 445 | } |
| 446 | |
| 447 | if (!incmd) { |
| 448 | incmd = new_commando(plugin, NULL, peer, idnum); |
| 449 | incmd->contents = tal_arr(incmd, u8, 0); |
| 450 | tal_arr_expand(&incoming_commands, incmd); |
| 451 | tal_add_destructor2(incmd, destroy_commando, &incoming_commands); |
| 452 | |
| 453 | /* More than 16 partial commands at once? Free oldest */ |
| 454 | if (tal_count(incoming_commands) > 16) |
| 455 | tal_free(incoming_commands[0]); |
| 456 | } |
| 457 | |
| 458 | /* 1MB should be enough for anybody! */ |
| 459 | append_contents(incmd, msg, msglen, 1024*1024); |
| 460 | |
| 461 | if (!terminal) |
| 462 | return command_hook_success(cmd); |
| 463 | |
| 464 | if (!incmd->contents) { |
| 465 | plugin_log(plugin, LOG_UNUSUAL, "%s: ignoring oversize request", |
| 466 | fmt_node_id(tmpctx, peer)); |
| 467 | return command_hook_success(cmd); |
| 468 | } |
| 469 | |
| 470 | return try_command(cmd, incmd); |
| 471 | } |
| 472 | |
| 473 | static struct command_result *handle_reply(struct node_id *peer, |
| 474 | u64 idnum, |
no test coverage detected