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