Skip to content

Commit dc4f9a4

Browse files
authoredFeb 6, 2022
Merge pull request #700 from kiwix/ipLimit
Add method to change MHD_OPTION_PER_IP_CONNECTION_LIMIT
2 parents ce24b1f + 261adf0 commit dc4f9a4

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed
 

‎include/server.h

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ namespace kiwix
5454
void setAddress(const std::string& addr) { m_addr = addr; }
5555
void setPort(int port) { m_port = port; }
5656
void setNbThreads(int threads) { m_nbThreads = threads; }
57+
void setIpConnectionLimit(int limit) { m_ipConnectionLimit = limit; }
5758
void setVerbose(bool verbose) { m_verbose = verbose; }
5859
void setIndexTemplateString(const std::string& indexTemplateString) { m_indexTemplateString = indexTemplateString; }
5960
void setTaskbar(bool withTaskbar, bool withLibraryButton)
@@ -75,6 +76,7 @@ namespace kiwix
7576
bool m_withTaskbar = true;
7677
bool m_withLibraryButton = true;
7778
bool m_blockExternalLinks = false;
79+
int m_ipConnectionLimit = 0;
7880
std::unique_ptr<InternalServer> mp_server;
7981
};
8082
}

‎src/server.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ bool Server::start() {
4949
m_withTaskbar,
5050
m_withLibraryButton,
5151
m_blockExternalLinks,
52-
m_indexTemplateString));
52+
m_indexTemplateString,
53+
m_ipConnectionLimit));
5354
return mp_server->start();
5455
}
5556

‎src/server/internalServer.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ InternalServer::InternalServer(Library* library,
120120
bool withTaskbar,
121121
bool withLibraryButton,
122122
bool blockExternalLinks,
123-
std::string indexTemplateString) :
123+
std::string indexTemplateString,
124+
int ipConnectionLimit) :
124125
m_addr(addr),
125126
m_port(port),
126127
m_root(normalizeRootUrl(root)),
@@ -130,6 +131,7 @@ InternalServer::InternalServer(Library* library,
130131
m_withLibraryButton(withLibraryButton),
131132
m_blockExternalLinks(blockExternalLinks),
132133
m_indexTemplateString(indexTemplateString.empty() ? RESOURCE::templates::index_html : indexTemplateString),
134+
m_ipConnectionLimit(ipConnectionLimit),
133135
mp_daemon(nullptr),
134136
mp_library(library),
135137
mp_nameMapper(nameMapper ? nameMapper : &defaultNameMapper)
@@ -168,6 +170,7 @@ bool InternalServer::start() {
168170
this,
169171
MHD_OPTION_SOCK_ADDR, &sockAddr,
170172
MHD_OPTION_THREAD_POOL_SIZE, m_nbThreads,
173+
MHD_OPTION_PER_IP_CONNECTION_LIMIT, m_ipConnectionLimit,
171174
MHD_OPTION_END);
172175
if (mp_daemon == nullptr) {
173176
std::cerr << "Unable to instantiate the HTTP daemon. The port " << m_port

‎src/server/internalServer.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ class InternalServer {
5555
bool withTaskbar,
5656
bool withLibraryButton,
5757
bool blockExternalLinks,
58-
std::string indexTemplateString);
58+
std::string indexTemplateString,
59+
int ipConnectionLimit);
5960
virtual ~InternalServer() = default;
6061

6162
MHD_Result handlerCallback(struct MHD_Connection* connection,
@@ -108,6 +109,7 @@ class InternalServer {
108109
bool m_withLibraryButton;
109110
bool m_blockExternalLinks;
110111
std::string m_indexTemplateString;
112+
int m_ipConnectionLimit;
111113
struct MHD_Daemon* mp_daemon;
112114

113115
Library* mp_library;

0 commit comments

Comments
 (0)
Please sign in to comment.