[feat] use argv to set certs dir

This commit is contained in:
dijunkun
2025-09-08 18:53:14 +08:00
parent 8b0dd95e2f
commit 94cee80cc6
4 changed files with 30 additions and 7 deletions

View File

@@ -15,6 +15,14 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
- name: Cache xmake dependencies
uses: actions/cache@v4
with:
path: ~/.xmake/packages
key: ${{ runner.os }}-xmake-deps-linux-${{ hashFiles('**/xmake.lua') }}
restore-keys: |
${{ runner.os }}-xmake-deps-linux-
- name: Install dependencies
run: |
sudo apt update

View File

@@ -13,20 +13,26 @@
#include "signal_server.h"
int main(int argc, char* argv[]) {
SignalServer s;
std::string port = "9090";
std::string log_dir = "./logs";
std::string certs_dir = "./cert";
if (argc > 1) {
port = argv[1];
}
if (argc > 2) {
log_dir = argv[2];
certs_dir = argv[2];
}
if (argc > 3) {
log_dir = argv[3];
}
InitLogger(log_dir);
s.Run(std::stoi(port));
SignalServer s;
s.Run(std::stoi(port), certs_dir);
return 0;
}

View File

@@ -73,8 +73,10 @@ context_ptr SignalServer::OnTlsInit(websocketpp::connection_hdl hdl) {
asio::ssl::context::default_workarounds | asio::ssl::context::no_sslv2 |
asio::ssl::context::no_sslv3 | asio::ssl::context::single_dh_use);
ctx->use_certificate_chain_file("cert/crossdesk.cn_bundle.crt");
ctx->use_private_key_file("cert/crossdesk.cn.key", asio::ssl::context::pem);
std::string cert_file = certs_dir_ + "/crossdesk.cn.crt";
std::string key_file = certs_dir_ + "/crossdesk.cn.key";
ctx->use_certificate_chain_file(cert_file);
ctx->use_private_key_file(key_file, asio::ssl::context::pem);
SSL_CTX_set_cipher_list(ctx->native_handle(),
"ECDHE-ECDSA-AES256-GCM-SHA384:"
@@ -96,7 +98,13 @@ bool SignalServer::OnPong(websocketpp::connection_hdl hdl, std::string s) {
return true;
}
void SignalServer::Run(uint16_t port) {
void SignalServer::Run(uint16_t port, std::string certs_dir) {
certs_dir_ = certs_dir;
if (!std::filesystem::exists(certs_dir_)) {
LOG_ERROR("Certs dir [{}] not exist", certs_dir_);
return;
}
server_.set_reuse_addr(true);
LOG_INFO("Signal server runs on port [{}]", port);

View File

@@ -35,12 +35,13 @@ class SignalServer {
bool OnPing(websocketpp::connection_hdl hdl, std::string s);
bool OnPong(websocketpp::connection_hdl hdl, std::string s);
void Run(uint16_t port);
void Run(uint16_t port, std::string certs_dir);
void SendMsg(websocketpp::connection_hdl hdl, json message);
void OnMessage(websocketpp::connection_hdl hdl, server::message_ptr msg);
private:
server server_;
std::string certs_dir_;
std::map<websocketpp::connection_hdl, connection_id,
std::owner_less<websocketpp::connection_hdl>>
ws_connections_;