MCPcopy Create free account
hub / github.com/ElementsProject/lightning / handle_incmd

Function handle_incmd

plugins/commando.c:431–471  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

429}
430
431static 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
473static struct command_result *handle_reply(struct node_id *peer,
474 u64 idnum,

Callers 1

handle_custommsgFunction · 0.85

Calls 8

find_commandoFunction · 0.85
fmt_node_idFunction · 0.85
tal_freeFunction · 0.85
new_commandoFunction · 0.85
append_contentsFunction · 0.85
try_commandFunction · 0.85
plugin_logFunction · 0.70
command_hook_successFunction · 0.70

Tested by

no test coverage detected