~ lightningd tells us to go! */
| 1844 | |
| 1845 | /*~ lightningd tells us to go! */ |
| 1846 | static void connect_activate(struct daemon *daemon, const u8 *msg) |
| 1847 | { |
| 1848 | bool do_listen; |
| 1849 | char *errmsg = NULL; |
| 1850 | |
| 1851 | if (!fromwire_connectd_activate(msg, &do_listen)) |
| 1852 | master_badmsg(WIRE_CONNECTD_ACTIVATE, msg); |
| 1853 | |
| 1854 | /* If we're --offline, lightningd tells us not to actually listen. */ |
| 1855 | if (do_listen) { |
| 1856 | for (size_t i = 0; i < tal_count(daemon->listen_fds); i++) { |
| 1857 | if (listen(daemon->listen_fds[i]->fd, 64) != 0) { |
| 1858 | if (daemon->listen_fds[i]->mayfail) { |
| 1859 | close(daemon->listen_fds[i]->fd); |
| 1860 | continue; |
| 1861 | } |
| 1862 | errmsg = tal_fmt(tmpctx, |
| 1863 | "Failed to listen on socket %s: %s", |
| 1864 | fmt_wireaddr_internal(tmpctx, |
| 1865 | &daemon->listen_fds[i]->wi), |
| 1866 | strerror(errno)); |
| 1867 | break; |
| 1868 | } |
| 1869 | /* Add to listeners array */ |
| 1870 | tal_arr_expand(&daemon->listeners, |
| 1871 | io_new_listener(daemon, |
| 1872 | daemon->listen_fds[i]->fd, |
| 1873 | get_in_cb(daemon->listen_fds[i] |
| 1874 | ->is_websocket), |
| 1875 | daemon)); |
| 1876 | } |
| 1877 | } else { |
| 1878 | for (size_t i = 0; i < tal_count(daemon->listen_fds); i++) |
| 1879 | close(daemon->listen_fds[i]->fd); |
| 1880 | } |
| 1881 | |
| 1882 | /* Free, with NULL assignment just as an extra sanity check. */ |
| 1883 | daemon->listen_fds = tal_free(daemon->listen_fds); |
| 1884 | |
| 1885 | /* OK, we're ready! */ |
| 1886 | daemon_conn_send(daemon->master, |
| 1887 | take(towire_connectd_activate_reply(NULL, errmsg))); |
| 1888 | } |
| 1889 | |
| 1890 | static bool addr_in(const struct wireaddr_internal *needle, |
| 1891 | const struct wireaddr_internal haystack[]) |
no test coverage detected