Skip to content

Commit

Permalink
收到带确认的心跳再进入 CONNECTED 状态
Browse files Browse the repository at this point in the history
  • Loading branch information
lanthora committed Sep 8, 2023
1 parent 13c1458 commit 26720be
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
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

0 comments on commit 26720be

Please sign in to comment.