The name of the initial branch for new projects is now "main" instead of "master". Existing projects remain unchanged. More information: https://doku.lrz.de/display/PUBLIC/GitLab

Commit d153944d authored by Michael Ott's avatar Michael Ott
Browse files

Whitelist only the specified Cassandra server for connections

parent 29777058
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <iostream> #include <iostream>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <boost/asio.hpp>
#include "cassandra.h" #include "cassandra.h"
...@@ -391,12 +392,27 @@ bool ConnectionImpl::connect() { ...@@ -391,12 +392,27 @@ bool ConnectionImpl::connect() {
if (username_.size() && password_.size()) { if (username_.size() && password_.size()) {
cass_cluster_set_credentials(cluster, username_.c_str(), password_.c_str()); cass_cluster_set_credentials(cluster, username_.c_str(), password_.c_str());
} }
cass_cluster_set_num_threads_io(cluster, numThreadsIo); cass_cluster_set_num_threads_io(cluster, numThreadsIo);
cass_cluster_set_queue_size_io(cluster, queueSizeIo); cass_cluster_set_queue_size_io(cluster, queueSizeIo);
cass_cluster_set_core_connections_per_host(cluster, coreConnPerHost); cass_cluster_set_core_connections_per_host(cluster, coreConnPerHost);
cass_cluster_set_request_timeout(cluster, 60000); cass_cluster_set_request_timeout(cluster, 60000);
boost::asio::io_service io_service;
boost::asio::ip::tcp::resolver resolver(io_service);
boost::asio::ip::tcp::resolver::query query(hostname_, std::to_string(port_));
boost::asio::ip::tcp::resolver::iterator iter = resolver.resolve(query);
boost::asio::ip::tcp::resolver::iterator end;
std::string whitelist;
while (iter != end) {
if (whitelist.size() > 0) {
whitelist.append(",");
}
whitelist.append(iter->endpoint().address().to_string());
iter++;
}
cass_cluster_set_whitelist_filtering(cluster, whitelist.c_str());
/* Force protcol version to 4 */ /* Force protcol version to 4 */
cass_cluster_set_protocol_version(cluster, 4); cass_cluster_set_protocol_version(cluster, 4);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment