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.
Dart airdrop-alternativeclipboardclipboard-sharingclipboard-synccopy-pastecross-platformend-to-end-encryptionfile-syncfile-transferfluttergolanglinuxmacosnat-traversalp2pself-hostedtailscaleuniversal-clipboardwebrtcwindows
fix(core): resume official relay after an allowance increase
baiyuze2f2d2839a203
diff --git a/client-core/internal/transport/p2p/official.go b/client-core/internal/transport/p2p/official.goindex 523842d..ba43760 100644--- a/client-core/internal/transport/p2p/official.go+++ b/client-core/internal/transport/p2p/official.go@@ -277,6 +277,17 @@ func directICEServers(servers []webrtc.ICEServer) []webrtc.ICEServer {return out}func (m *Manager) officialFailed(id string, a *officialAttempt, err error) {+ // A tunnel reports quota closure before ICE notices the disconnected+ // transport. Preserve that reason so a later allowance increase can clear+ // the cooldown and notify the peer, rather than waiting until midnight.+ var quotaError *gateway.Error+ if !errors.As(err, "aError) {+ u := m.gateway.Usage()+ switch u.Reason {+ case "quota_exhausted", "global_exhausted", "global_paused", "relay_blocked", "device_banned":+ err = &gateway.Error{Code: u.Reason, Usage: &u}+ }+ }m.mu.Lock()if m.relays[id] == a {var ge *gateway.Error@@ -285,7 +296,7 @@ func (m *Manager) officialFailed(id string, a *officialAttempt, err error) {}u := m.gateway.Usage()a.failedUntil = time.Now().Add(time.Minute)- if u.ResetAt > time.Now().Unix() && (u.Reason == "quota_exhausted" || u.Reason == "global_exhausted" || u.Reason == "peer_quota_exhausted") {+ if u.ResetAt > time.Now().Unix() && (a.failReason == "quota_exhausted" || a.failReason == "global_exhausted" || a.failReason == "peer_quota_exhausted") {a.failedUntil = time.Unix(u.ResetAt, 0)}}diff --git a/client-core/internal/transport/p2p/official_test.go b/client-core/internal/transport/p2p/official_test.goindex 73f293a..9b7534e 100644--- a/client-core/internal/transport/p2p/official_test.go+++ b/client-core/internal/transport/p2p/official_test.go@@ -3,6 +3,7 @@ package p2pimport ("context""crypto/sha256"+ "errors""fmt""net""net/http"@@ -113,6 +114,29 @@ func TestOfficialDirectNeverRequestsGateway(t *testing.T) {t.Fatal("direct path contacted relay authorization")}}++func TestOfficialQuotaRecoveryAfterTransportClosure(t *testing.T) {+ id := identity.FromSeed(make([]byte, 32))+ c, err := gateway.NewClient(id, "http://127.0.0.1:1", nil)+ if err != nil {+ t.Fatal(err)+ }+ defer c.Close()+ c.ReportError(&gateway.Error{Code: "quota_exhausted", Usage: &gateway.Usage{Available: true, Reason: "quota_exhausted", ResetAt: time.Now().Add(time.Hour).Unix()}})+ m := NewManager(ManagerOptions{SelfID: id.DeviceID, Gateway: c, Official: func() bool { return true }, DisableEgressProbe: true, SendSignal: func(context.Context, string, *pb.SignalMessage) error { return nil }})+ defer m.Close()+ ctx, cancel := context.WithCancel(context.Background())+ a := &officialAttempt{id: "attempt", ctx: ctx, cancel: cancel}+ m.relays["peer"] = a+ m.officialFailed("peer", a, errors.New("relay connection closed"))+ if a.failReason != "quota_exhausted" {+ t.Fatalf("lost closure reason: %q", a.failReason)+ }+ m.OfficialAllowanceChanged()+ if !a.failedUntil.IsZero() || a.failReason != "" {+ t.Fatal("new allowance did not permit a retry")+ }+}func TestOfficialDirectThenGatewayTURN(t *testing.T) {binary := os.Getenv("PF_GATEWAY_TEST_BINARY")if binary == "" {