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

Function new_peer

connectd/connectd.c:230–264  ·  view source on GitHub ↗

~ This is where we create a new peer. */

Source from the content-addressed store, hash-verified

228
229/*~ This is where we create a new peer. */
230static struct peer *new_peer(struct daemon *daemon,
231 const struct node_id *id,
232 const struct crypto_state *cs,
233 const u8 *their_features,
234 struct io_conn *conn STEALS,
235 int *fd_for_subd)
236{
237 struct peer *peer = tal(daemon, struct peer);
238
239 peer->daemon = daemon;
240 peer->id = *id;
241 peer->counter = daemon->connection_counter++;
242 peer->cs = *cs;
243 peer->subds = tal_arr(peer, struct subd *, 0);
244 peer->peer_in = NULL;
245 peer->sent_to_peer = NULL;
246 peer->urgent = false;
247 peer->draining = false;
248 peer->peer_outq = msg_queue_new(peer, false);
249 peer->last_recv_time = time_now();
250
251#if DEVELOPER
252 peer->dev_writes_enabled = NULL;
253 peer->dev_read_enabled = true;
254#endif
255
256 peer->to_peer = conn;
257
258 /* Now we own it */
259 tal_steal(peer, peer->to_peer);
260 peer_htable_add(&daemon->peers, peer);
261 tal_add_destructor(peer, destroy_peer);
262
263 return peer;
264}
265
266/*~ Note the lack of static: this is called by peer_exchange_initmsg.c once the
267 * INIT messages are exchanged, and also by the retry code above. */

Callers 5

peer_connectedFunction · 0.70
wallet_peer_loadFunction · 0.50
test_wallet_outputsFunction · 0.50
test_channel_crudFunction · 0.50

Calls 2

msg_queue_newFunction · 0.85
time_nowFunction · 0.85

Tested by 3

test_wallet_outputsFunction · 0.40
test_channel_crudFunction · 0.40