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