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

Function new_lightningd

lightningd/lightningd.c:90–383  ·  view source on GitHub ↗

~ The core lightning object: it's passed everywhere, and is basically a * global variable. This new_xxx pattern is something we'll see often: * it allocates and initializes a new structure, using *tal*, the hierarchical * allocator. */

Source from the content-addressed store, hash-verified

88 * it allocates and initializes a new structure, using *tal*, the hierarchical
89 * allocator. */
90static struct lightningd *new_lightningd(const tal_t *ctx)
91{
92 /*~ tal: each allocation is a child of an existing object (or NULL,
93 * the top-level object). When an object is freed, all the objects
94 * `tallocated` off it are also freed. We use it in place of malloc
95 * and free. For the technically inclined: tal allocations usually
96 * build a tree, and tal_freeing any node in the tree will result in
97 * the entire subtree rooted at that node to be freed.
98 *
99 * It's incredibly useful for grouping object lifetimes, as we'll see.
100 * For example, a `struct lightningd` has a pointer to a `log_book`
101 * which is allocated off the `struct lightningd`, and has its own
102 * internal members allocated off `log_book`: freeing `struct
103 * lightningd` frees them all.
104 *
105 * In this case, freeing `ctx` will free `ld`:
106 */
107 struct lightningd *ld = tal(ctx, struct lightningd);
108
109 /*~ Style note: `ctx` is declared `const`, yet we can `tallocate` from
110 * it. Adding/removing children is not considered to change an
111 * object; nor, in fact, is freeing it with tal_free(). This allows
112 * us to use const more liberally: the style rule here is that you
113 * should use 'const' on pointers if you can. */
114
115 /* They can turn this on with --developer */
116 ld->developer = false;
117
118 /*~ We used to EXPLICITLY #if-wrap DEVELOPER code, but as our test
119 * matrix grew, we turned them into a --developer runtime option.
120 * We still use the `dev` prefix everywhere to make the developer-
121 * only variations explicit though. */
122 ld->dev_debug_subprocess = NULL;
123 ld->dev_no_plugin_checksum = false;
124 ld->dev_disconnect_fd = -1;
125 ld->dev_subdaemon_fail = false;
126 ld->dev_allow_localhost = false;
127 ld->dev_fast_gossip = false;
128 ld->dev_fast_gossip_prune = false;
129 ld->dev_throttle_gossip = false;
130 ld->dev_suppress_gossip = false;
131 ld->dev_fast_reconnect = false;
132 ld->dev_force_privkey = NULL;
133 ld->dev_force_bip32_seed = NULL;
134 ld->dev_force_channel_secrets = NULL;
135 ld->dev_force_channel_secrets_shaseed = NULL;
136 ld->dev_force_tmp_channel_id = NULL;
137 ld->dev_no_htlc_timeout = false;
138 ld->dev_no_version_checks = false;
139 ld->dev_max_funding_unconfirmed = 2016;
140 ld->dev_low_prio_anchor_blocks = 2016;
141 ld->dev_ignore_modern_onion = false;
142 ld->dev_disable_commit = -1;
143 ld->dev_no_ping_timer = false;
144 ld->dev_any_channel_type = false;
145 ld->dev_allow_shutdown_destination_change = false;
146 ld->dev_hsmd_no_preapprove_check = false;
147 ld->dev_hsmd_fail_preapprove = false;

Callers 1

mainFunction · 0.85

Calls 8

list_head_initFunction · 0.85
timers_initFunction · 0.85
time_monoFunction · 0.85
new_log_bookFunction · 0.70
new_loggerFunction · 0.70
new_topologyFunction · 0.70
jsonrpc_setupFunction · 0.70
plugins_newFunction · 0.70

Tested by

no test coverage detected