Skip to content
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

收到带确认的心跳再进入 CONNECTED 状态 #109

Merged
merged 1 commit into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/core/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -760,8 +760,13 @@ int Client::handleHeartbeatMessage(const UdpMessage &message) {
spdlog::debug("peer port does not match, update: old {:08x} new {:08x}", peer.ip, message.ip);
peer.port = message.port;
}
peer.count = 0;
peer.updateState(PeerState::CONNECTED);
if (!peer.ack) {
peer.ack = 1;
}
if (heartbeat->ack) {
peer.count = 0;
peer.updateState(PeerState::CONNECTED);
}
return 0;
}

Expand All @@ -771,6 +776,7 @@ int Client::sendHeartbeat(const PeerInfo &peer) {
heartbeat.tun = Address::hostToNet(this->tun.getIP());
heartbeat.ip = Address::hostToNet(this->selfInfo.ip);
heartbeat.port = Address::hostToNet(this->selfInfo.port);
heartbeat.ack = peer.ack;

UdpMessage message;
message.ip = peer.ip;
Expand Down
1 change: 1 addition & 0 deletions src/core/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ struct PeerHeartbeatMessage {
uint32_t tun;
uint32_t ip;
uint16_t port;
uint8_t ack;
} __attribute__((packed));

struct PeerRawIPv4Message {
Expand Down
1 change: 1 addition & 0 deletions src/peer/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ void PeerInfo::reset() {
this->ip = 0;
this->port = 0;
this->count = 0;
this->ack = 0;
this->key.clear();
}

Expand Down
1 change: 1 addition & 0 deletions src/peer/peer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class PeerInfo {
uint32_t ip;
uint16_t port;
uint32_t count;
uint8_t ack;

void reset();
int updateKey(const std::string &password);
Expand Down