~ lightningd tells us to go! */
| 1789 | |
| 1790 | /*~ lightningd tells us to go! */ |
| 1791 | static void connect_activate(struct daemon *daemon, const u8 *msg) |
| 1792 | { |
| 1793 | bool do_listen; |
| 1794 | char *errmsg = NULL; |
| 1795 | |
| 1796 | if (!fromwire_connectd_activate(msg, &do_listen)) |
| 1797 | master_badmsg(WIRE_CONNECTD_ACTIVATE, msg); |
| 1798 | |
| 1799 | /* If we're --offline, lightningd tells us not to actually listen. */ |
| 1800 | if (do_listen) { |
| 1801 | for (size_t i = 0; i < tal_count(daemon->listen_fds); i++) { |
| 1802 | if (listen(daemon->listen_fds[i]->fd, 64) != 0) { |
| 1803 | if (daemon->listen_fds[i]->mayfail) { |
| 1804 | close(daemon->listen_fds[i]->fd); |
| 1805 | continue; |
| 1806 | } |
| 1807 | errmsg = tal_fmt(tmpctx, |
| 1808 | "Failed to listen on socket %s: %s", |
| 1809 | fmt_wireaddr_internal(tmpctx, |
| 1810 | &daemon->listen_fds[i]->wi), |
| 1811 | strerror(errno)); |
| 1812 | break; |
| 1813 | } |
| 1814 | /* Add to listeners array */ |
| 1815 | tal_arr_expand(&daemon->listeners, |
| 1816 | io_new_listener(daemon, |
| 1817 | daemon->listen_fds[i]->fd, |
| 1818 | get_in_cb(daemon->listen_fds[i] |
| 1819 | ->is_websocket), |
| 1820 | daemon)); |
| 1821 | } |
| 1822 | } else { |
| 1823 | for (size_t i = 0; i < tal_count(daemon->listen_fds); i++) |
| 1824 | close(daemon->listen_fds[i]->fd); |
| 1825 | } |
| 1826 | |
| 1827 | /* Free, with NULL assignment just as an extra sanity check. */ |
| 1828 | daemon->listen_fds = tal_free(daemon->listen_fds); |
| 1829 | |
| 1830 | /* OK, we're ready! */ |
| 1831 | daemon_conn_send(daemon->master, |
| 1832 | take(towire_connectd_activate_reply(NULL, errmsg))); |
| 1833 | } |
| 1834 | |
| 1835 | static bool addr_in(const struct wireaddr_internal *needle, |
| 1836 | const struct wireaddr_internal haystack[]) |
no test coverage detected