| 1646 | } |
| 1647 | |
| 1648 | bool RpcServer::configure_http(const RpcServerConfig& cfg) |
| 1649 | { |
| 1650 | if (!cfg.is_valid()) |
| 1651 | return false; |
| 1652 | |
| 1653 | my->_cache_enabled = cfg.enable_cache; |
| 1654 | |
| 1655 | try |
| 1656 | { |
| 1657 | my->_config = cfg; |
| 1658 | auto m = my.get(); |
| 1659 | my->_httpd = std::make_shared<fc::http::server>(); |
| 1660 | int attempts = 0; |
| 1661 | bool success = false; |
| 1662 | |
| 1663 | while (!success) { |
| 1664 | try |
| 1665 | { |
| 1666 | my->_httpd->listen(cfg.httpd_endpoint); |
| 1667 | success = true; |
| 1668 | } |
| 1669 | catch (fc::exception& e) |
| 1670 | { |
| 1671 | FC_ASSERT(++attempts < 30, "Unable to bind HTTPD port; refusing to continue."); |
| 1672 | ulog("Failed to bind HTTPD port ${endpoint}; waiting 10 seconds and retrying (attempt ${attempt}/30)", |
| 1673 | ("endpoint", cfg.httpd_endpoint)("attempt", attempts)); |
| 1674 | elog("Failed to bind HTTPD port ${endpoint} with error ${e}", ("endpoint", cfg.rpc_endpoint)("e", e.to_detail_string())); |
| 1675 | } |
| 1676 | if (!success) |
| 1677 | fc::usleep(fc::seconds(10)); |
| 1678 | } |
| 1679 | |
| 1680 | my->_httpd->on_request([m](const fc::http::request& r, const fc::http::server::response& s){ m->handle_request(r, s); }); |
| 1681 | return true; |
| 1682 | } FC_RETHROW_EXCEPTIONS(warn, "attempting to configure rpc server ${port}", ("port", cfg.rpc_endpoint)("config", cfg)); |
| 1683 | } |
| 1684 | |
| 1685 | bool RpcServer::configure_encrypted_rpc(const RpcServerConfig& cfg) |
| 1686 | { |
no test coverage detected