-
Notifications
You must be signed in to change notification settings - Fork 9
feat(wish): make it able to run both TLS and non-TLS benchmark #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,10 +26,10 @@ | |
|
|
||
| ABSL_FLAG(std::string, host, "127.0.0.1", "Server host to connect to"); | ||
| ABSL_FLAG(int, port, 8080, "Server port to connect to"); | ||
| ABSL_FLAG(std::string, ca_cert, "../certs/ca.crt", "Path to CA certificate"); | ||
| ABSL_FLAG(std::string, client_cert, "../certs/client.crt", | ||
| ABSL_FLAG(std::string, ca_cert, "certs/ca.crt", "Path to CA certificate"); | ||
| ABSL_FLAG(std::string, client_cert, "certs/client.crt", | ||
| "Path to client certificate"); | ||
| ABSL_FLAG(std::string, client_key, "../certs/client.key", | ||
| ABSL_FLAG(std::string, client_key, "certs/client.key", | ||
|
Comment on lines
+29
to
+32
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. adjusting the default path |
||
| "Path to client private key"); | ||
|
|
||
| namespace { | ||
|
|
@@ -101,7 +101,10 @@ bool InitConnection(ClientState* client) { | |
| const int fd = bufferevent_getfd(client->bev); | ||
| if (fd >= 0) { | ||
| int nodelay = 1; | ||
| setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &nodelay, sizeof(nodelay)); | ||
| int result = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &nodelay, sizeof(nodelay)); | ||
| if (result != 0) { | ||
| LOG(FATAL) << "setsockopt(TCP_NODELAY) failed"; | ||
| } | ||
|
Comment on lines
+104
to
+107
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added return value check using this opportunity |
||
| } | ||
|
|
||
| client->connected = true; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,35 @@ | ||
| #include <iostream> | ||
| #include <string> | ||
|
|
||
| #include "../src/tls_server.h" | ||
| #include "../src/wish_handler.h" | ||
| #include "absl/flags/flag.h" | ||
| #include "absl/flags/parse.h" | ||
| #include "absl/log/initialize.h" | ||
| #include "absl/log/log.h" | ||
|
|
||
| ABSL_FLAG(int, port, 8080, "Port to listen on"); | ||
| ABSL_FLAG(std::string, ca_cert, "certs/ca.crt", "Path to CA certificate file"); | ||
| ABSL_FLAG(std::string, server_cert, "certs/server.crt", "Path to server certificate file"); | ||
| ABSL_FLAG(std::string, server_key, "certs/server.key", "Path to server private key file"); | ||
|
|
||
| int main(int argc, char** argv) { | ||
| int port = 8080; | ||
| absl::ParseCommandLine(argc, argv); | ||
| absl::InitializeLog(); | ||
|
|
||
| const int port = absl::GetFlag(FLAGS_port); | ||
| const std::string ca_cert = absl::GetFlag(FLAGS_ca_cert); | ||
| const std::string server_cert = absl::GetFlag(FLAGS_server_cert); | ||
| const std::string server_key = absl::GetFlag(FLAGS_server_key); | ||
|
|
||
| TlsServer server("../certs/ca.crt", "../certs/server.crt", | ||
| "../certs/server.key", port); | ||
| TlsServer server(ca_cert, server_cert, server_key, port); | ||
|
|
||
| if (!server.Init()) { | ||
| std::cerr << "Failed to initialize server" << std::endl; | ||
| LOG(ERROR) << "Failed to initialize server"; | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. switched to abseil logging library using this opportunity |
||
| return 1; | ||
| } | ||
|
|
||
| server.SetOnConnection([](struct bufferevent* bev) { | ||
| std::cout << "Client connected." << std::endl; | ||
| LOG(INFO) << "Client connected."; | ||
|
|
||
| WishHandler* handler = new WishHandler(bev, true); | ||
|
|
||
|
|
@@ -39,7 +52,7 @@ int main(int argc, char** argv) { | |
| type = "UNKNOWN(" + std::to_string(opcode) + ")"; | ||
| break; | ||
| } | ||
| std::cout << "Received [" << type << "]: " << msg << std::endl; | ||
| LOG(INFO) << "Received [" << type << "]: " << msg; | ||
|
|
||
| // Echo back | ||
| if (opcode == WISH_OPCODE_TEXT) | ||
|
|
@@ -51,7 +64,7 @@ int main(int argc, char** argv) { | |
| else if (opcode == WISH_OPCODE_BINARY_METADATA) | ||
| handler->SendBinaryMetadata(msg); | ||
| else { | ||
| std::cerr << "Unknown opcode, cannot echo." << std::endl; | ||
| LOG(WARNING) << "Unknown opcode, cannot echo."; | ||
| } | ||
| }); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,18 @@ | ||
| #include "tls_server.h" | ||
|
|
||
| #include <iostream> | ||
| #include <cstring> | ||
| #include <arpa/inet.h> | ||
| #include <netinet/tcp.h> | ||
|
|
||
| #include <cstring> | ||
| #include <iostream> | ||
|
Comment on lines
+4
to
+7
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. automated reordering to comply with the Google C++ Style Guide |
||
|
|
||
| // To use BoringSSL | ||
| #define EVENT__HAVE_OPENSSL 1 | ||
| #include <event2/bufferevent_ssl.h> | ||
| #include <openssl/ssl.h> | ||
|
|
||
| TlsServer::TlsServer(const std::string& ca_file, const std::string& cert_file, | ||
| const std::string& key_file, int port) | ||
| const std::string& key_file, int port) | ||
| : ca_file_(ca_file), | ||
| cert_file_(cert_file), | ||
| key_file_(key_file), | ||
|
|
@@ -78,11 +80,16 @@ void TlsServer::SetOnConnection(ConnectCallback cb) { | |
| } | ||
|
|
||
| void TlsServer::AcceptConnCb(struct evconnlistener* listener, | ||
| evutil_socket_t fd, struct sockaddr* address, | ||
| int socklen, void* ctx) { | ||
| evutil_socket_t fd, struct sockaddr* address, | ||
| int socklen, void* ctx) { | ||
| struct event_base* base = evconnlistener_get_base(listener); | ||
| TlsServer* server = static_cast<TlsServer*>(ctx); | ||
|
|
||
| int one = 1; | ||
| if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one)) < 0) { | ||
| std::cerr << "Failed to set TCP_NODELAY: " << strerror(errno) << std::endl; | ||
| } | ||
|
|
||
| SSL* ssl = SSL_new(server->tls_ctx_.ssl_ctx()); | ||
| struct bufferevent* bev = bufferevent_openssl_socket_new( | ||
| base, fd, ssl, BUFFEREVENT_SSL_ACCEPTING, BEV_OPT_CLOSE_ON_FREE); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to send certs, too