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

Function new_client

hsmd/hsmd.c:184–250  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

182}
183
184static struct client *new_client(const tal_t *ctx,
185 const struct chainparams *chainparams,
186 const struct node_id *id,
187 u64 dbid,
188 const u64 capabilities,
189 int fd)
190{
191 struct client *c = tal(ctx, struct client);
192
193 c->msg_in = NULL;
194
195 /*~ All-zero pubkey is used for the initial master connection */
196 if (id) {
197 c->id = *id;
198 if (!node_id_valid(id))
199 status_failed(STATUS_FAIL_INTERNAL_ERROR,
200 "Invalid node id %s",
201 fmt_node_id(tmpctx, id));
202 } else {
203 memset(&c->id, 0, sizeof(c->id));
204 }
205 c->dbid = dbid;
206
207 c->capabilities = capabilities;
208 c->chainparams = chainparams;
209
210 /*~ This is the core of ccan/io: the connection creation calls a
211 * callback which returns the initial plan to execute: in our case,
212 * read a message.*/
213 c->conn = io_new_conn(ctx, fd, client_read_next, c);
214
215 /*~ tal_steal() moves a pointer to a new parent. At this point, the
216 * hierarchy is:
217 *
218 * ctx -> c
219 * ctx -> c->conn
220 *
221 * We want to the c->conn to own 'c', so that if the io_conn closes,
222 * the client is freed:
223 *
224 * ctx -> c->conn -> c.
225 */
226 tal_steal(c->conn, c);
227
228 /* We put the special zero-db HSM connections into an array, the rest
229 * go into the map. */
230 if (dbid == 0) {
231 assert(num_dbid_zero_clients < ARRAY_SIZE(dbid_zero_clients));
232 dbid_zero_clients[num_dbid_zero_clients++] = c;
233 c->hsmd_client = hsmd_client_new_main(c, c->capabilities, c);
234 } else {
235 struct client *old_client = uintmap_get(&clients, dbid);
236
237 /* Close conn and free any old client of this dbid. */
238 if (old_client)
239 io_close(old_client->conn);
240
241 if (!uintmap_add(&clients, dbid, c))

Callers 2

pass_client_hsmfdFunction · 0.85
mainFunction · 0.85

Calls 6

node_id_validFunction · 0.85
fmt_node_idFunction · 0.85
hsmd_client_new_mainFunction · 0.85
io_closeFunction · 0.85
hsmd_client_new_peerFunction · 0.85
status_failedFunction · 0.50

Tested by

no test coverage detected