Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences
C++ algoliadatastoreelasticsearchenterprise-searchfacetingfull-text-searchfuzzy-searchgeosearchin-memoryinstantsearchmerchandisingpineconesearchsearch-enginesemantic-searchsimilarity-searchsite-searchsynonymstypo-tolerancevector-search
HTTPS is now supported!
Kishore Nallan42d0c3114001
diff --git a/.gitignore b/.gitignoreindex 9098d07d..2734a815 100644--- a/.gitignore+++ b/.gitignore@@ -3,4 +3,5 @@external*buildcmake-build-debug-cmake-build-release\ No newline at end of file+cmake-build-release+*.pem\ No newline at end of filediff --git a/TODO.md b/TODO.mdindex 2b18da8a..5a2d8a49 100644--- a/TODO.md+++ b/TODO.md@@ -72,6 +72,7 @@- ~~change "search_by" to "query_by"~~- ~~during index_in_memory() validations should be front loaded~~- ~~Support token ranking field being a float~~+- ~~https support~~- get collection should show schema- highlight of string arrays?- NOT operator support@@ -80,7 +81,6 @@- Test for snippets- Test for replication- Proper logging-- https support- Validate before string to int conversion in the http api layer- > INT32_MAX validation for float field- art bool supportdiff --git a/include/http_client.h b/include/http_client.hindex 8c941f7f..c7e99372 100644--- a/include/http_client.h+++ b/include/http_client.h@@ -23,6 +23,7 @@ public:long get_reponse(std::string & response) {CURL *curl = curl_easy_init();curl_easy_setopt(curl, CURLOPT_URL, url.c_str());+ curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); // to allow self-signed certscurl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, HttpClient::curl_write);curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);diff --git a/include/http_server.h b/include/http_server.hindex b0b2a7c3..e4cc74b5 100644--- a/include/http_server.h+++ b/include/http_server.h@@ -40,8 +40,14 @@ private:const uint32_t listen_port;+ std::string ssl_cert_path;++ std::string ssl_cert_key_path;+static void on_accept(h2o_socket_t *listener, const char *err);+ int setup_ssl(const char *cert_file, const char *key_file);+int create_listener();h2o_pathconf_t *register_handler(h2o_hostconf_t *hostconf, const char *path,@@ -60,7 +66,8 @@ private:static constexpr const char* SEND_RESPONSE_MSG = "send_response";public:- HttpServer(std::string listen_address, uint32_t listen_port);+ HttpServer(std::string listen_address, uint32_t listen_port,+ std::string ssl_cert_path, std::string ssl_cert_key_path);~HttpServer();diff --git a/include/replicator.h b/include/replicator.hindex 1dbcc7ce..e7d3dfbd 100644--- a/include/replicator.h+++ b/include/replicator.h@@ -115,6 +115,9 @@ public:rocksdb::WriteBatch write_batch(update_decoded);store._get_db_unsafe()->Write(rocksdb::WriteOptions(), &write_batch);}+ } else {+ std::cout << "Replication error while fetching records from master, status_code="+ << status_code << std::endl;}std::this_thread::sleep_for(std::chrono::milliseconds(3000));diff --git a/src/http_server.cpp b/src/http_server.cppindex 5ddc4ffc..77c6dbca 100644--- a/src/http_server.cpp+++ b/src/http_server.cpp@@ -18,8 +18,10 @@ struct h2o_custom_res_message_t {void* data;};-HttpServer::HttpServer(std::string listen_address, uint32_t listen_port):- listen_address(listen_address), listen_port(listen_port) {+HttpServer::HttpServer(std::string listen_address, uint32_t listen_port,+ std::string ssl_cert_path, std::string ssl_cert_key_path):+ listen_address(listen_address), listen_port(listen_port),+ ssl_cert_path(ssl_cert_path), ssl_cert_key_path(ssl_cert_key_path) {accept_ctx = new h2o_accept_ctx_t();h2o_config_init(&config);hostconf = h2o_config_register_host(&config, h2o_iovec_init(H2O_STRLIT("default")), 65535);@@ -41,10 +43,53 @@ void HttpServer::on_accept(h2o_socket_t *listener, const char *err) {h2o_accept(http_server->accept_ctx, sock);}+int HttpServer::setup_ssl(const char *cert_file, const char *key_file) {+ SSL_load_error_strings();+ SSL_library_init();++ accept_ctx->ssl_ctx = SSL_CTX_new(SSLv23_server_method());++ // As recommended by:+ // https://github.com/ssllabs/research/wiki/SSL-and-TLS-Deployment-Best-Practices#23-use-secure-cipher-suites+ SSL_CTX_set_cipher_list(accept_ctx->ssl_ctx, "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:"+ "ECDHE-ECDSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA256:ECDHE-ECDSA-AES256-SHA384:"+ "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:"+ "ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:"+ "DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA256");++ // Without this, DH and ECDH ciphers will be ignored by OpenSSL+ int nid = NID_X9_62_prime256v1;+ EC_KEY *key = EC_KEY_new_by_curve_name(nid);+ if (key == NULL) {+ std::cout << "Failed to create DH/ECDH." << std::endl;+ return -1;+ }+ SSL_CTX_set_tmp_ecdh(accept_ctx->ssl_ctx, key);+ EC_KEY_free(key);++ SSL_CTX_set_options(accept_ctx->ssl_ctx, SSL_OP_NO_SSLv2);++ if (SSL_CTX_use_certificate_file(accept_ctx->ssl_ctx, cert_file, SSL_FILETYPE_PEM) != 1) {+ std::cout << "An error occurred while trying to load server certificate file:" << cert_file << std::endl;+ return -1;+ }+ if (SSL_CTX_use_PrivateKey_file(accept_ctx->ssl_ctx, key_file, SSL_FILETYPE_PEM) != 1) {+ std::cout << "An error occurred while trying to load private key file: " << key_file << std::endl;+ return -1;+ }++ h2o_ssl_register_alpn_protocols(accept_ctx->ssl_ctx, h2o_http2_alpn_protocols);+ return 0;+}+int HttpServer::create_listener(void) {struct sockaddr_in addr;int fd, reuseaddr_flag = 1;+ if(!ssl_cert_path.empty() && !ssl_cert_key_path.empty()) {+ setup_ssl(ssl_cert_path.c_str(), ssl_cert_key_path.c_str());+ }+accept_ctx->ctx = &ctx;accept_ctx->hosts = config.hosts;diff --git a/src/main/typesense_server.cpp b/src/main/typesense_server.cppindex 51ee2305..e88f9576 100644--- a/src/main/typesense_server.cpp+++ b/src/main/typesense_server.cpp@@ -20,11 +20,15 @@ void catch_interrupt(int sig) {int main(int argc, char **argv) {cmdline::parser options;options.add<std::string>("data-dir", 'd', "Directory where data will be stored.", true);- options.add<std::string>("api-auth-key", 'k', "Key for authenticating the API endpoints.", true);- options.add<std::string>("listen-address", 'a', "Address to which Typesense server binds.", false, "0.0.0.0");+ options.add<std::string>("api-auth-key", 'a', "Key for authenticating the API endpoints.", true);+ options.add<std::string>("listen-address", 'h', "Address to which Typesense server binds.", false, "0.0.0.0");options.add<uint32_t>("listen-port", 'p', "Port on which Typesense server listens.", false, 8108);- options.add<std::string>("master", 'm', "<master_address>:<master_port> combination to start the server as a "- "read-only replica.", false, "");+ options.add<std::string>("master", 'm', "Master host in http(s)://<master_address>:<master_port> format "+ "to start the server as a read-only replica.", false, "");++ options.add<std::string>("ssl-certificate", 'c', "Path to the SSL certificate file.", false, "");+ options.add<std::string>("ssl-certificate-key", 'k', "Path to the SSL certificate key file.", false, "");+options.parse_check(argc, argv);signal(SIGINT, catch_interrupt);@@ -42,7 +46,9 @@ int main(int argc, char **argv) {server = new HttpServer(options.get<std::string>("listen-address"),- options.get<uint32_t>("listen-port")+ options.get<uint32_t>("listen-port"),+ options.get<std::string>("ssl-certificate"),+ options.get<std::string>("ssl-certificate-key"));// collection management@@ -68,8 +74,8 @@ int main(int argc, char **argv) {const std::string & master_host_port = options.get<std::string>("master");std::vector<std::string> parts;StringUtils::split(master_host_port, parts, ":");- if(parts.size() != 2) {- std::cerr << "Invalid value for --master option. Usage: <master_address>:<master_port>" << std::endl;+ if(parts.size() != 3) {+ std::cerr << "Invalid value for --master option. Usage: http(s)://<master_address>:<master_port>" << std::endl;return 1;}