From 4ea90f7fd99e8696e4643615abbe33c5824275c7 Mon Sep 17 00:00:00 2001 From: lanthora Date: Tue, 23 Apr 2024 09:47:14 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yaml | 3 +-- README.md | 4 +--- scripts/search-deps.sh | 36 +++++++++++++++------------------- src/cffi/candy.cc | 2 +- src/core/client.cc | 12 +++++++----- src/core/client.h | 4 ++-- src/core/common.h | 2 +- 7 files changed, 29 insertions(+), 34 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 96f6ff8..5c41452 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -68,9 +68,8 @@ jobs: cmake -B build -DCMAKE_BUILD_TYPE=Release && cmake --build build mkdir artifact cp candy.conf artifact - cp build/src/main/candy.exe artifact cp build/src/tun/wintun/bin/amd64/wintun.dll artifact - scripts/search-deps.sh artifact/candy.exe artifact + scripts/search-deps.sh build/src/main/candy.exe artifact - name: set release package name shell: bash if: github.event_name == 'release' diff --git a/README.md b/README.md index 8d36fbc..fa72755 100644 --- a/README.md +++ b/README.md @@ -62,11 +62,9 @@ zypper refresh && zypper install candy 请参考 [Homebrew](https://github.com/lanthora/homebrew-repo) 仓库中提供的方法安装. -Mac 默认的睡眠策略是: 1.在关闭屏幕一段时间后睡眠; 2.睡眠时收到网络包唤醒. Candy 运行过程中每 30 秒产生一个心跳,这会导致机器被频繁唤醒.对于作为服务器长期开机的 Mac 设备来说,可以关闭睡眠功能;对于作为普通设备的笔记本来说,可以关闭网络唤醒功能.参考苹果官网[睡眠与唤醒](https://support.apple.com/zh-cn/guide/mac-help/mchle41a6ccd/mac)完成设置. - ### Windows -[Cake](https://github.com/lanthora/cake) 是将本项目作为依赖库构建的 GUI 版本,其 Release 中提供[安装包](https://github.com/lanthora/cake/releases/latest). +[Cake](https://github.com/lanthora/cake) 是将本项目作为依赖库构建的 GUI 版本,其 [Release](https://github.com/lanthora/cake/releases/latest) 中提供安装包. 在 [Release](https://github.com/lanthora/candy/releases/latest) 中提供了由 CI 构建的命令行版本.用户可以在此基础上自行定制. diff --git a/scripts/search-deps.sh b/scripts/search-deps.sh index 5c192f7..4434efb 100755 --- a/scripts/search-deps.sh +++ b/scripts/search-deps.sh @@ -18,42 +18,38 @@ recursive_search_deps () { continue fi - # If there are two arguments, copy the dependency to the specified directory - if [ "$#" -eq 2 ]; then - # Copy the dependency to the specified directory - cp "$dep" "$2" - # Output the copied file path and name - echo "Copied $dep to $2/" - else - # Show the dependency - echo "$dep" - fi + # Copy the dependency to the specified directory + cp -n "$dep" "$2" + # Output the copied file path and name + echo "Copied $dep to $2" # Add the dependency to the processed array processed+=("$dep") # Recursively call the function to process the dependency's dependencies - recursive_search_deps "$dep" ${2:-} + recursive_search_deps "$dep" "$2" fi done } # Check if the executable file is given as an argument -if [ -z "$1" ]; then - echo "Usage: $0 [DESTINATION]" +if [ -z "$2" ]; then + echo "Usage: $0 " exit 1 fi -# If there are two arguments, check if the directory exists before proceeding -if [ "$#" -eq 2 ]; then - if [ ! -d "$2" ]; then - echo "Error: Directory $2 does not exist." - exit 1 - fi +# Create the directory if it does not exist +if [ ! -d "$2" ]; then + mkdir -p $2 fi # Get the absolute path of the executable file exe=$(readlink -f "$1") +# Copy the executable file to the target directory +cp "$exe" "$2" +exe=$2/$(basename "$exe") +exe=$(readlink -f "$exe") + # Call the function to get the whole list of dependencies recursively -recursive_search_deps "$exe" ${2:-} +recursive_search_deps "$exe" "$2" diff --git a/src/cffi/candy.cc b/src/cffi/candy.cc index d2e9133..3ab3ec8 100644 --- a/src/cffi/candy.cc +++ b/src/cffi/candy.cc @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT #include "cffi/candy.h" #include "core/client.h" -#include "spdlog/sinks/rotating_file_sink.h" #include "utility/time.h" +#include #include #include diff --git a/src/core/client.cc b/src/core/client.cc index b532892..d6bb07b 100644 --- a/src/core/client.cc +++ b/src/core/client.cc @@ -593,7 +593,7 @@ void Client::handleLocalPeerConnMessage(WebSocketMessage &message) { } } -// 调用这个函数是需要确保双方同时调用. +// 需要确保双方同时调用. // 1. 收到对方报文时,一般会回包,此时调用 // 2. 收到主动发现报文时,这时一定会回包 void Client::tryDirectConnection(uint32_t ip) { @@ -736,7 +736,7 @@ void Client::tick() { for (auto &[ip, peer] : this->ipPeerMap) { switch (peer.getState()) { case PeerState::INIT: - // 收到对方通过服务器转发的数据的时候,会切换为 PREPARING,这里不做处理 + // 收到对方通过服务器转发的数据的时候,会切换为 PREPARING, 这里不做处理 break; case PeerState::PREPARING: @@ -1115,7 +1115,7 @@ int Client::handleHeartbeatMessage(const UdpMessage &message) { return -1; } - // 收到对端的心跳,检查地址,更新端口,并将状态调整为 CONNECTED + // 收到对端的心跳,更新地址和端口 PeerHeartbeatMessage *heartbeat = (PeerHeartbeatMessage *)message.buffer.c_str(); std::unique_lock lock(this->ipPeerMutex); uint32_t tun = Address::netToHost(heartbeat->tun); @@ -1134,12 +1134,14 @@ int Client::handleHeartbeatMessage(const UdpMessage &message) { spdlog::debug("heartbeat port mismatch: {} auth {} real {}", Address::ipToStr(tun), peer.port, message.port); peer.port = message.port; } + // 设置确认标识,下次向对方发送的心跳将携带确认标识 if (!peer.ack) { peer.ack = 1; } if (peer.getState() == PeerState::PREPARING) { sendHeartbeatMessage(peer, udpHolder.getDefaultIP(), udpHolder.getBindPort()); } + // 对方发来的心跳中包含确认标识,状态更新为 CONNECTED if (heartbeat->ack) { if (peer.getState() == PeerState::CONNECTED) { peer.count = 0; @@ -1204,7 +1206,7 @@ int Client::updateRouteTable(RouteEntry entry) { std::unique_lock lock(this->rtTableMutex); - // 拿到的到达此目的地址的历史路由,下一跳可能不同 + // 到达此目的地址的历史路由,下一跳可能不同 auto oldEntry = this->rtTable.find(entry.dst); // 本机检测到连接断开,删除所有以断联设备作为下一跳的路由并广播 @@ -1232,7 +1234,7 @@ int Client::updateRouteTable(RouteEntry entry) { return 0; } - // 收到设备断联广播,删除本机相同的路由并广播 + // 收到设备断连广播,删除本机相同的路由并广播 if (!isDirect && isDelete) { if (oldEntry != this->rtTable.end() && oldEntry->second.next == entry.next) { oldEntry->second.delay = DELAY_LIMIT; diff --git a/src/core/client.h b/src/core/client.h index e965679..d8b450a 100644 --- a/src/core/client.h +++ b/src/core/client.h @@ -34,10 +34,10 @@ class Client { int setName(const std::string &name); std::string getName() const; - // 连接 websocket 服务端时身份认证的密码 + // 连接 websocket 服务端时身份认证的口令 int setPassword(const std::string &password); - // 用于数据转发的服务端地址 + // 用于数据转发和对等连接控制的服务端地址 int setWebSocketServer(const std::string &server); // TUN 地址,向服务端要求强制使用这个地址,使用相同地址的前一个设备会被踢出网络 diff --git a/src/core/common.h b/src/core/common.h index d054349..df16064 100644 --- a/src/core/common.h +++ b/src/core/common.h @@ -27,7 +27,7 @@ namespace Candy { -// 出现内部异常时调用,调整进程退出码为 1, 并模拟产生 SIGTERM, 进程将回收资源并退出 +// 出现内部异常时调用 void shutdown(Client *client); void shutdown(Server *client);