Skip to content

PasteFerry (隔空贴): clipboard and file sync across macOS, Windows and Linux. Direct-first, end-to-end encrypted. Optional official access: no server to host. Independent self-hosting remains available.

fix(core): answer retried pairing intent exchanges

baiyuzeac424b1be1c5
diff --git a/client-core/internal/peers/friends.go b/client-core/internal/peers/friends.go
index 440a711..372a9cc 100644
--- a/client-core/internal/peers/friends.go
+++ b/client-core/internal/peers/friends.go
@@ -563,14 +563,19 @@ func (m *Manager) handlePairIntent(from string, in *pb.PairIntent) {
m.mu.Unlock()
return
}
- first := p.peerIntent == ""
+ // The first reply can arrive before the other side records its session.
+ // Answer retries too, while limiting replies so they cannot echo forever.
+ now := time.Now()
+ reply := now.Sub(p.intentReplyAt) >= time.Second
+ if reply {
+ p.intentReplyAt = now
+ }
p.peerIntent = intent
if in.GetCard() != nil {
p.peerCard = cleanCard(in.GetCard())
}
m.mu.Unlock()
- if first {
- // 对方可能还没收到本端的,回一条
+ if reply {
go m.sendIntent(p)
}
m.evaluateIntent(p)
diff --git a/client-core/internal/peers/manager.go b/client-core/internal/peers/manager.go
index b3b524a..31bc52d 100644
--- a/client-core/internal/peers/manager.go
+++ b/client-core/internal/peers/manager.go
@@ -48,12 +48,13 @@ type pendingPair struct {
// 这次是配对还是加好友(lan.IntentDevice / lan.IntentFriend),对方的用途(不知道时为空)
// 和名片。两边的用途一致才继续,见 friends.go
- intent string
- peerIntent string
- peerCard *pb.FriendCard
- intentKnown chan struct{} // 知道对方的用途后关闭
- intentDone bool
- mismatch error
+ intent string
+ peerIntent string
+ peerCard *pb.FriendCard
+ intentKnown chan struct{} // 知道对方的用途后关闭
+ intentDone bool
+ intentReplyAt time.Time
+ mismatch error
// 加好友:两边的用户各自点了「添加」(1)或「取消」(-1)
localDecision int
peerDecision int