Skip to content

Commit

Permalink
修正注释
Browse files Browse the repository at this point in the history
  • Loading branch information
lanthora committed Apr 23, 2024
1 parent 319ad0f commit 4ea90f7
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 34 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 构建的命令行版本.用户可以在此基础上自行定制.

Expand Down
36 changes: 16 additions & 20 deletions scripts/search-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <PATH> [DESTINATION]"
if [ -z "$2" ]; then
echo "Usage: $0 <PATH> <DESTINATION>"
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"
2 changes: 1 addition & 1 deletion src/cffi/candy.cc
Original file line number Diff line number Diff line change
@@ -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 <spdlog/sinks/rotating_file_sink.h>
#include <spdlog/spdlog.h>
#include <stdlib.h>

Expand Down
12 changes: 7 additions & 5 deletions src/core/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ void Client::handleLocalPeerConnMessage(WebSocketMessage &message) {
}
}

// 调用这个函数是需要确保双方同时调用.
// 需要确保双方同时调用.
// 1. 收到对方报文时,一般会回包,此时调用
// 2. 收到主动发现报文时,这时一定会回包
void Client::tryDirectConnection(uint32_t ip) {
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -1204,7 +1206,7 @@ int Client::updateRouteTable(RouteEntry entry) {

std::unique_lock lock(this->rtTableMutex);

// 拿到的到达此目的地址的历史路由,下一跳可能不同
// 到达此目的地址的历史路由,下一跳可能不同
auto oldEntry = this->rtTable.find(entry.dst);

// 本机检测到连接断开,删除所有以断联设备作为下一跳的路由并广播
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/core/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 地址,向服务端要求强制使用这个地址,使用相同地址的前一个设备会被踢出网络
Expand Down
2 changes: 1 addition & 1 deletion src/core/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

namespace Candy {

// 出现内部异常时调用,调整进程退出码为 1, 并模拟产生 SIGTERM, 进程将回收资源并退出
// 出现内部异常时调用
void shutdown(Client *client);
void shutdown(Server *client);

Expand Down

0 comments on commit 4ea90f7

Please sign in to comment.