~ lightningd tells us to go! */
| 1546 | |
| 1547 | /*~ lightningd tells us to go! */ |
| 1548 | static void connect_activate(struct daemon *daemon, const u8 *msg) |
| 1549 | { |
| 1550 | bool do_listen; |
| 1551 | char *errmsg = NULL; |
| 1552 | |
| 1553 | if (!fromwire_connectd_activate(msg, &do_listen)) |
| 1554 | master_badmsg(WIRE_CONNECTD_ACTIVATE, msg); |
| 1555 | |
| 1556 | /* If we're --offline, lightningd tells us not to actually listen. */ |
| 1557 | if (do_listen) { |
| 1558 | for (size_t i = 0; i < tal_count(daemon->listen_fds); i++) { |
| 1559 | if (listen(daemon->listen_fds[i]->fd, 64) != 0) { |
| 1560 | if (daemon->listen_fds[i]->mayfail) |
| 1561 | continue; |
| 1562 | errmsg = tal_fmt(tmpctx, |
| 1563 | "Failed to listen on socket %s: %s", |
| 1564 | type_to_string(tmpctx, |
| 1565 | struct wireaddr_internal, |
| 1566 | &daemon->listen_fds[i]->wi), |
| 1567 | strerror(errno)); |
| 1568 | break; |
| 1569 | } |
| 1570 | notleak(io_new_listener(daemon, |
| 1571 | daemon->listen_fds[i]->fd, |
| 1572 | get_in_cb(daemon->listen_fds[i] |
| 1573 | ->is_websocket), |
| 1574 | daemon)); |
| 1575 | } |
| 1576 | } |
| 1577 | |
| 1578 | /* Free, with NULL assignment just as an extra sanity check. */ |
| 1579 | daemon->listen_fds = tal_free(daemon->listen_fds); |
| 1580 | |
| 1581 | /* OK, we're ready! */ |
| 1582 | daemon_conn_send(daemon->master, |
| 1583 | take(towire_connectd_activate_reply(NULL, errmsg))); |
| 1584 | } |
| 1585 | |
| 1586 | /* BOLT #10: |
| 1587 | * |
no test coverage detected