| 2561 | } |
| 2562 | |
| 2563 | int main(int argc, char *argv[]) |
| 2564 | { |
| 2565 | struct daemon *daemon; |
| 2566 | bool developer; |
| 2567 | |
| 2568 | setup_locale(); |
| 2569 | |
| 2570 | /* Common subdaemon setup code. */ |
| 2571 | developer = subdaemon_setup(argc, argv); |
| 2572 | |
| 2573 | /* Allocate and set up our simple top-level structure. */ |
| 2574 | daemon = tal(NULL, struct daemon); |
| 2575 | daemon->developer = developer; |
| 2576 | daemon->connection_counter = 1; |
| 2577 | /* htable_new is our helper which allocates a htable, initializes it |
| 2578 | * and set up the memleak callback so our memleak code can see objects |
| 2579 | * inside it */ |
| 2580 | daemon->peers = new_htable(daemon, peer_htable); |
| 2581 | daemon->listeners = tal_arr(daemon, struct io_listener *, 0); |
| 2582 | daemon->connecting = new_htable(daemon, connecting_htable); |
| 2583 | list_head_init(&daemon->pending_in); |
| 2584 | daemon->important_ids = new_htable(daemon, important_id_htable); |
| 2585 | timers_init(&daemon->timers, time_mono()); |
| 2586 | daemon->gossmap_raw = NULL; |
| 2587 | daemon->shutting_down = false; |
| 2588 | daemon->max_connect_in_flight = 10; |
| 2589 | daemon->dev_suppress_gossip = false; |
| 2590 | daemon->custom_msgs = NULL; |
| 2591 | daemon->dev_exhausted_fds = false; |
| 2592 | daemon->dev_lightningd_is_slow = false; |
| 2593 | daemon->dev_keep_nagle = false; |
| 2594 | /* We generally allow 1MB per second per peer, except for dev testing */ |
| 2595 | daemon->gossip_stream_limit = 1000000; |
| 2596 | daemon->incoming_stream_limit = 1000000; |
| 2597 | /* Half a CPU-second/sec, total, split across however many peers we have */ |
| 2598 | daemon->cpu_budget_usec_limit = 500000; |
| 2599 | daemon->scid_htable = new_htable(daemon, scid_htable); |
| 2600 | |
| 2601 | /* stdin == control */ |
| 2602 | daemon->master = daemon_conn_new(daemon, STDIN_FILENO, recv_req, NULL, |
| 2603 | daemon); |
| 2604 | tal_add_destructor(daemon->master, master_gone); |
| 2605 | |
| 2606 | /* This tells the status_* subsystem to use this connection to send |
| 2607 | * our status_ and failed messages. */ |
| 2608 | status_setup_async(daemon->master); |
| 2609 | |
| 2610 | /* Don't leave around websocketd zombies. Technically not portable, |
| 2611 | * but OK for Linux and BSD, so... */ |
| 2612 | signal(SIGCHLD, SIG_IGN); |
| 2613 | |
| 2614 | /* This streams gossip to and from gossipd */ |
| 2615 | daemon->gossipd = daemon_conn_new(daemon, GOSSIPCTL_FD, |
| 2616 | recv_gossip, NULL, |
| 2617 | daemon); |
| 2618 | tal_add_destructor(daemon->gossipd, gossipd_failed); |
| 2619 | |
| 2620 | /* Set up ecdh() function so it uses our HSM fd, and calls |
nothing calls this directly
no test coverage detected