| 668 | } |
| 669 | |
| 670 | int connectd_init(struct lightningd *ld) |
| 671 | { |
| 672 | int fds[2]; |
| 673 | u8 *msg; |
| 674 | int hsmfd; |
| 675 | struct wireaddr_internal *wireaddrs = ld->proposed_wireaddr; |
| 676 | enum addr_listen_announce *listen_announce = ld->proposed_listen_announce; |
| 677 | const char *websocket_helper_path; |
| 678 | void *ret; |
| 679 | |
| 680 | websocket_helper_path = subdaemon_path(tmpctx, ld, |
| 681 | "lightning_websocketd"); |
| 682 | |
| 683 | if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fds) != 0) |
| 684 | fatal("Could not socketpair for connectd<->gossipd"); |
| 685 | |
| 686 | hsmfd = hsm_get_global_fd(ld, HSM_PERM_ECDH); |
| 687 | |
| 688 | ld->connectd = new_global_subd(ld, "lightning_connectd", |
| 689 | connectd_wire_name, connectd_msg, |
| 690 | take(&hsmfd), take(&fds[1]), |
| 691 | /* Not take(): we share it */ |
| 692 | ld->dev_disconnect_fd >= 0 ? |
| 693 | &ld->dev_disconnect_fd : NULL, |
| 694 | NULL); |
| 695 | if (!ld->connectd) |
| 696 | err(1, "Could not subdaemon connectd"); |
| 697 | |
| 698 | /* If no addr specified, hand wildcard to connectd */ |
| 699 | if (tal_count(wireaddrs) == 0 && ld->autolisten) { |
| 700 | wireaddrs = tal_arrz(tmpctx, struct wireaddr_internal, 1); |
| 701 | listen_announce = tal_arr(tmpctx, enum addr_listen_announce, 1); |
| 702 | wireaddrs->itype = ADDR_INTERNAL_ALLPROTO; |
| 703 | wireaddrs->u.allproto.is_websocket = false; |
| 704 | wireaddrs->u.allproto.port = ld->portnum; |
| 705 | *listen_announce = ADDR_LISTEN_AND_ANNOUNCE; |
| 706 | } else |
| 707 | /* Make it clear that autolisten is not active! */ |
| 708 | ld->autolisten = false; |
| 709 | |
| 710 | msg = towire_connectd_init(tmpctx, chainparams, |
| 711 | ld->our_features, |
| 712 | &ld->our_nodeid, |
| 713 | wireaddrs, |
| 714 | listen_announce, |
| 715 | ld->proxyaddr, |
| 716 | ld->always_use_proxy || ld->pure_tor_setup, |
| 717 | ld->dev_allow_localhost, |
| 718 | ld->config.use_dns, |
| 719 | ld->tor_service_password ? ld->tor_service_password : "", |
| 720 | ld->config.connection_timeout_secs, |
| 721 | websocket_helper_path, |
| 722 | ld->message_padding, |
| 723 | ld->dev_fast_gossip, |
| 724 | ld->dev_disconnect_fd >= 0, |
| 725 | ld->dev_no_ping_timer, |
| 726 | ld->dev_handshake_no_reply, |
| 727 | ld->dev_throttle_gossip, |
no test coverage detected