-
Notifications
You must be signed in to change notification settings - Fork 9
feat(wish/cpp): split TLS implementation from the example server/client #19
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 |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # WiSH C++ Implementation | ||
|
|
||
| This directory contains a C++ implementation of WiSH protocol together with a thin TLS stack enabling mTLS. | ||
|
|
||
| # Development Conventions | ||
|
|
||
| ## Coding style | ||
|
|
||
| We basically follow [Google C++ style guide](https://google.github.io/styleguide/cppguide.html). |
|
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. adding a very simple base for benchmarking |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| #include <chrono> | ||
| #include <iostream> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| #include "../src/tls_client.h" | ||
| #include "../src/wish_handler.h" | ||
|
|
||
| int main() { | ||
| TlsClient client("../certs/ca.crt", "../certs/client.crt", | ||
| "../certs/client.key", "127.0.0.1", 8080); | ||
|
|
||
| if (!client.Init()) { | ||
| std::cerr << "Failed to initialize client" << std::endl; | ||
| return 1; | ||
| } | ||
|
|
||
| const int kTotalMessages = 1000; | ||
| int messages_received = 0; | ||
| auto start_time = std::chrono::high_resolution_clock::now(); | ||
|
|
||
| client.SetOnOpen([&start_time, kTotalMessages](WishHandler* handler) { | ||
| std::cout << "Connected! Starting benchmark..." << std::endl; | ||
|
|
||
| start_time = std::chrono::high_resolution_clock::now(); | ||
|
|
||
| for (int i = 0; i < kTotalMessages; ++i) { | ||
| handler->SendText("Benchmark message " + std::to_string(i)); | ||
| } | ||
| }); | ||
|
|
||
| client.SetOnMessage([&messages_received, kTotalMessages, | ||
| &start_time](uint8_t opcode, const std::string& msg) { | ||
| messages_received++; | ||
| if (messages_received == kTotalMessages) { | ||
| auto end_time = std::chrono::high_resolution_clock::now(); | ||
| auto duration = std::chrono::duration_cast<std::chrono::milliseconds>( | ||
| end_time - start_time); | ||
| std::cout << "Benchmark complete: Received " << kTotalMessages | ||
| << " messages in " << duration.count() << " ms." << std::endl; | ||
| exit(0); | ||
| } | ||
| }); | ||
|
|
||
| client.Run(); | ||
|
|
||
| return 0; | ||
| } |
This file was deleted.
|
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. renamed to clarify that this is an echo server implementation |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| #include <iostream> | ||
| #include <string> | ||
|
|
||
| #include "../src/tls_server.h" | ||
| #include "../src/wish_handler.h" | ||
|
|
||
| int main(int argc, char** argv) { | ||
| int port = 8080; | ||
|
|
||
| TlsServer server("../certs/ca.crt", "../certs/server.crt", | ||
| "../certs/server.key", port); | ||
|
|
||
| if (!server.Init()) { | ||
| std::cerr << "Failed to initialize server" << std::endl; | ||
| return 1; | ||
| } | ||
|
|
||
| server.SetOnConnection([](struct bufferevent* bev) { | ||
| std::cout << "Client connected." << std::endl; | ||
|
|
||
| WishHandler* handler = new WishHandler(bev, true); | ||
|
|
||
| handler->SetOnMessage([handler](uint8_t opcode, const std::string& msg) { | ||
| std::string type; | ||
| switch (opcode) { | ||
| case WISH_OPCODE_TEXT: | ||
| type = "TEXT"; | ||
| break; | ||
| case WISH_OPCODE_BINARY: | ||
| type = "BINARY"; | ||
| break; | ||
| case WISH_OPCODE_TEXT_METADATA: | ||
| type = "TEXT_METADATA"; | ||
| break; | ||
| case WISH_OPCODE_BINARY_METADATA: | ||
| type = "BINARY_METADATA"; | ||
| break; | ||
| default: | ||
| type = "UNKNOWN(" + std::to_string(opcode) + ")"; | ||
| break; | ||
| } | ||
| std::cout << "Received [" << type << "]: " << msg << std::endl; | ||
|
|
||
| // Echo back | ||
| if (opcode == WISH_OPCODE_TEXT) | ||
| handler->SendText(msg); | ||
|
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. changed to not prefixing received data with "Echo: " |
||
| else if (opcode == WISH_OPCODE_BINARY) | ||
| handler->SendBinary(msg); | ||
| else if (opcode == WISH_OPCODE_TEXT_METADATA) | ||
| handler->SendTextMetadata(msg); | ||
|
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. changed to echo back using the same opcode respectively |
||
| else if (opcode == WISH_OPCODE_BINARY_METADATA) | ||
| handler->SendBinaryMetadata(msg); | ||
| else { | ||
| std::cerr << "Unknown opcode, cannot echo." << std::endl; | ||
| } | ||
| }); | ||
|
|
||
| handler->Start(); | ||
| }); | ||
|
|
||
| server.Run(); | ||
|
|
||
| return 0; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| #include <iostream> | ||
| #include <string> | ||
|
|
||
| #include "../src/tls_client.h" | ||
| #include "../src/wish_handler.h" | ||
|
|
||
| int main() { | ||
| TlsClient client("../certs/ca.crt", "../certs/client.crt", | ||
| "../certs/client.key", "127.0.0.1", 8080); | ||
|
|
||
| if (!client.Init()) { | ||
| std::cerr << "Failed to initialize client" << std::endl; | ||
| return 1; | ||
| } | ||
|
|
||
| client.SetOnOpen([](WishHandler* handler) { | ||
| std::cout << "Connected and Handshake Complete!" << std::endl; | ||
|
|
||
| handler->SendText("Hello WiSH Text!"); | ||
| handler->SendBinary("Hello WiSH Binary!"); | ||
| handler->SendTextMetadata("Hello WiSH Metadata!"); | ||
| handler->SendBinaryMetadata("Hello WiSH Binary Metadata!"); | ||
| }); | ||
|
|
||
| client.SetOnMessage([](uint8_t opcode, const std::string& msg) { | ||
| std::string type; | ||
| switch (opcode) { | ||
| case WISH_OPCODE_TEXT: | ||
| type = "TEXT"; | ||
| break; | ||
| case WISH_OPCODE_BINARY: | ||
| type = "BINARY"; | ||
| break; | ||
| case WISH_OPCODE_TEXT_METADATA: | ||
| type = "TEXT_METADATA"; | ||
| break; | ||
| case WISH_OPCODE_BINARY_METADATA: | ||
| type = "BINARY_METADATA"; | ||
| break; | ||
| default: | ||
| type = "UNKNOWN(" + std::to_string(opcode) + ")"; | ||
| break; | ||
| } | ||
| std::cout << "Server says [" << type << "]: " << msg << std::endl; | ||
| }); | ||
|
|
||
| client.Run(); | ||
|
|
||
| return 0; | ||
| } |
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.
removing the
wish-prefix for now for simplicity