Skip to content

Commit

Permalink
Fix bugs: http only listen on localhost (#1759)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?

- HTTP server listens on 0.0.0.0 instead of localhost.
- Fix show index issue.

Issue link:#1647, #1757

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)

---------

Signed-off-by: Jin Hai <haijin.chn@gmail.com>
  • Loading branch information
JinHai-CN authored Aug 29, 2024
1 parent f31e43d commit 09396bf
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 21 deletions.
6 changes: 2 additions & 4 deletions src/bin/infinity_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,14 @@ auto main(int argc, char **argv) -> int {

fmt::print("Currently enabled SIMD support: {}\n", fmt::join(GetSupportedSimdTypesList(), ", "));

http_server_thread = infinity::Thread([&]() { http_server.Start(InfinityContext::instance().config()->HTTPPort()); });
http_server_thread = infinity::Thread([&]() { http_server.Start(InfinityContext::instance().config()->ServerAddress(), InfinityContext::instance().config()->HTTPPort()); });

u32 thrift_server_port = InfinityContext::instance().config()->ClientPort();

#if THRIFT_SERVER_TYPE == 0

i32 thrift_server_pool_size = InfinityContext::instance().config()->ConnectionPoolSize();
pool_thrift_server.Init(thrift_server_port, thrift_server_pool_size);
pool_thrift_server.Init(InfinityContext::instance().config()->ServerAddress(), thrift_server_port, thrift_server_pool_size);
pool_thrift_thread = infinity::Thread([&]() { pool_thrift_server.Start(); });

#elif THRIFT_SERVER_TYPE == 1
Expand Down Expand Up @@ -240,8 +240,6 @@ auto main(int argc, char **argv) -> int {

pg_thread.join();



fmt::print("Server is shutdown\n");
return 0;
}
6 changes: 3 additions & 3 deletions src/network/http_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3269,7 +3269,7 @@ class SetConfigHandler final : public HttpRequestHandler {

namespace infinity {

void HTTPServer::Start(u16 port) {
void HTTPServer::Start(const String& ip_address, u16 port) {

WebEnvironment::init();

Expand Down Expand Up @@ -3333,12 +3333,12 @@ void HTTPServer::Start(u16 port) {

router->route("POST", "/variables", MakeShared<SetGlobalVariableHandler>());

SharedPtr<HttpConnectionProvider> connection_provider = HttpConnectionProvider::createShared({"localhost", port, WebAddress::IP_4});
SharedPtr<HttpConnectionProvider> connection_provider = HttpConnectionProvider::createShared({ip_address, port, WebAddress::IP_4});
SharedPtr<HttpConnectionHandler> connection_handler = HttpConnectionHandler::createShared(router);

server_ = MakeShared<WebServer>(connection_provider, connection_handler);

fmt::print("HTTP server listen on port: {}\n", port);
fmt::print("HTTP server listen on {}: {}\n", ip_address, port);

server_->run();
}
Expand Down
2 changes: 1 addition & 1 deletion src/network/http_server.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace infinity {

export class HTTPServer {
public:
void Start(u16 port);
void Start(const String& server_address, u16 port);
void Shutdown();
private:
SharedPtr<HttpRouter> router_{};
Expand Down
21 changes: 12 additions & 9 deletions src/network/thrift_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,14 @@ class InfinityServiceCloneFactory final : public infinity_thrift_rpc::InfinitySe

// Thrift server

void ThreadedThriftServer::Init(i32 port_no) {
void ThreadedThriftServer::Init(const String& server_address, i32 port_no) {

std::cout << "API server listen on: 0.0.0.0:" << port_no << std::endl;
fmt::print("API server listen on {}: {}\n", server_address, port_no);
// std::cout << "API server listen on: " << server_address << ": " << port_no << std::endl;
SharedPtr<TBinaryProtocolFactory> binary_protocol_factory = MakeShared<TBinaryProtocolFactory>();
binary_protocol_factory->setStrict(true, true);
server = MakeUnique<TThreadedServer>(MakeShared<infinity_thrift_rpc::InfinityServiceProcessorFactory>(MakeShared<InfinityServiceCloneFactory>()),
MakeShared<TServerSocket>(port_no), // port
MakeShared<TServerSocket>(server_address, port_no),
MakeShared<TBufferedTransportFactory>(),
binary_protocol_factory);
}
Expand All @@ -78,9 +79,9 @@ void ThreadedThriftServer::Start() { server->serve(); }

void ThreadedThriftServer::Shutdown() { server->stop(); }

void PoolThriftServer::Init(i32 port_no, i32 pool_size) {
void PoolThriftServer::Init(const String& server_address, i32 port_no, i32 pool_size) {

SharedPtr<TServerSocket> server_socket = MakeShared<TServerSocket>(port_no);
SharedPtr<TServerSocket> server_socket = MakeShared<TServerSocket>(server_address, port_no);

SharedPtr<TBinaryProtocolFactory> protocol_factory = MakeShared<TBinaryProtocolFactory>();
// SharedPtr<TCompactProtocolFactory> protocol_factory = MakeShared<TCompactProtocolFactory>();
Expand All @@ -91,7 +92,8 @@ void PoolThriftServer::Init(i32 port_no, i32 pool_size) {
threadManager->threadFactory(threadFactory);
threadManager->start();

std::cout << "API server listen on: 0.0.0.0:" << port_no << ", thread pool: " << pool_size << std::endl;
fmt::print("API server(for Infinity-SDK) listen on {}: {}, connection limit: {}\n", server_address, port_no, pool_size);
// std::cout << "API server listen on: " << server_address << ": " << port_no << ", thread pool: " << pool_size << std::endl;

server =
MakeUnique<TThreadPoolServer>(MakeShared<infinity_thrift_rpc::InfinityServiceProcessorFactory>(MakeShared<InfinityServiceCloneFactory>()),
Expand All @@ -105,7 +107,7 @@ void PoolThriftServer::Start() { server->serve(); }

void PoolThriftServer::Shutdown() { server->stop(); }

void NonBlockPoolThriftServer::Init(i32 port_no, i32 pool_size) {
void NonBlockPoolThriftServer::Init(const String& server_address, i32 port_no, i32 pool_size) {

SharedPtr<ThreadFactory> thread_factory = MakeShared<ThreadFactory>();
service_handler_ = MakeShared<InfinityThriftService>();
Expand All @@ -117,9 +119,10 @@ void NonBlockPoolThriftServer::Init(i32 port_no, i32 pool_size) {
threadManager->threadFactory(thread_factory);
threadManager->start();

std::cout << "Non-block API server listen on: 0.0.0.0:" << port_no << ", thread pool: " << pool_size << std::endl;
fmt::print("Non-block API server listen on {}: {}, connection limit: {}\n", server_address, port_no, pool_size);
// std::cout << "Non-block API server listen on: " << server_address << ": " << port_no << ", thread pool: " << pool_size << std::endl;

SharedPtr<TNonblockingServerSocket> non_block_socket = MakeShared<TNonblockingServerSocket>(port_no);
SharedPtr<TNonblockingServerSocket> non_block_socket = MakeShared<TNonblockingServerSocket>(server_address, port_no);

// server_thread_ = thread_factory->newThread(std::shared_ptr<TServer>(
// new TNonblockingServer(serviceProcessor, protocolFactory, nbSocket1, threadManager)));
Expand Down
6 changes: 3 additions & 3 deletions src/network/thrift_server.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace infinity {

export class ThreadedThriftServer {
public:
void Init(i32 port_no);
void Init(const String& server_address, i32 port_no);
void Start();
void Shutdown();

Expand All @@ -46,7 +46,7 @@ private:

export class PoolThriftServer {
public:
void Init(i32 port_no, i32 pool_size);
void Init(const String& server_address, i32 port_no, i32 pool_size);
void Start();
void Shutdown();

Expand All @@ -56,7 +56,7 @@ private:

export class NonBlockPoolThriftServer {
public:
void Init(i32 port_no, i32 pool_size);
void Init(const String& server_address, i32 port_no, i32 pool_size);
void Start();
void Shutdown();

Expand Down
2 changes: 1 addition & 1 deletion src/storage/definition/index_hnsw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ String IndexHnsw::ToString() const {
String IndexHnsw::BuildOtherParamsString() const {
std::stringstream ss;
ss << "metric = " << MetricTypeToString(metric_type_) << ", encode_type = " << HnswEncodeTypeToString(encode_type_) << ", M = " << M_
<< ", ef_construction = " << ef_construction_ << ", block_size = " << block_size_;
<< ", ef_construction = " << ef_construction_;
return ss.str();
}

Expand Down

0 comments on commit 09396bf

Please sign in to comment.