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): don't call a peer outdated before it has connected

baiyuze501341b40030
diff --git a/client-core/cmd/pasteferryd/main.go b/client-core/cmd/pasteferryd/main.go
index dd30b89..a662e73 100644
--- a/client-core/cmd/pasteferryd/main.go
+++ b/client-core/cmd/pasteferryd/main.go
@@ -288,6 +288,7 @@ func run(dataDir string) error {
Store: db,
LoadConfig: loadCfg,
StatePath: filepath.Join(paths.Root, "egress.json"),
+ AppVersion: version,
OnDeviceChanged: func(d *pb.Device) {
hub.Publish(rpc.EventDeviceChanged(d))
},
diff --git a/client-core/internal/peers/manager.go b/client-core/internal/peers/manager.go
index 82a55d7..d2bf275 100644
--- a/client-core/internal/peers/manager.go
+++ b/client-core/internal/peers/manager.go
@@ -16,6 +16,7 @@ import (
"net/http"
"net/netip"
"runtime"
+ "sort"
"sync"
"time"
@@ -89,9 +90,19 @@ type Manager struct {
// serverOnline 是信令服务器报告的在线状态;局域网的在线状态在 lan 里
serverOnline map[string]bool
conn map[string]p2p.ConnState // P2P 连接状态(直连/中转)
- // features 是对端在 PeerFeatures 里声明的功能,见 wire.proto。没收到过的设备没有条目
+ // features 是对端在 PeerFeatures 里声明的功能,见 wire.proto。没收到过的设备没有条目。
+ // 启动时从数据库读回上次的声明,所以重启后不必等连上就知道对方支持什么
features map[string]map[string]bool
- pending map[string]*pendingPair // session -> 待确认配对
+ // peerVersion 是对端声明里带的版本号(2.5.4 起),旧版本没有
+ peerVersion map[string]string
+ // declared 记下本次连接里对端是否发过声明;legacy 是连上 legacyWait 后仍没声明、判定为旧版本的设备
+ declared map[string]bool
+ legacy map[string]bool
+ // appVersion 是本机的版本号,随功能声明发给对端
+ appVersion string
+ // noFeatures 让测试模拟不发功能声明的旧版本
+ noFeatures bool
+ pending map[string]*pendingPair // session -> 待确认配对
// stashed 暂存配对确认前到达的信令,按对端 device_id 归集
stashed map[string][]*pb.SignalMessage
active *activeCode
@@ -124,8 +135,14 @@ type Options struct {
// LANPort / LANDiscovery 供测试替换局域网通道的端口和发现方式,默认 8788 与 mDNS
LANPort int
LANDiscovery lan.Discovery
+ // AppVersion 是本机的版本号,随功能声明发给对端,对端用它提示「需要更新到哪个版本」
+ AppVersion string
}
+// legacyWait 是连上以后等对端功能声明的时间。旧版本(2.5.0 之前)从不发声明,
+// 等这么久还没有就判定为旧版本;在此之前只能说「还不知道」
+var legacyWait = 5 * time.Second
+
func NewManager(opts Options) (*Manager, error) {
log := opts.Logger
if log == nil {
@@ -145,6 +162,10 @@ func NewManager(opts Options) (*Manager, error) {
serverOnline: make(map[string]bool),
conn: make(map[string]p2p.ConnState),
features: make(map[string]map[string]bool),
+ peerVersion: make(map[string]string),
+ declared: make(map[string]bool),
+ legacy: make(map[string]bool),
+ appVersion: opts.AppVersion,
pending: make(map[string]*pendingPair),
stashed: make(map[string][]*pb.SignalMessage),
}
@@ -155,6 +176,10 @@ func NewManager(opts Options) (*Manager, error) {
}
for _, d := range devices {
m.known[d.ID] = d
+ if len(d.Features) > 0 {
+ m.features[d.ID] = featureSet(d.Features)
+ m.peerVersion[d.ID] = d.AppVersion
+ }
}
m.gateway, err = gateway.NewClient(opts.Identity, gateway.OfficialBaseURL, func(u gateway.Usage) {
@@ -364,7 +389,18 @@ func (m *Manager) featuresMessage() *pb.PeerMessage {
f = []string{FeatureSendFilesOff}
}
f = append(f, FeatureSendFilesTCP)
- return &pb.PeerMessage{Payload: &pb.PeerMessage_Features{Features: &pb.PeerFeatures{Features: f}}}
+ return &pb.PeerMessage{Payload: &pb.PeerMessage_Features{Features: &pb.PeerFeatures{Features: f, AppVersion: m.appVersion}}}
+}
+
+func featureSet(names []string) map[string]bool {
+ set := make(map[string]bool, len(names))
+ for i, name := range names {
+ if i >= 64 || len(name) > 64 {
+ break
+ }
+ set[name] = true
+ }
+ return set
}
// BroadcastFeatures 在本机的功能开关变了以后(比如关掉了接收文件)告诉所有连着的设备。
@@ -378,19 +414,55 @@ func (m *Manager) BroadcastFeatures() {
}
func (m *Manager) updatePeerFeatures(id string, f *pb.PeerFeatures) {
- set := make(map[string]bool, len(f.GetFeatures()))
- for i, name := range f.GetFeatures() {
- if i >= 64 || len(name) > 64 {
- break
- }
- set[name] = true
+ set := featureSet(f.GetFeatures())
+ version := f.GetAppVersion()
+ if len(version) > 32 {
+ version = version[:32]
}
m.mu.Lock()
_, ok := m.known[id]
if ok {
m.features[id] = set
+ m.peerVersion[id] = version
+ m.declared[id] = true
+ delete(m.legacy, id)
}
m.mu.Unlock()
+ if !ok {
+ return
+ }
+ names := make([]string, 0, len(set))
+ for name := range set {
+ names = append(names, name)
+ }
+ sort.Strings(names)
+ if err := m.store.SetDeviceFeatures(id, names, version); err != nil {
+ m.log.Warn("保存对端功能声明失败", "device", id, "err", err)
+ }
+ if d, ok := m.device(id); ok {
+ m.notify(d)
+ }
+}
+
+// checkLegacy 在连上 legacyWait 之后检查对端发过功能声明没有:
+// 还连着却一直没发,说明是不认识声明的旧版本。
+func (m *Manager) checkLegacy(id string) {
+ m.mu.Lock()
+ _, ok := m.known[id]
+ isLegacy := ok && connected(m.conn[id]) && !m.declared[id]
+ if isLegacy {
+ m.legacy[id] = true
+ // 上次存下的声明不再可信(对方装回了旧版本)
+ delete(m.features, id)
+ delete(m.peerVersion, id)
+ }
+ m.mu.Unlock()
+ if !isLegacy {
+ return
+ }
+ if err := m.store.SetDeviceFeatures(id, nil, ""); err != nil {
+ m.log.Warn("清除对端功能声明失败", "device", id, "err", err)
+ }
if d, ok := m.device(id); ok {
m.notify(d)
}
@@ -645,11 +717,17 @@ func (m *Manager) handleP2PState(deviceID string, state p2p.ConnState) {
m.mu.Lock()
prev := m.conn[deviceID]
m.conn[deviceID] = state
+ if connected(state) && !connected(prev) {
+ m.declared[deviceID] = false
+ }
m.mu.Unlock()
if connected(state) && !connected(prev) {
cfg := m.loadConfig()
_ = m.p2p.Send(deviceID, &pb.PeerMessage{Payload: &pb.PeerMessage_Display{Display: &pb.PeerDisplay{Name: cfg.DeviceName, Platform: runtime.GOOS}}})
- _ = m.p2p.Send(deviceID, m.featuresMessage())
+ if !m.noFeatures {
+ _ = m.p2p.Send(deviceID, m.featuresMessage())
+ }
+ time.AfterFunc(legacyWait, func() { m.checkLegacy(deviceID) })
}
m.log.Info("P2P 连接状态", "device", deviceID, "state", state)
@@ -1311,6 +1389,7 @@ func (m *Manager) toProtoLocked(d store.Device, online bool, session string) *pb
conn = m.conn[d.ID].Proto()
}
f := m.features[d.ID]
+ _, declared := m.features[d.ID]
return &pb.Device{
Id: d.ID,
Name: d.Name,
@@ -1323,6 +1402,8 @@ func (m *Manager) toProtoLocked(d store.Device, online bool, session string) *pb
ReceivesFiles: f[FeatureSendFiles] || f[FeatureSendFilesOff],
ReceiveDisabled: f[FeatureSendFilesOff],
LanReachable: online && m.lan.Reachable(d.ID),
+ FeaturesKnown: declared || m.legacy[d.ID],
+ AppVersion: m.peerVersion[d.ID],
}
}
diff --git a/client-core/internal/peers/manager_test.go b/client-core/internal/peers/manager_test.go
index 94e8793..b3238eb 100644
--- a/client-core/internal/peers/manager_test.go
+++ b/client-core/internal/peers/manager_test.go
@@ -8,6 +8,7 @@ import (
"net"
"net/http/httptest"
"path/filepath"
+ "slices"
"strconv"
"strings"
"sync"
@@ -424,3 +425,89 @@ func TestRefreshPeerFeatures(t *testing.T) {
t.Fatal("快速通道能力丢失")
}
}
+
+func peerDevice(t *testing.T, d *device, id string) *pb.Device {
+ t.Helper()
+ dev, ok := d.m.device(id)
+ if !ok {
+ t.Fatalf("%s 没有设备 %s", d.name, id)
+ }
+ return dev
+}
+
+// 没连上的设备只能说「还不知道」:在线(服务器或局域网报告)但 P2P 没通时,
+// 不能因为没收到声明就判定为旧版本。
+func TestFeaturesUnknownWhileNotConnected(t *testing.T) {
+ a := newDevice(t, "a", nil, lanOnly())
+ peer := store.Device{ID: "peer", Name: "peer", PublicKey: make([]byte, 32), PairedAt: time.Now()}
+ if err := a.m.store.PutDevice(peer); err != nil {
+ t.Fatal(err)
+ }
+ a.m.mu.Lock()
+ a.m.known[peer.ID] = peer
+ a.m.serverOnline[peer.ID] = true
+ a.m.mu.Unlock()
+ a.m.checkLegacy(peer.ID)
+ dev := peerDevice(t, a, peer.ID)
+ if !dev.GetOnline() || dev.GetFeaturesKnown() || dev.GetReceivesFiles() {
+ t.Fatalf("没连上就判定了功能: %v", dev)
+ }
+}
+
+// 收到声明后知道对方能收文件和它的版本号,并存进数据库;重启后不必等连上就知道。
+func TestFeaturesDeclaredAndRemembered(t *testing.T) {
+ network := lan.NewMemoryNetwork()
+ a, b := newDevice(t, "a", network, lanOnly()), newDevice(t, "b", network, lanOnly())
+ b.m.appVersion = "2.5.4"
+ waitLANUp(t, a, b)
+ pairDevices(t, a, b, "")
+ waitDirect(t, a, b)
+ waitFor(t, "a 收到 b 的声明", func() bool { return peerDevice(t, a, b.id()).GetFeaturesKnown() })
+ dev := peerDevice(t, a, b.id())
+ if !dev.GetReceivesFiles() || dev.GetAppVersion() != "2.5.4" {
+ t.Fatalf("声明不对: %v", dev)
+ }
+ devices, err := a.m.store.ListDevices()
+ if err != nil || len(devices) != 1 {
+ t.Fatalf("读设备: %v %v", devices, err)
+ }
+ got := devices[0]
+ if got.AppVersion != "2.5.4" || !slices.Contains(got.Features, FeatureSendFiles) {
+ t.Fatalf("没存下声明: %+v", got)
+ }
+
+ // 用同一个数据库再建一个 Manager,相当于重启:还没连上就知道对方的功能
+ restarted, err := NewManager(Options{
+ Identity: a.m.identity,
+ Store: a.m.store,
+ Logger: slog.New(slog.NewTextHandler(io.Discard, nil)),
+ LoadConfig: lanOnly,
+ StatePath: filepath.Join(t.TempDir(), "egress.json"),
+ LANPort: -1,
+ })
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() { restarted.P2P().Close() })
+ dev, _ = restarted.device(b.id())
+ if !dev.GetFeaturesKnown() || !dev.GetReceivesFiles() || dev.GetAppVersion() != "2.5.4" {
+ t.Fatalf("重启后没读回声明: %v", dev)
+ }
+}
+
+// 旧版本从不发声明:连上 legacyWait 后仍没有,才判定为旧版本,并清掉上次存下的声明。
+func TestLegacyPeerAfterWait(t *testing.T) {
+ old := legacyWait
+ legacyWait = 300 * time.Millisecond
+ t.Cleanup(func() { legacyWait = old })
+ network := lan.NewMemoryNetwork()
+ a, b := newDevice(t, "a", network, lanOnly()), newDevice(t, "b", network, lanOnly())
+ b.m.noFeatures = true
+ waitLANUp(t, a, b)
+ pairDevices(t, a, b, "")
+ waitDirect(t, a, b)
+ waitFor(t, "判定为旧版本", func() bool { return peerDevice(t, a, b.id()).GetFeaturesKnown() })
+ if dev := peerDevice(t, a, b.id()); dev.GetReceivesFiles() || dev.GetAppVersion() != "" {
+ t.Fatalf("旧版本不该能收文件: %v", dev)
+ }
+}
diff --git a/client-core/internal/store/store.go b/client-core/internal/store/store.go
index 3b444c4..a38643f 100644
--- a/client-core/internal/store/store.go
+++ b/client-core/internal/store/store.go
@@ -115,6 +115,10 @@ type Device struct {
Platform string
PublicKey []byte
PairedAt time.Time
+ // Features 是对方最近一次声明的功能(PeerFeatures),AppVersion 是它当时的版本号。
+ // 存下来是为了重启后不必等连上就知道对方支持什么;空表示还没收到过
+ Features []string
+ AppVersion string
}
type Store struct{ db *sql.DB }
@@ -253,6 +257,14 @@ CREATE INDEX IF NOT EXISTS idx_clips_source ON clips(source_clip_id) WHERE sou
CREATE INDEX IF NOT EXISTS idx_clips_favorite ON clips(favorite, favorited_at DESC);`); err != nil {
return fmt.Errorf("建索引: %w", err)
}
+ for _, col := range []struct{ name, decl string }{
+ {"features", "TEXT NOT NULL DEFAULT ''"},
+ {"app_version", "TEXT NOT NULL DEFAULT ''"},
+ } {
+ if err := s.addColumnIfMissing("devices", col.name, col.decl); err != nil {
+ return err
+ }
+ }
if err := s.migrateTransfers(); err != nil {
return err
}
@@ -698,7 +710,7 @@ ON CONFLICT(id) DO UPDATE SET
func (s *Store) ListDevices() ([]Device, error) {
rows, err := s.db.Query(`
-SELECT id, name, platform, public_key, paired_at FROM devices ORDER BY paired_at`)
+SELECT id, name, platform, public_key, paired_at, features, app_version FROM devices ORDER BY paired_at`)
if err != nil {
return nil, err
}
@@ -707,15 +719,26 @@ SELECT id, name, platform, public_key, paired_at FROM devices ORDER BY paired_at
for rows.Next() {
var d Device
var paired int64
- if err := rows.Scan(&d.ID, &d.Name, &d.Platform, &d.PublicKey, &paired); err != nil {
+ var features string
+ if err := rows.Scan(&d.ID, &d.Name, &d.Platform, &d.PublicKey, &paired, &features, &d.AppVersion); err != nil {
return nil, err
}
d.PairedAt = time.Unix(paired, 0)
+ if features != "" {
+ d.Features = strings.Split(features, ",")
+ }
out = append(out, d)
}
return out, rows.Err()
}
+// SetDeviceFeatures 记下对方最近一次声明的功能和版本号。设备不存在时什么也不做
+func (s *Store) SetDeviceFeatures(id string, features []string, appVersion string) error {
+ _, err := s.db.Exec(`UPDATE devices SET features=?, app_version=? WHERE id=?`,
+ strings.Join(features, ","), appVersion, id)
+ return err
+}
+
func (s *Store) DeleteDevice(id string) error {
_, err := s.db.Exec(`DELETE FROM devices WHERE id=?`, id)
return err
diff --git a/proto/gen/pasteferry/v1/daemon.pb.go b/proto/gen/pasteferry/v1/daemon.pb.go
index f887d34..4b6447f 100644
--- a/proto/gen/pasteferry/v1/daemon.pb.go
+++ b/proto/gen/pasteferry/v1/daemon.pb.go
@@ -825,7 +825,12 @@ type Device struct {
// 对方关闭了接收文件
ReceiveDisabled bool `protobuf:"varint,10,opt,name=receive_disabled,json=receiveDisabled,proto3" json:"receive_disabled,omitempty"`
// 在同一个局域网里能直接找到对方,隔空传送的雷达据此把它放在内圈
- LanReachable bool `protobuf:"varint,11,opt,name=lan_reachable,json=lanReachable,proto3" json:"lan_reachable,omitempty"`
+ LanReachable bool `protobuf:"varint,11,opt,name=lan_reachable,json=lanReachable,proto3" json:"lan_reachable,omitempty"`
+ // 已经知道对方支持哪些功能(2.5.4 起):收到过它的声明(含重启前存下的),
+ // 或者连上 5 秒仍没收到、判定为旧版本。为 false 时 receives_files 只是「还不知道」,界面不能据此说对方要更新
+ FeaturesKnown bool `protobuf:"varint,12,opt,name=features_known,json=featuresKnown,proto3" json:"features_known,omitempty"`
+ // 对方声明里带的版本号,旧版本为空
+ AppVersion string `protobuf:"bytes,13,opt,name=app_version,json=appVersion,proto3" json:"app_version,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
@@ -937,6 +942,20 @@ func (x *Device) GetLanReachable() bool {
return false
}
+func (x *Device) GetFeaturesKnown() bool {
+ if x != nil {
+ return x.FeaturesKnown
+ }
+ return false
+}
+
+func (x *Device) GetAppVersion() string {
+ if x != nil {
+ return x.AppVersion
+ }
+ return ""
+}
+
type Event struct {
state protoimpl.MessageState `protogen:"open.v1"`
// Types that are valid to be assigned to Payload:
@@ -4885,7 +4904,7 @@ const file_pasteferry_v1_daemon_proto_rawDesc = "" +
"\aclip_id\x18\x01 \x01(\tR\x06clipId\x12 \n" +
"\vtransferred\x18\x02 \x01(\x03R\vtransferred\x12\x14\n" +
"\x05total\x18\x03 \x01(\x03R\x05total\x12(\n" +
- "\x10bytes_per_second\x18\x04 \x01(\x01R\x0ebytesPerSecond\"\x9b\x03\n" +
+ "\x10bytes_per_second\x18\x04 \x01(\x01R\x0ebytesPerSecond\"\xe3\x03\n" +
"\x06Device\x12\x0e\n" +
"\x02id\x18\x01 \x01(\tR\x02id\x12\x12\n" +
"\x04name\x18\x02 \x01(\tR\x04name\x12\x1a\n" +
@@ -4900,7 +4919,10 @@ const file_pasteferry_v1_daemon_proto_rawDesc = "" +
"\x0ereceives_files\x18\t \x01(\bR\rreceivesFiles\x12)\n" +
"\x10receive_disabled\x18\n" +
" \x01(\bR\x0freceiveDisabled\x12#\n" +
- "\rlan_reachable\x18\v \x01(\bR\flanReachable\"\xbf\x06\n" +
+ "\rlan_reachable\x18\v \x01(\bR\flanReachable\x12%\n" +
+ "\x0efeatures_known\x18\f \x01(\bR\rfeaturesKnown\x12\x1f\n" +
+ "\vapp_version\x18\r \x01(\tR\n" +
+ "appVersion\"\xbf\x06\n" +
"\x05Event\x12:\n" +
"\n" +
"clip_added\x18\x01 \x01(\v2\x19.pasteferry.v1.ClipRecordH\x00R\tclipAdded\x12>\n" +
diff --git a/proto/gen/pasteferry/v1/wire.pb.go b/proto/gen/pasteferry/v1/wire.pb.go
index b94cefd..00bde1b 100644
--- a/proto/gen/pasteferry/v1/wire.pb.go
+++ b/proto/gen/pasteferry/v1/wire.pb.go
@@ -2366,7 +2366,9 @@ type PeerFeatures struct {
state protoimpl.MessageState `protogen:"open.v1"`
// "send_files_v1":能接收隔空传送。关闭了接收时不带它,改带 "send_files_off",
// 对方的雷达显示「不接收文件」而不是「需要更新」
- Features []string `protobuf:"bytes,1,rep,name=features,proto3" json:"features,omitempty"`
+ Features []string `protobuf:"bytes,1,rep,name=features,proto3" json:"features,omitempty"`
+ // 发出这条声明的版本号(2.5.4 起)。只用来在界面上提示「需要更新到哪个版本」,不用来判断功能
+ AppVersion string `protobuf:"bytes,2,opt,name=app_version,json=appVersion,proto3" json:"app_version,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
@@ -2408,6 +2410,13 @@ func (x *PeerFeatures) GetFeatures() []string {
return nil
}
+func (x *PeerFeatures) GetAppVersion() string {
+ if x != nil {
+ return x.AppVersion
+ }
+ return ""
+}
+
// 连接就绪后各自发一次。只有本端能确定自己发出的数据是否走 TURN:
// 对端经中转发来的包,在本端看来可能只是一个普通地址(peer-reflexive),
// 单靠自己的视角会把中转误判成直连。两端交换后,任一端经中转即显示为中转。
@@ -3661,9 +3670,11 @@ const file_pasteferry_v1_wire_proto_rawDesc = "" +
"sendCancel\x12<\n" +
"\vsend_result\x18\f \x01(\v2\x19.pasteferry.v1.SendResultH\x00R\n" +
"sendResultB\t\n" +
- "\apayload\"*\n" +
+ "\apayload\"K\n" +
"\fPeerFeatures\x12\x1a\n" +
- "\bfeatures\x18\x01 \x03(\tR\bfeatures\"$\n" +
+ "\bfeatures\x18\x01 \x03(\tR\bfeatures\x12\x1f\n" +
+ "\vapp_version\x18\x02 \x01(\tR\n" +
+ "appVersion\"$\n" +
"\bLinkInfo\x12\x18\n" +
"\arelayed\x18\x01 \x01(\bR\arelayed\"=\n" +
"\vPeerDisplay\x12\x12\n" +
diff --git a/proto/pasteferry/v1/daemon.proto b/proto/pasteferry/v1/daemon.proto
index 7cb735e..9e2a52f 100644
--- a/proto/pasteferry/v1/daemon.proto
+++ b/proto/pasteferry/v1/daemon.proto
@@ -207,6 +207,11 @@ message Device {
bool receive_disabled = 10;
// 在同一个局域网里能直接找到对方,隔空传送的雷达据此把它放在内圈
bool lan_reachable = 11;
+ // 已经知道对方支持哪些功能(2.5.4 起):收到过它的声明(含重启前存下的),
+ // 或者连上 5 秒仍没收到、判定为旧版本。为 false 时 receives_files 只是「还不知道」,界面不能据此说对方要更新
+ bool features_known = 12;
+ // 对方声明里带的版本号,旧版本为空
+ string app_version = 13;
}
// macOS 剪贴板授权状态,对应 NSPasteboardAccessBehavior。
diff --git a/proto/pasteferry/v1/wire.proto b/proto/pasteferry/v1/wire.proto
index bc10d80..0ebb82c 100644
--- a/proto/pasteferry/v1/wire.proto
+++ b/proto/pasteferry/v1/wire.proto
@@ -273,6 +273,8 @@ message PeerFeatures {
// "send_files_v1":能接收隔空传送。关闭了接收时不带它,改带 "send_files_off",
// 对方的雷达显示「不接收文件」而不是「需要更新」
repeated string features = 1;
+ // 发出这条声明的版本号(2.5.4 起)。只用来在界面上提示「需要更新到哪个版本」,不用来判断功能
+ string app_version = 2;
}
// 连接就绪后各自发一次。只有本端能确定自己发出的数据是否走 TURN:
diff --git a/ui/lib/gen/pasteferry/v1/daemon.pb.dart b/ui/lib/gen/pasteferry/v1/daemon.pb.dart
index 2210f1c..898d0ca 100644
--- a/ui/lib/gen/pasteferry/v1/daemon.pb.dart
+++ b/ui/lib/gen/pasteferry/v1/daemon.pb.dart
@@ -577,6 +577,8 @@ class Device extends $pb.GeneratedMessage {
$core.bool? receivesFiles,
$core.bool? receiveDisabled,
$core.bool? lanReachable,
+ $core.bool? featuresKnown,
+ $core.String? appVersion,
}) {
final result = Device._();
if (id != null) result.id = id;
@@ -591,6 +593,8 @@ class Device extends $pb.GeneratedMessage {
if (receivesFiles != null) result.receivesFiles = receivesFiles;
if (receiveDisabled != null) result.receiveDisabled = receiveDisabled;
if (lanReachable != null) result.lanReachable = lanReachable;
+ if (featuresKnown != null) result.featuresKnown = featuresKnown;
+ if (appVersion != null) result.appVersion = appVersion;
return result;
}
@@ -619,6 +623,8 @@ class Device extends $pb.GeneratedMessage {
..aOB(9, _omitFieldNames ? '' : 'receivesFiles')
..aOB(10, _omitFieldNames ? '' : 'receiveDisabled')
..aOB(11, _omitFieldNames ? '' : 'lanReachable')
+ ..aOB(12, _omitFieldNames ? '' : 'featuresKnown')
+ ..aOS(13, _omitFieldNames ? '' : 'appVersion')
..hasRequiredFields = false;
@$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.')
@@ -745,6 +751,27 @@ class Device extends $pb.GeneratedMessage {
$core.bool hasLanReachable() => $_has(10);
@$pb.TagNumber(11)
void clearLanReachable() => $_clearField(11);
+
+ /// 已经知道对方支持哪些功能(2.5.4 起):收到过它的声明(含重启前存下的),
+ /// 或者连上 5 秒仍没收到、判定为旧版本。为 false 时 receives_files 只是「还不知道」,界面不能据此说对方要更新
+ @$pb.TagNumber(12)
+ $core.bool get featuresKnown => $_getBF(11);
+ @$pb.TagNumber(12)
+ set featuresKnown($core.bool value) => $_setBool(11, value);
+ @$pb.TagNumber(12)
+ $core.bool hasFeaturesKnown() => $_has(11);
+ @$pb.TagNumber(12)
+ void clearFeaturesKnown() => $_clearField(12);
+
+ /// 对方声明里带的版本号,旧版本为空
+ @$pb.TagNumber(13)
+ $core.String get appVersion => $_getSZ(12);
+ @$pb.TagNumber(13)
+ set appVersion($core.String value) => $_setString(12, value);
+ @$pb.TagNumber(13)
+ $core.bool hasAppVersion() => $_has(12);
+ @$pb.TagNumber(13)
+ void clearAppVersion() => $_clearField(13);
}
enum Event_Payload {
diff --git a/ui/lib/gen/pasteferry/v1/daemon.pbjson.dart b/ui/lib/gen/pasteferry/v1/daemon.pbjson.dart
index fca632e..5c9f0b7 100644
--- a/ui/lib/gen/pasteferry/v1/daemon.pbjson.dart
+++ b/ui/lib/gen/pasteferry/v1/daemon.pbjson.dart
@@ -297,6 +297,8 @@ const Device$json = {
{'1': 'receives_files', '3': 9, '4': 1, '5': 8, '10': 'receivesFiles'},
{'1': 'receive_disabled', '3': 10, '4': 1, '5': 8, '10': 'receiveDisabled'},
{'1': 'lan_reachable', '3': 11, '4': 1, '5': 8, '10': 'lanReachable'},
+ {'1': 'features_known', '3': 12, '4': 1, '5': 8, '10': 'featuresKnown'},
+ {'1': 'app_version', '3': 13, '4': 1, '5': 9, '10': 'appVersion'},
],
};
@@ -309,7 +311,8 @@ final $typed_data.Uint8List deviceDescriptor = $convert.base64Decode(
'ZF9hdF91bml4GAcgASgDUgxwYWlyZWRBdFVuaXgSJwoPcGFpcmluZ19zZXNzaW9uGAggASgJUg'
'5wYWlyaW5nU2Vzc2lvbhIlCg5yZWNlaXZlc19maWxlcxgJIAEoCFINcmVjZWl2ZXNGaWxlcxIp'
'ChByZWNlaXZlX2Rpc2FibGVkGAogASgIUg9yZWNlaXZlRGlzYWJsZWQSIwoNbGFuX3JlYWNoYW'
- 'JsZRgLIAEoCFIMbGFuUmVhY2hhYmxl');
+ 'JsZRgLIAEoCFIMbGFuUmVhY2hhYmxlEiUKDmZlYXR1cmVzX2tub3duGAwgASgIUg1mZWF0dXJl'
+ 'c0tub3duEh8KC2FwcF92ZXJzaW9uGA0gASgJUgphcHBWZXJzaW9u');
@$core.Deprecated('Use eventDescriptor instead')
const Event$json = {
diff --git a/ui/lib/gen/pasteferry/v1/wire.pb.dart b/ui/lib/gen/pasteferry/v1/wire.pb.dart
index f63e594..98c8465 100644
--- a/ui/lib/gen/pasteferry/v1/wire.pb.dart
+++ b/ui/lib/gen/pasteferry/v1/wire.pb.dart
@@ -2877,9 +2877,11 @@ class PeerMessage extends $pb.GeneratedMessage {
class PeerFeatures extends $pb.GeneratedMessage {
factory PeerFeatures({
$core.Iterable<$core.String>? features,
+ $core.String? appVersion,
}) {
final result = PeerFeatures._();
if (features != null) result.features.addAll(features);
+ if (appVersion != null) result.appVersion = appVersion;
return result;
}
@@ -2897,6 +2899,7 @@ class PeerFeatures extends $pb.GeneratedMessage {
package: const $pb.PackageName(_omitMessageNames ? '' : 'pasteferry.v1'),
createEmptyInstance: PeerFeatures.$_createMessage)
..pPS(1, _omitFieldNames ? '' : 'features')
+ ..aOS(2, _omitFieldNames ? '' : 'appVersion')
..hasRequiredFields = false;
@$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.')
@@ -2925,6 +2928,16 @@ class PeerFeatures extends $pb.GeneratedMessage {
/// 对方的雷达显示「不接收文件」而不是「需要更新」
@$pb.TagNumber(1)
$pb.PbList<$core.String> get features => $_getList(0);
+
+ /// 发出这条声明的版本号(2.5.4 起)。只用来在界面上提示「需要更新到哪个版本」,不用来判断功能
+ @$pb.TagNumber(2)
+ $core.String get appVersion => $_getSZ(1);
+ @$pb.TagNumber(2)
+ set appVersion($core.String value) => $_setString(1, value);
+ @$pb.TagNumber(2)
+ $core.bool hasAppVersion() => $_has(1);
+ @$pb.TagNumber(2)
+ void clearAppVersion() => $_clearField(2);
}
/// 连接就绪后各自发一次。只有本端能确定自己发出的数据是否走 TURN:
diff --git a/ui/lib/gen/pasteferry/v1/wire.pbjson.dart b/ui/lib/gen/pasteferry/v1/wire.pbjson.dart
index 5ee80d1..3a56196 100644
--- a/ui/lib/gen/pasteferry/v1/wire.pbjson.dart
+++ b/ui/lib/gen/pasteferry/v1/wire.pbjson.dart
@@ -858,12 +858,14 @@ const PeerFeatures$json = {
'1': 'PeerFeatures',
'2': [
{'1': 'features', '3': 1, '4': 3, '5': 9, '10': 'features'},
+ {'1': 'app_version', '3': 2, '4': 1, '5': 9, '10': 'appVersion'},
],
};
/// Descriptor for `PeerFeatures`. Decode as a `google.protobuf.DescriptorProto`.
-final $typed_data.Uint8List peerFeaturesDescriptor = $convert
- .base64Decode('CgxQZWVyRmVhdHVyZXMSGgoIZmVhdHVyZXMYASADKAlSCGZlYXR1cmVz');
+final $typed_data.Uint8List peerFeaturesDescriptor = $convert.base64Decode(
+ 'CgxQZWVyRmVhdHVyZXMSGgoIZmVhdHVyZXMYASADKAlSCGZlYXR1cmVzEh8KC2FwcF92ZXJzaW'
+ '9uGAIgASgJUgphcHBWZXJzaW9u');
@$core.Deprecated('Use linkInfoDescriptor instead')
const LinkInfo$json = {
diff --git a/ui/lib/l10n/app_en.arb b/ui/lib/l10n/app_en.arb
index 19ceaf4..6af8fbf 100644
--- a/ui/lib/l10n/app_en.arb
+++ b/ui/lib/l10n/app_en.arb
@@ -951,6 +951,14 @@
}
}
},
+ "sendConnectingTip": "Connecting to {name}. You can send once it's connected.",
+ "@sendConnectingTip": {
+ "placeholders": {
+ "name": {
+ "type": "String"
+ }
+ }
+ },
"sendNotReceiving": "Not receiving files",
"sendDelivered": "Delivered",
"sendToTitle": "Send to {name}",
diff --git a/ui/lib/l10n/app_ja.arb b/ui/lib/l10n/app_ja.arb
index 044cefe..e8c2894 100644
--- a/ui/lib/l10n/app_ja.arb
+++ b/ui/lib/l10n/app_ja.arb
@@ -406,6 +406,7 @@
"sendRelayLeft": "中継 · 今日の残り {left}",
"sendNeedsUpdate": "アップデートが必要",
"sendNeedsUpdateTip": "{name} は PasteFerry 2.5 以降にアップデートするとファイルを受信できます。",
+ "sendConnectingTip": "{name} に接続しています。接続したら送信できます。",
"sendNotReceiving": "ファイルを受信しない",
"sendDelivered": "送信済み",
"sendToTitle": "{name} に送信",
diff --git a/ui/lib/l10n/app_localizations.dart b/ui/lib/l10n/app_localizations.dart
index 70b1957..58fd0c3 100644
--- a/ui/lib/l10n/app_localizations.dart
+++ b/ui/lib/l10n/app_localizations.dart
@@ -2546,6 +2546,12 @@ abstract class AppLocalizations {
/// **'{name} can receive files after updating to PasteFerry 2.5 or later.'**
String sendNeedsUpdateTip(String name);
+ /// No description provided for @sendConnectingTip.
+ ///
+ /// In en, this message translates to:
+ /// **'Connecting to {name}. You can send once it\'s connected.'**
+ String sendConnectingTip(String name);
+
/// No description provided for @sendNotReceiving.
///
/// In en, this message translates to:
diff --git a/ui/lib/l10n/app_localizations_en.dart b/ui/lib/l10n/app_localizations_en.dart
index cb19d47..a347145 100644
--- a/ui/lib/l10n/app_localizations_en.dart
+++ b/ui/lib/l10n/app_localizations_en.dart
@@ -1527,6 +1527,11 @@ class AppLocalizationsEn extends AppLocalizations {
return '$name can receive files after updating to PasteFerry 2.5 or later.';
}
+ @override
+ String sendConnectingTip(String name) {
+ return 'Connecting to $name. You can send once it\'s connected.';
+ }
+
@override
String get sendNotReceiving => 'Not receiving files';
diff --git a/ui/lib/l10n/app_localizations_ja.dart b/ui/lib/l10n/app_localizations_ja.dart
index 01c5aef..e3b834d 100644
--- a/ui/lib/l10n/app_localizations_ja.dart
+++ b/ui/lib/l10n/app_localizations_ja.dart
@@ -1403,6 +1403,11 @@ class AppLocalizationsJa extends AppLocalizations {
return '$name は PasteFerry 2.5 以降にアップデートするとファイルを受信できます。';
}
+ @override
+ String sendConnectingTip(String name) {
+ return '$name に接続しています。接続したら送信できます。';
+ }
+
@override
String get sendNotReceiving => 'ファイルを受信しない';
diff --git a/ui/lib/l10n/app_localizations_zh.dart b/ui/lib/l10n/app_localizations_zh.dart
index 44b5a10..d23ee06 100644
--- a/ui/lib/l10n/app_localizations_zh.dart
+++ b/ui/lib/l10n/app_localizations_zh.dart
@@ -1385,6 +1385,11 @@ class AppLocalizationsZh extends AppLocalizations {
return '$name 更新到隔空贴 2.5 或更高版本后才能接收文件。';
}
+ @override
+ String sendConnectingTip(String name) {
+ return '正在连接 $name,连上后就能发送。';
+ }
+
@override
String get sendNotReceiving => '不接收文件';
@@ -3155,6 +3160,11 @@ class AppLocalizationsZhHantHk extends AppLocalizationsZh {
return '$name 更新到隔空貼 2.5 或更新版本後才能接收檔案。';
}
+ @override
+ String sendConnectingTip(String name) {
+ return '正在連線 $name,連上後就能傳送。';
+ }
+
@override
String get sendNotReceiving => '不接收檔案';
@@ -4925,6 +4935,11 @@ class AppLocalizationsZhHantTw extends AppLocalizationsZh {
return '$name 更新到隔空貼 2.5 或更新版本後才能接收檔案。';
}
+ @override
+ String sendConnectingTip(String name) {
+ return '正在連線 $name,連上後就能傳送。';
+ }
+
@override
String get sendNotReceiving => '不接收檔案';
diff --git a/ui/lib/l10n/app_zh.arb b/ui/lib/l10n/app_zh.arb
index 5eedb63..6830a4b 100644
--- a/ui/lib/l10n/app_zh.arb
+++ b/ui/lib/l10n/app_zh.arb
@@ -406,6 +406,7 @@
"sendRelayLeft": "中转 · 今日剩 {left}",
"sendNeedsUpdate": "需要更新",
"sendNeedsUpdateTip": "{name} 更新到隔空贴 2.5 或更高版本后才能接收文件。",
+ "sendConnectingTip": "正在连接 {name},连上后就能发送。",
"sendNotReceiving": "不接收文件",
"sendDelivered": "已送达",
"sendToTitle": "发送到 {name}",
diff --git a/ui/lib/l10n/app_zh_Hant_HK.arb b/ui/lib/l10n/app_zh_Hant_HK.arb
index a1a2941..c19f1b2 100644
--- a/ui/lib/l10n/app_zh_Hant_HK.arb
+++ b/ui/lib/l10n/app_zh_Hant_HK.arb
@@ -406,6 +406,7 @@
"sendRelayLeft": "中轉 · 今日剩 {left}",
"sendNeedsUpdate": "需要更新",
"sendNeedsUpdateTip": "{name} 更新到隔空貼 2.5 或更新版本後才能接收檔案。",
+ "sendConnectingTip": "正在連線 {name},連上後就能傳送。",
"sendNotReceiving": "不接收檔案",
"sendDelivered": "已送達",
"sendToTitle": "傳送到 {name}",
diff --git a/ui/lib/l10n/app_zh_Hant_TW.arb b/ui/lib/l10n/app_zh_Hant_TW.arb
index 4cbf047..dc543cb 100644
--- a/ui/lib/l10n/app_zh_Hant_TW.arb
+++ b/ui/lib/l10n/app_zh_Hant_TW.arb
@@ -406,6 +406,7 @@
"sendRelayLeft": "中繼 · 今日剩 {left}",
"sendNeedsUpdate": "需要更新",
"sendNeedsUpdateTip": "{name} 更新到隔空貼 2.5 或更新版本後才能接收檔案。",
+ "sendConnectingTip": "正在連線 {name},連上後就能傳送。",
"sendNotReceiving": "不接收檔案",
"sendDelivered": "已送達",
"sendToTitle": "傳送到 {name}",
diff --git a/ui/lib/pages/send_page.dart b/ui/lib/pages/send_page.dart
index 70d0776..3f1357a 100644
--- a/ui/lib/pages/send_page.dart
+++ b/ui/lib/pages/send_page.dart
@@ -395,7 +395,11 @@ class _SendPageState extends State<SendPage> with SingleTickerProviderStateMixin
avatar: Icon(platformIcon(d.platform), size: 14),
// 发不了的写上原因
label: Text(_canSend(d) ? d.name : '${d.name} · ${_statusOf(context, state, d)}'),
- onPressed: _canSend(d) ? () => _openDialog(d) : null,
+ onPressed: _canSend(d)
+ ? () => _openDialog(d)
+ : _connecting(d)
+ ? () => _connect(state, d)
+ : null,
),
],
),
@@ -418,10 +422,19 @@ class _SendPageState extends State<SendPage> with SingleTickerProviderStateMixin
bool _canSend(Device d) => d.online && d.receivesFiles && !d.receiveDisabled;
+ /// 在线、但还不知道对方能不能收文件(还没连上、没收到它的功能声明)。
+ /// 这时不能说对方要更新:点它就先去连
+ bool _connecting(Device d) => d.online && !d.featuresKnown && !d.receivesFiles;
+
+ void _connect(AppState state, Device d) {
+ state.reconnect(d.id).catchError((_) => ConnectionKind.CONNECTION_KIND_UNSPECIFIED);
+ }
+
/// 发不了的原因,或者能发时的连接方式
String _statusOf(BuildContext context, AppState state, Device d) {
final l = context.l10n;
if (!d.online) return l.offline;
+ if (_connecting(d)) return l.reconnecting;
if (!d.receivesFiles) return l.sendNeedsUpdate;
if (d.receiveDisabled) return l.sendNotReceiving;
return routeLabel(l, state, d);
@@ -453,7 +466,11 @@ class _SendPageState extends State<SendPage> with SingleTickerProviderStateMixin
: d.lanReachable
? p.online
: p.accent;
- final tip = !d.receivesFiles ? l.sendNeedsUpdateTip(d.name) : _statusOf(context, state, d);
+ final tip = _connecting(d)
+ ? l.sendConnectingTip(d.name)
+ : d.online && !d.receivesFiles
+ ? l.sendNeedsUpdateTip(d.name)
+ : _statusOf(context, state, d);
double? progress;
if (sending != null) {
progress = sending.status == 'active' && sending.totalBytes > 0
@@ -472,7 +489,11 @@ class _SendPageState extends State<SendPage> with SingleTickerProviderStateMixin
dropTarget: _dropTarget == d.id && enabled,
sending: sending != null,
progress: progress,
- onTap: enabled ? () => _openDialog(d) : null,
+ onTap: enabled
+ ? () => _openDialog(d)
+ : _connecting(d)
+ ? () => _connect(state, d)
+ : null,
),
);
}
diff --git a/ui/test/send_page_test.dart b/ui/test/send_page_test.dart
index f9045c9..42945a2 100644
--- a/ui/test/send_page_test.dart
+++ b/ui/test/send_page_test.dart
@@ -27,7 +27,7 @@ AppState _demo(String language, {bool withActive = true}) => AppState()
connection: ConnectionKind.CONNECTION_KIND_RELAY, receivesFiles: true),
Device(id: 'linux', name: 'Ubuntu 笔记本', platform: 'linux'),
Device(id: 'old', name: 'Old PC', platform: 'windows', online: true,
- connection: ConnectionKind.CONNECTION_KIND_DIRECT),
+ connection: ConnectionKind.CONNECTION_KIND_DIRECT, featuresKnown: true),
Device(id: 'off', name: 'iMac', platform: 'darwin', online: true, lanReachable: true,
connection: ConnectionKind.CONNECTION_KIND_DIRECT, receivesFiles: true, receiveDisabled: true),
],
@@ -78,6 +78,27 @@ void main() {
return l;
}
+ testWidgets('还没连上的设备写「正在连接」,不写需要更新', (tester) async {
+ final state = AppState()
+ ..debugSeed(
+ status: Status(version: '2.5.4'),
+ config: Config(language: language, deviceName: 'MacBook Pro'),
+ self: Device(id: 'self', name: 'MacBook Pro', platform: 'darwin'),
+ peers: [
+ // 在线(服务器或局域网报告)但还没连上、没收到功能声明
+ Device(id: 'new', name: 'Linux 台式机', platform: 'linux', online: true),
+ // 连上以后一直没声明,判定为旧版本
+ Device(id: 'old', name: 'Old PC', platform: 'windows', online: true,
+ connection: ConnectionKind.CONNECTION_KIND_DIRECT, featuresKnown: true),
+ ],
+ );
+ final l = await open(tester, state);
+ expect(find.text(l.reconnecting), findsOneWidget);
+ expect(find.byTooltip(l.sendConnectingTip('Linux 台式机')), findsOneWidget);
+ expect(find.text(l.sendNeedsUpdate), findsOneWidget);
+ expect(find.byTooltip(l.sendNeedsUpdateTip('Old PC')), findsOneWidget);
+ });
+
testWidgets('雷达与列表', (tester) async {
final l = await open(tester, _demo(language));
expect(find.text(l.sendSubtitle), findsOneWidget);