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

Function handle_incmd

plugins/commando.c:437–477  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

435}
436
437static 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
479static struct command_result *handle_reply(struct node_id *peer,
480 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