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.

feat(core): pair with nearby devices without a code

baiyuzec4a581674576
diff --git a/client-core/cmd/copysync-cli/main.go b/client-core/cmd/copysync-cli/main.go
index 527210a..93df4ec 100644
--- a/client-core/cmd/copysync-cli/main.go
+++ b/client-core/cmd/copysync-cli/main.go
@@ -11,6 +11,7 @@
// copysync-cli nat 网络出口、局域网与各设备连接情况
// copysync-cli pair 生成配对码
// copysync-cli join CODE [ADDRESS] 兑换配对码;不在同一网段时带上对方显示的地址
+// copysync-cli nearby [NAME] 搜索附近设备:给了 NAME 就在它出现时向它发起配对,否则等对方点本机
// copysync-cli address DEVICE ADDR 手动指定某台设备的地址
package main
@@ -42,7 +43,7 @@ func main() {
cmd := flag.Arg(0)
if cmd == "" {
fmt.Fprintln(os.Stderr,
- "用法: copysync-cli [-data-dir DIR] <status|watch|history|config|devices|nat|pair|join CODE [ADDRESS]|address DEVICE ADDR>")
+ "用法: copysync-cli [-data-dir DIR] <status|watch|history|config|devices|nat|pair|join CODE [ADDRESS]|nearby [NAME]|address DEVICE ADDR>")
os.Exit(2)
}
@@ -94,6 +95,8 @@ func run(cmd, dataDir string) error {
return createPairing(ctx, client)
case "join":
return joinPairing(ctx, client, flag.Arg(1), flag.Arg(2))
+ case "nearby":
+ return nearbyPairing(ctx, client, flag.Arg(1))
case "address":
return setAddress(ctx, client, flag.Arg(1), flag.Arg(2))
default:
@@ -179,33 +182,37 @@ func createPairing(ctx context.Context, c pb.DaemonServiceClient) error {
continue // 非待确认的配对事件(普通的在线状态变化)
}
fmt.Printf("\n 对方已兑换:%s(%s)\n", d.GetName(), d.GetPlatform())
- if err := printFingerprints(ctx, c, d); err != nil {
- return err
- }
- fmt.Print(" 确认配对?[y/N] ")
-
- var answer string
- fmt.Scanln(&answer)
- accept := answer == "y" || answer == "Y"
-
- confirmCtx, confirmCancel := context.WithTimeout(ctx, 10*time.Second)
- _, confirmErr := c.ConfirmPairing(confirmCtx, &pb.ConfirmPairingRequest{
- PairingSession: d.GetPairingSession(),
- Accept: accept,
- })
- confirmCancel()
- if confirmErr != nil {
- return confirmErr
- }
- if accept {
- fmt.Println("\n ✓ 配对成功")
- } else {
- fmt.Println("\n 已取消")
- }
- return nil
+ return confirmPeer(ctx, c, d, d.GetPairingSession())
}
}
+// confirmPeer 打印两行安全指纹,问用户是否一致,把回答告诉后台服务。
+func confirmPeer(ctx context.Context, c pb.DaemonServiceClient, peer *pb.Device, session string) error {
+ if err := printFingerprints(ctx, c, peer); err != nil {
+ return err
+ }
+ fmt.Print(" 确认配对?[y/N] ")
+
+ var answer string
+ fmt.Scanln(&answer)
+ accept := answer == "y" || answer == "Y"
+
+ confirmCtx, cancel := context.WithTimeout(ctx, 10*time.Second)
+ defer cancel()
+ if _, err := c.ConfirmPairing(confirmCtx, &pb.ConfirmPairingRequest{
+ PairingSession: session,
+ Accept: accept,
+ }); err != nil {
+ return err
+ }
+ if accept {
+ fmt.Println("\n ✓ 配对成功")
+ } else {
+ fmt.Println("\n 已取消")
+ }
+ return nil
+}
+
// printFingerprints 打印配对时要核对的两行:本机与对方的公钥指纹,按指纹排序。
// 两台设备打印出的内容完全相同,用户比对两块屏幕即可;规则与界面一致
// (见 ui/lib/widgets/pairing_dialog.dart 的 pairingFingerprintRows)。
@@ -350,27 +357,95 @@ func joinPairing(ctx context.Context, c pb.DaemonServiceClient, code, address st
}
peer := resp.GetPeer()
fmt.Printf("\n 找到设备:%s(%s)\n", peer.GetName(), peer.GetPlatform())
- if err := printFingerprints(ctx, c, peer); err != nil {
+ return confirmPeer(ctx, c, peer, resp.GetPairingSession())
+}
+
+// nearbyPairing 打开「搜索附近设备」,列出附近同样打开了的设备,直到配对完成或 Ctrl+C。
+// 给了 target(设备名或实例名)时,它一出现就向它发起配对;没给时等对方点本机。
+// 期间本机在局域网里公开设备名,与界面上开着这个窗口一样。
+func nearbyPairing(ctx context.Context, c pb.DaemonServiceClient, target string) error {
+ ctx, cancel := context.WithCancel(ctx)
+ defer cancel()
+ events, err := c.Subscribe(ctx, &pb.SubscribeRequest{})
+ if err != nil {
+ return err
+ }
+ nearby, err := c.WatchNearby(ctx, &pb.Empty{})
+ if err != nil {
return err
}
- fmt.Print(" 确认配对?[y/N] ")
- var answer string
- fmt.Scanln(&answer)
- accept := answer == "y" || answer == "Y"
+ requests := make(chan *pb.Device, 1)
+ go func() {
+ for {
+ ev, err := events.Recv()
+ if err != nil {
+ return
+ }
+ if d := ev.GetDeviceChanged(); d != nil && d.GetPairingSession() != "" {
+ select {
+ case requests <- d:
+ default:
+ }
+ }
+ }
+ }()
+ lists := make(chan []*pb.NearbyDevice)
+ lost := make(chan error, 1)
+ go func() {
+ for {
+ msg, err := nearby.Recv()
+ if err != nil {
+ lost <- err
+ return
+ }
+ select {
+ case lists <- msg.GetDevices():
+ case <-ctx.Done():
+ return
+ }
+ }
+ }()
- if _, err := c.ConfirmPairing(ctx, &pb.ConfirmPairingRequest{
- PairingSession: resp.GetPairingSession(),
- Accept: accept,
- }); err != nil {
- return err
+ fmt.Println("\n 正在搜索附近的设备…(Ctrl+C 取消)")
+ for {
+ select {
+ case err := <-lost:
+ return err
+ case list := <-lists:
+ printNearby(list)
+ for _, d := range list {
+ if target == "" || d.GetPaired() || (d.GetName() != target && d.GetId() != target) {
+ continue
+ }
+ pairCtx, pairCancel := context.WithTimeout(ctx, 20*time.Second)
+ resp, err := c.PairNearby(pairCtx, &pb.PairNearbyRequest{Id: d.GetId()})
+ pairCancel()
+ if err != nil {
+ return err
+ }
+ fmt.Printf("\n %s 已回应\n", d.GetName())
+ return confirmPeer(ctx, c, resp.GetPeer(), resp.GetPairingSession())
+ }
+ case d := <-requests:
+ fmt.Printf("\n %s(%s)请求配对\n", d.GetName(), d.GetPlatform())
+ return confirmPeer(ctx, c, d, d.GetPairingSession())
+ }
}
- if accept {
- fmt.Println("\n ✓ 配对成功")
- } else {
- fmt.Println("\n 已取消")
+}
+
+func printNearby(list []*pb.NearbyDevice) {
+ fmt.Printf("\n %s 附近的设备:\n", time.Now().Format("15:04:05"))
+ if len(list) == 0 {
+ fmt.Println(" (没有。另一台也要打开「搜索附近设备」)")
+ }
+ for _, d := range list {
+ note := d.GetId()
+ if d.GetPaired() {
+ note = "已配对"
+ }
+ fmt.Printf(" %-24s %-8s %s\n", d.GetName(), d.GetPlatform(), note)
}
- return nil
}
func resolvePaths(dataDir string) (config.Paths, error) {
diff --git a/client-core/cmd/copysyncd/main.go b/client-core/cmd/copysyncd/main.go
index 7230459..ccd108d 100644
--- a/client-core/cmd/copysyncd/main.go
+++ b/client-core/cmd/copysyncd/main.go
@@ -331,6 +331,9 @@ func run(dataDir string) error {
ConfirmPairing: peerMgr.ConfirmPairing,
Unpair: peerMgr.Unpair,
SetDeviceAddress: peerMgr.SetDeviceAddress,
+ ShowNearby: peerMgr.ShowNearby,
+ Nearby: peerMgr.Nearby,
+ PairNearby: peerMgr.PairNearby,
SignalingConnected: peerMgr.Connected,
ServerConfigured: peerMgr.ServerConfigured,
LANEnabled: peerMgr.LANEnabled,
diff --git a/client-core/internal/peers/manager.go b/client-core/internal/peers/manager.go
index 366222a..1dd2893 100644
--- a/client-core/internal/peers/manager.go
+++ b/client-core/internal/peers/manager.go
@@ -183,11 +183,12 @@ func NewManager(opts Options) (*Manager, error) {
DeviceInfo: func() (string, string) {
return m.loadConfig().DeviceName, runtime.GOOS
},
- OnSignal: m.handleSignal,
- OnReachable: m.handleLANReachable,
- OnRestarted: m.handlePeerRestarted,
- AcceptPair: m.acceptLANPair,
- OnChange: m.notifyStatus,
+ OnSignal: m.handleSignal,
+ OnReachable: m.handleLANReachable,
+ OnRestarted: m.handlePeerRestarted,
+ AcceptPair: m.acceptLANPair,
+ AcceptNearby: m.acceptNearby,
+ OnChange: m.notifyStatus,
})
m.client = signaling.New(signaling.Options{
@@ -640,6 +641,27 @@ func (m *Manager) acceptLANPair(peer lan.PeerInfo) bool {
return err == nil
}
+// acceptNearby:有人在「搜索附近设备」里点了本机。弹出核对指纹的确认,由用户决定接不接受。
+// 对方没收到回复会接着重发,同一台设备的请求只弹一次。
+func (m *Manager) acceptNearby(peer lan.PeerInfo) bool {
+ m.mu.RLock()
+ for _, p := range m.pending {
+ if p.initiated && p.peer.ID == peer.ID {
+ m.mu.RUnlock()
+ return true
+ }
+ }
+ m.mu.RUnlock()
+
+ _, err := m.addPending(store.Device{
+ ID: peer.ID,
+ Name: peer.Name,
+ Platform: peer.Platform,
+ PublicKey: peer.PublicKey,
+ }, true, peer.Addrs)
+ return err == nil
+}
+
// ErrBadPeerID 表示对方的 device_id 与公钥对不上:有人在转发途中改了它。
var ErrBadPeerID = errors.New("对方的设备 ID 与公钥不匹配")
@@ -838,6 +860,47 @@ func (m *Manager) redeemViaServer(ctx context.Context, code string) (*pb.Device,
}
}
+// ShowNearby 在「搜索附近设备」窗口打开期间公开本机,窗口关掉时调用返回的函数。见 lan.Transport.ShowNearby。
+func (m *Manager) ShowNearby() (hide func()) { return m.lan.ShowNearby() }
+
+// Nearby 返回附近同样打开了「搜索附近设备」窗口的设备。
+func (m *Manager) Nearby() []*pb.NearbyDevice {
+ list := m.lan.Nearby()
+ m.mu.RLock()
+ defer m.mu.RUnlock()
+ out := make([]*pb.NearbyDevice, 0, len(list))
+ for _, n := range list {
+ _, paired := m.known[n.PeerID]
+ out = append(out, &pb.NearbyDevice{
+ Id: n.ID,
+ Name: n.Name,
+ Platform: n.Platform,
+ Paired: n.PeerID != "" && paired,
+ })
+ }
+ return out
+}
+
+// PairNearby 向附近的一台设备发起配对,返回待用户核对的对端信息与会话 ID。
+// 与 RedeemPairingCode 一样,此时尚未建立互信——必须再调 ConfirmPairing。
+func (m *Manager) PairNearby(ctx context.Context, id string) (*pb.Device, string, error) {
+ if !m.lan.Running() {
+ return nil, "", ErrNoChannel
+ }
+ lctx, cancel := context.WithTimeout(ctx, 5*time.Second)
+ peer, err := m.lan.PairNearby(lctx, id)
+ cancel()
+ if err != nil {
+ return nil, "", err
+ }
+ dev := store.Device{ID: peer.ID, Name: peer.Name, Platform: peer.Platform, PublicKey: peer.PublicKey}
+ session, err := m.addPending(dev, false, peer.Addrs)
+ if err != nil {
+ return nil, "", err
+ }
+ return m.toProto(dev, false, session), session, nil
+}
+
// ConfirmPairing 在用户核对指纹后落库,正式建立互信。
func (m *Manager) ConfirmPairing(ctx context.Context, session string, accept bool) error {
m.mu.Lock()
diff --git a/client-core/internal/peers/manager_test.go b/client-core/internal/peers/manager_test.go
index bd70f31..cdab8e5 100644
--- a/client-core/internal/peers/manager_test.go
+++ b/client-core/internal/peers/manager_test.go
@@ -284,3 +284,86 @@ func TestCodeUsableOnceAcrossChannels(t *testing.T) {
case <-time.After(time.Second):
}
}
+
+// 搜索附近设备:两台都打开窗口,a 点了 b,b 弹出确认(重复的请求只弹一次),
+// 双方核对后确认、直连;之后 b 在 a 的列表里显示为已配对。
+func TestPairNearby(t *testing.T) {
+ net := lan.NewMemoryNetwork()
+ a, b := newDevice(t, "办公室的 Mac", net, lanOnly()), newDevice(t, "b", net, lanOnly())
+ waitLANUp(t, a, b)
+ hideA, hideB := a.m.ShowNearby(), b.m.ShowNearby()
+ defer hideA()
+ defer hideB()
+
+ var target *pb.NearbyDevice
+ waitFor(t, "a 看到附近的 b", func() bool {
+ list := a.m.Nearby()
+ if len(list) == 1 {
+ target = list[0]
+ }
+ return target != nil
+ })
+ if target.GetName() != "b" || target.GetPaired() {
+ t.Fatalf("附近的设备信息不对: %v", target)
+ }
+ waitFor(t, "b 看到附近的 a", func() bool {
+ list := b.m.Nearby()
+ return len(list) == 1 && list[0].GetName() == "办公室的 Mac"
+ })
+
+ ctx := context.Background()
+ peer, session, err := a.m.PairNearby(ctx, target.GetId())
+ if err != nil {
+ t.Fatalf("向附近的设备发起配对: %v", err)
+ }
+ if peer.GetId() != b.id() || peer.GetName() != "b" {
+ t.Fatalf("配对的不是 b: %v", peer)
+ }
+ var bSession string
+ select {
+ case bSession = <-b.sessions:
+ case <-time.After(5 * time.Second):
+ t.Fatal("b 没收到配对请求")
+ }
+ // a 没收到回复时会重发;同一台设备的请求只弹一次确认
+ if _, _, err := a.m.PairNearby(ctx, target.GetId()); err != nil {
+ t.Fatalf("再点一次: %v", err)
+ }
+ select {
+ case s := <-b.sessions:
+ t.Fatalf("同一台设备的请求不该再弹一次确认: %s", s)
+ case <-time.After(300 * time.Millisecond):
+ }
+
+ if err := b.m.ConfirmPairing(ctx, bSession, true); err != nil {
+ t.Fatal(err)
+ }
+ if err := a.m.ConfirmPairing(ctx, session, true); err != nil {
+ t.Fatal(err)
+ }
+ waitDirect(t, a, b)
+ sendAndExpect(t, a, b, "clip-nearby")
+ waitFor(t, "b 在 a 的列表里显示为已配对", func() bool {
+ list := a.m.Nearby()
+ return len(list) == 1 && list[0].GetPaired()
+ })
+}
+
+// 对方没打开窗口时看不到它,也配不上。
+func TestNearbyNeedsBothWindows(t *testing.T) {
+ net := lan.NewMemoryNetwork()
+ a, b := newDevice(t, "a", net, lanOnly()), newDevice(t, "b", net, lanOnly())
+ waitLANUp(t, a, b)
+ defer a.m.ShowNearby()()
+
+ time.Sleep(500 * time.Millisecond)
+ if list := a.m.Nearby(); len(list) != 0 {
+ t.Fatalf("b 没打开窗口,不该出现在附近: %v", list)
+ }
+ if _, _, err := a.m.PairNearby(context.Background(), "copysync-000000000000"); !errors.Is(err, lan.ErrNotFound) {
+ t.Fatalf("应当找不到,得到 %v", err)
+ }
+ if _, peers := b.m.Devices(); len(peers) != 0 {
+ t.Fatalf("b 不该多出设备: %v", peers)
+ }
+}
diff --git a/client-core/internal/rpc/server.go b/client-core/internal/rpc/server.go
index da77395..4b0a052 100644
--- a/client-core/internal/rpc/server.go
+++ b/client-core/internal/rpc/server.go
@@ -13,6 +13,7 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
+ "google.golang.org/protobuf/proto"
"github.com/baiyuze/copysync/client-core/internal/clipboard"
"github.com/baiyuze/copysync/client-core/internal/config"
@@ -44,13 +45,17 @@ type Deps struct {
Permission func() clipboard.Permission
OpenPermissionSettings func() error
// Network 返回最近一轮网络出口探测的结果
- Network func() *pb.NetworkInfo
- Devices func() (self *pb.Device, peers []*pb.Device)
- CreatePairingCode func(ctx context.Context) (code string, expiresAt time.Time, lanAddrs []string, err error)
- RedeemPairingCode func(ctx context.Context, code, address string) (*pb.Device, string, error)
- ConfirmPairing func(ctx context.Context, session string, accept bool) error
- Unpair func(ctx context.Context, deviceID string) error
- SetDeviceAddress func(ctx context.Context, deviceID, address string) error
+ Network func() *pb.NetworkInfo
+ Devices func() (self *pb.Device, peers []*pb.Device)
+ CreatePairingCode func(ctx context.Context) (code string, expiresAt time.Time, lanAddrs []string, err error)
+ RedeemPairingCode func(ctx context.Context, code, address string) (*pb.Device, string, error)
+ ConfirmPairing func(ctx context.Context, session string, accept bool) error
+ Unpair func(ctx context.Context, deviceID string) error
+ SetDeviceAddress func(ctx context.Context, deviceID, address string) error
+ // ShowNearby / Nearby / PairNearby 是「搜索附近设备」,见 lan/nearby.go
+ ShowNearby func() (hide func())
+ Nearby func() []*pb.NearbyDevice
+ PairNearby func(ctx context.Context, id string) (*pb.Device, string, error)
SignalingConnected func() bool
ServerConfigured func() bool
LANEnabled func() bool
@@ -430,3 +435,42 @@ func (s *Server) SetDeviceAddress(ctx context.Context, req *pb.SetDeviceAddressR
}
return &pb.Empty{}, nil
}
+
+// WatchNearby 在调用期间公开本机(界面上「搜索附近设备」的窗口开着),
+// 附近的设备有变化时推送最新的列表。窗口关掉、界面退出时调用随之结束,本机也随之撤下。
+func (s *Server) WatchNearby(_ *pb.Empty, stream grpc.ServerStreamingServer[pb.NearbyDevices]) error {
+ if s.deps.ShowNearby == nil || s.deps.Nearby == nil {
+ return status.Error(codes.Unimplemented, "当前版本不支持搜索附近设备")
+ }
+ hide := s.deps.ShowNearby()
+ defer hide()
+
+ tk := time.NewTicker(time.Second)
+ defer tk.Stop()
+ var last *pb.NearbyDevices
+ for {
+ cur := &pb.NearbyDevices{Devices: s.deps.Nearby()}
+ if last == nil || !proto.Equal(cur, last) {
+ if err := stream.Send(cur); err != nil {
+ return err
+ }
+ last = cur
+ }
+ select {
+ case <-stream.Context().Done():
+ return nil
+ case <-tk.C:
+ }
+ }
+}
+
+func (s *Server) PairNearby(ctx context.Context, req *pb.PairNearbyRequest) (*pb.RedeemPairingCodeResponse, error) {
+ if s.deps.PairNearby == nil {
+ return nil, status.Error(codes.Unimplemented, "当前版本不支持搜索附近设备")
+ }
+ peer, session, err := s.deps.PairNearby(ctx, req.GetId())
+ if err != nil {
+ return nil, pairingStatus(err)
+ }
+ return &pb.RedeemPairingCodeResponse{Peer: peer, PairingSession: session}, nil
+}
diff --git a/client-core/internal/transport/lan/lan.go b/client-core/internal/transport/lan/lan.go
index 42e1827..4379ed0 100644
--- a/client-core/internal/transport/lan/lan.go
+++ b/client-core/internal/transport/lan/lan.go
@@ -105,6 +105,9 @@ type Options struct {
// AcceptPair 在有人用正确的配对码发来请求时调用。返回 false 表示这个码已经在别处
// (服务器那边)用掉了,请求会被拒绝。
AcceptPair func(peer PeerInfo) bool
+ // AcceptNearby 在有人从「搜索附近设备」里点了本机时调用(只在本机也开着这个窗口时)。
+ // 返回 false 会拒绝请求
+ AcceptNearby func(peer PeerInfo) bool
// OnChange 在开关、系统拦截状态变化时调用,用来刷新界面上的状态
OnChange func()
}
@@ -166,6 +169,11 @@ type Transport struct {
// 显示配对码的一方据此先往本机发一个空包,见 found
seeking int
pokedAt map[string]time.Time
+ // visible 是开着的「搜索附近设备」窗口数:大于零时广播里带上设备名,见 nearby.go
+ visible int
+ visibleName string
+ visiblePlatform string
+ nearby map[string]*nearbyState // mDNS 实例名 → 附近设备
// nextProbe 是下一次探测本地网络权限的时间,probeAddr 是探测的地址,见 probeTarget
nextProbe time.Time
probeAddr netip.Addr
@@ -210,6 +218,7 @@ func New(opts Options) *Transport {
responses: make(map[string]cachedResponse),
waiters: make(map[string]*pairWaiter),
pokedAt: make(map[string]time.Time),
+ nearby: make(map[string]*nearbyState),
reach: make(map[string]bool),
}
}
@@ -283,6 +292,7 @@ func (t *Transport) Stop() {
}
}
t.instances = make(map[string]seenInstance)
+ t.nearby = make(map[string]*nearbyState)
t.pairing = nil
t.mu.Unlock()
@@ -546,6 +556,10 @@ func (t *Transport) handle(pkt *pb.LanPacket, src netip.AddrPort) {
t.handlePairResponse(p.PairResponse, src)
case *pb.LanPacket_PairReject:
t.handlePairReject(p.PairReject)
+ case *pb.LanPacket_NearbyRequest:
+ t.handleNearbyRequest(p.NearbyRequest, src)
+ case *pb.LanPacket_NearbyPing:
+ t.handleNearbyPing(p.NearbyPing, src)
}
}
@@ -682,6 +696,14 @@ func (t *Transport) tick() {
for k, si := range t.instances {
if now.Sub(si.seen) > instanceTTL {
delete(t.instances, k)
+ delete(t.nearby, k)
+ }
+ }
+ for _, ns := range t.nearby {
+ for ap, at := range ns.addrs {
+ if now.Sub(at) > nearbyStale {
+ delete(ns.addrs, ap)
+ }
}
}
@@ -750,6 +772,7 @@ func (t *Transport) tick() {
if probe {
t.probe()
}
+ t.pingNearby()
}
// probe 往本网段里的一个地址发几个字节,看系统是否拦着(只有 macOS 有目标地址),
@@ -880,6 +903,7 @@ func (t *Transport) advertTextLocked() map[string]string {
if t.seeking > 0 {
text["s"] = "1"
}
+ t.nearbyAdvertLocked(text)
return text
}
@@ -912,6 +936,12 @@ func (t *Transport) found(inst Instance) {
if fresh && (inst.Text["p"] == "1" || inst.Text["s"] == "1") {
t.log.Debug("发现正在配对的实例", "实例", inst.Name, "地址", inst.Addr, "开放配对码", inst.Text["p"] == "1", "在找人配对", inst.Text["s"] == "1")
}
+ // 两边都开着「搜索附近设备」:马上告诉对方本机在,不必等下一轮 tick。
+ // pion 只在实例有变化时才报,这里不会被刷屏
+ var ping []netip.AddrPort
+ if _, ok := nearbyName(inst.Text); ok && t.visible > 0 {
+ ping = t.nearbyAddrsLocked(inst.Name)
+ }
var hello string
if id := t.tokens[inst.Text["t"]]; id != "" {
@@ -933,6 +963,7 @@ func (t *Transport) found(inst Instance) {
t.log.Debug("向在找人配对的实例敲门", "地址", poke)
_ = t.write(poke, []byte(magic))
}
+ t.sendNearbyPing(ping)
if hello != "" {
t.sendHello(hello, []netip.AddrPort{inst.Addr}, true, t.intervalFor(hello))
}
diff --git a/client-core/internal/transport/lan/lan_test.go b/client-core/internal/transport/lan/lan_test.go
index d7b77d7..c229fa4 100644
--- a/client-core/internal/transport/lan/lan_test.go
+++ b/client-core/internal/transport/lan/lan_test.go
@@ -26,6 +26,7 @@ type node struct {
known map[string]ed25519.PublicKey
book map[string][]string
accepted []PeerInfo
+ nearbyReq []PeerInfo // 从「搜索附近设备」发来的配对请求
signals chan *pb.SignalMessage
reach chan string
restarted chan string
@@ -77,6 +78,12 @@ func newNodeWith(t *testing.T, d Discovery) *node {
n.accepted = append(n.accepted, p)
return true
},
+ AcceptNearby: func(p PeerInfo) bool {
+ n.mu.Lock()
+ defer n.mu.Unlock()
+ n.nearbyReq = append(n.nearbyReq, p)
+ return true
+ },
})
if err := n.t.Start(); err != nil {
t.Fatal(err)
diff --git a/client-core/internal/transport/lan/nearby.go b/client-core/internal/transport/lan/nearby.go
new file mode 100644
index 0000000..7e93abf
--- /dev/null
+++ b/client-core/internal/transport/lan/nearby.go
@@ -0,0 +1,269 @@
+package lan
+
+import (
+ "context"
+ "encoding/base64"
+ "errors"
+ "net/netip"
+ "sort"
+ "sync"
+ "time"
+ "unicode/utf8"
+
+ pb "github.com/baiyuze/copysync/proto/gen/copysync/v1"
+)
+
+// 「搜索附近设备」:窗口打开期间在局域网里公开设备名,看得到附近同样打开了窗口的设备,
+// 点一下就能配对,不用输配对码。
+//
+// - 只在窗口打开期间公开:广播里平时只有匿名令牌,打开窗口才加上设备名(n)和系统(o)。
+// 设备名用 base64url 编码,经 Windows 的系统 DNS-SD 服务转一道也不会走样。
+// - mDNS 不会通知实例下线(pion 只报新出现和有变化的实例),所以两台都打开窗口时
+// 每 2 秒互发一个 LanNearbyPing,几秒收不到就当对方走了。它同时是敲门:
+// 没放行防火墙的 Windows 先往对方发过包,对方随后的配对请求才进得来。
+// - 配对请求不带配对码,只在窗口打开期间接受,由对方的用户在弹窗里决定接不接受;
+// 之后双方照常核对指纹,防中间人的办法与用配对码时相同。
+
+const (
+ // 这么久没收到对方的 ping、mDNS 也没有它的新消息,就从列表里拿掉。对方每 2 秒(tick)发一次
+ nearbyStale = 7 * time.Second
+ maxNearbyName = 60 // 设备名在广播里最多占的字节数(编码前)
+ maxNearbyAddrs = 4
+)
+
+// NearbyInstance 是附近一台打开了「搜索附近设备」窗口的设备。
+type NearbyInstance struct {
+ ID string // mDNS 实例名,本次启动内有效,用来发起配对
+ Name string
+ Platform string
+ // PeerID 非空表示这是已配对的设备(按广播里的令牌认出来的)
+ PeerID string
+}
+
+type nearbyState struct {
+ addrs map[netip.AddrPort]time.Time // 对方的 ping 实际来自的地址
+}
+
+// ShowNearby 让本机出现在附近设备的「搜索附近设备」窗口里,直到调用返回的 hide。
+// 可以叠加调用(同时开着两个界面),全部 hide 之后才撤下。
+func (t *Transport) ShowNearby() (hide func()) {
+ name, platform := "", ""
+ if t.opts.DeviceInfo != nil {
+ name, platform = t.opts.DeviceInfo()
+ }
+ t.mu.Lock()
+ t.visible++
+ t.visibleName, t.visiblePlatform = name, platform
+ t.mu.Unlock()
+ t.updateAdvert()
+ t.pingNearby()
+
+ var once sync.Once
+ return func() {
+ once.Do(func() {
+ t.mu.Lock()
+ t.visible--
+ if t.visible == 0 {
+ t.nearby = make(map[string]*nearbyState)
+ }
+ t.mu.Unlock()
+ t.updateAdvert()
+ })
+ }
+}
+
+// Nearby 返回附近打开了「搜索附近设备」窗口的设备,按名字排序。本机没打开窗口时为空。
+func (t *Transport) Nearby() []NearbyInstance {
+ now := time.Now()
+ t.mu.Lock()
+ defer t.mu.Unlock()
+ if !t.running || t.visible == 0 {
+ return nil
+ }
+ var out []NearbyInstance
+ for id, si := range t.instances {
+ name, ok := nearbyName(si.inst.Text)
+ if !ok || now.Sub(si.seen) > nearbyStale {
+ continue
+ }
+ out = append(out, NearbyInstance{
+ ID: id,
+ Name: name,
+ Platform: si.inst.Text["o"],
+ PeerID: t.tokens[si.inst.Text["t"]],
+ })
+ }
+ sort.Slice(out, func(i, j int) bool {
+ if out[i].Name != out[j].Name {
+ return out[i].Name < out[j].Name
+ }
+ return out[i].ID < out[j].ID
+ })
+ return out
+}
+
+// PairNearby 向附近的一台设备发起配对,直到 ctx 结束。对方关掉了窗口或一直没有回音时返回 ErrNotFound。
+func (t *Transport) PairNearby(ctx context.Context, id string) (PeerInfo, error) {
+ if !t.Running() {
+ return PeerInfo{}, ErrDisabled
+ }
+ targets := func() []netip.AddrPort {
+ t.mu.Lock()
+ defer t.mu.Unlock()
+ return t.nearbyAddrsLocked(id)
+ }
+ if len(targets()) == 0 {
+ return PeerInfo{}, ErrNotFound
+ }
+ peer, err := t.exchange(ctx, t.selfPairInfo(), nearbyRequest, targets, false)
+ if errors.Is(err, ErrCodeClosed) {
+ // 对方明确拒收:它已经关掉了窗口
+ return PeerInfo{}, ErrNotFound
+ }
+ return peer, err
+}
+
+func (t *Transport) handleNearbyRequest(ps *pb.LanPairSigned, src netip.AddrPort) {
+ info, ok := t.openPairInfo(ps)
+ if !ok || len(info.GetNonce()) < 8 || t.resendResponse(info.GetNonce(), src) {
+ return
+ }
+ t.mu.Lock()
+ visible := t.visible > 0
+ t.mu.Unlock()
+ if !visible {
+ t.reject(src, info.GetNonce(), "closed")
+ return
+ }
+ peer := peerFromInfo(info, src)
+ if t.opts.AcceptNearby == nil || !t.opts.AcceptNearby(peer) {
+ t.reject(src, info.GetNonce(), "closed")
+ return
+ }
+ t.log.Info("附近的设备请求配对,等待用户核对指纹", "peer", peer.Name, "src", src)
+ t.respondPair(info, peer, src)
+}
+
+// handleNearbyPing 记下对方还在、以及它实际在哪个地址。
+func (t *Transport) handleNearbyPing(p *pb.LanNearbyPing, src netip.AddrPort) {
+ now := time.Now()
+ t.mu.Lock()
+ defer t.mu.Unlock()
+ si, ok := t.instances[p.GetInstance()]
+ if t.visible == 0 || !ok {
+ return
+ }
+ if _, ok := nearbyName(si.inst.Text); !ok {
+ return
+ }
+ // mDNS 只在实例有变化时才报,对方一直开着窗口时靠 ping 让它保持新鲜
+ si.seen = now
+ t.instances[p.GetInstance()] = si
+ ns := t.nearby[p.GetInstance()]
+ if ns == nil {
+ ns = &nearbyState{addrs: make(map[netip.AddrPort]time.Time)}
+ t.nearby[p.GetInstance()] = ns
+ }
+ ns.addrs[src] = now
+}
+
+// pingNearby 告诉附近打开了窗口的每台设备:本机还在。本机没打开窗口时什么也不做。
+func (t *Transport) pingNearby() {
+ t.mu.Lock()
+ if !t.running || t.visible == 0 {
+ t.mu.Unlock()
+ return
+ }
+ var targets []netip.AddrPort
+ for id, si := range t.instances {
+ if _, ok := nearbyName(si.inst.Text); ok {
+ targets = append(targets, t.nearbyAddrsLocked(id)...)
+ }
+ }
+ t.mu.Unlock()
+ t.sendNearbyPing(targets)
+}
+
+func (t *Transport) sendNearbyPing(targets []netip.AddrPort) {
+ if len(targets) == 0 {
+ return
+ }
+ pkt, err := encode(&pb.LanPacket{Payload: &pb.LanPacket_NearbyPing{NearbyPing: &pb.LanNearbyPing{
+ Instance: t.instance,
+ }}})
+ if err != nil {
+ return
+ }
+ for _, dst := range targets {
+ _ = t.write(dst, pkt)
+ }
+}
+
+// nearbyAddrsLocked 是某个实例可能在的地址:ping 实际来自的地址在前,mDNS 报的地址在后。
+func (t *Transport) nearbyAddrsLocked(id string) []netip.AddrPort {
+ si, ok := t.instances[id]
+ if !ok {
+ return nil
+ }
+ var out []netip.AddrPort
+ if ns := t.nearby[id]; ns != nil {
+ for ap := range ns.addrs {
+ out = append(out, ap)
+ }
+ sort.Slice(out, func(i, j int) bool { return ns.addrs[out[i]].After(ns.addrs[out[j]]) })
+ }
+ if si.inst.Addr.IsValid() && !containsAddr(out, si.inst.Addr) {
+ out = append(out, si.inst.Addr)
+ }
+ if len(out) > maxNearbyAddrs {
+ out = out[:maxNearbyAddrs]
+ }
+ return out
+}
+
+// nearbyAdvertLocked 把本机的设备名和系统加进广播(窗口打开期间)。
+func (t *Transport) nearbyAdvertLocked(text map[string]string) {
+ if t.visible == 0 {
+ return
+ }
+ name := t.visibleName
+ if name == "" {
+ name = "CopySync"
+ }
+ text["n"] = base64.RawURLEncoding.EncodeToString([]byte(truncateUTF8(name, maxNearbyName)))
+ if t.visiblePlatform != "" {
+ text["o"] = t.visiblePlatform
+ }
+}
+
+// nearbyName 取出广播里的设备名。没有设备名(对方没打开窗口,或是旧版本)时返回 false。
+func nearbyName(text map[string]string) (string, bool) {
+ enc := text["n"]
+ if enc == "" {
+ return "", false
+ }
+ b, err := base64.RawURLEncoding.DecodeString(enc)
+ if err != nil || len(b) == 0 || !utf8.Valid(b) {
+ return "", false
+ }
+ return string(b), true
+}
+
+func truncateUTF8(s string, max int) string {
+ if len(s) <= max {
+ return s
+ }
+ for max > 0 && !utf8.RuneStart(s[max]) {
+ max--
+ }
+ return s[:max]
+}
+
+func containsAddr(list []netip.AddrPort, ap netip.AddrPort) bool {
+ for _, x := range list {
+ if x == ap {
+ return true
+ }
+ }
+ return false
+}
diff --git a/client-core/internal/transport/lan/nearby_test.go b/client-core/internal/transport/lan/nearby_test.go
new file mode 100644
index 0000000..f078857
--- /dev/null
+++ b/client-core/internal/transport/lan/nearby_test.go
@@ -0,0 +1,158 @@
+package lan
+
+import (
+ "context"
+ "errors"
+ "testing"
+ "time"
+)
+
+// waitNearby 等到 n 的「附近的设备」里正好有 want 台。
+func waitNearby(t *testing.T, n *node, want int) []NearbyInstance {
+ t.Helper()
+ deadline := time.Now().Add(3 * time.Second)
+ for {
+ got := n.t.Nearby()
+ if len(got) == want {
+ return got
+ }
+ if time.Now().After(deadline) {
+ t.Fatalf("%s 附近应有 %d 台设备,得到 %+v", n.id.DeviceID[:6], want, got)
+ }
+ time.Sleep(20 * time.Millisecond)
+ }
+}
+
+// 设备名只在窗口打开期间公开;两台都打开才互相看得到,关掉就消失。
+func TestNearbyOnlyWhileShown(t *testing.T) {
+ net := NewMemoryNetwork()
+ a, b := newNode(t, net), newNode(t, net)
+
+ if got := a.t.Nearby(); len(got) != 0 {
+ t.Fatalf("没打开窗口时不该有附近的设备: %+v", got)
+ }
+ a.t.mu.Lock()
+ for _, si := range a.t.instances {
+ if _, ok := nearbyName(si.inst.Text); ok {
+ t.Errorf("没打开窗口的设备不该广播设备名: %v", si.inst.Text)
+ }
+ }
+ a.t.mu.Unlock()
+
+ hideA := a.t.ShowNearby()
+ defer hideA()
+ waitNearby(t, a, 0) // b 还没打开窗口
+
+ hideB := b.t.ShowNearby()
+ got := waitNearby(t, a, 1)
+ if got[0].Name != "node-"+b.id.DeviceID[:4] || got[0].Platform != "test" || got[0].PeerID != "" {
+ t.Fatalf("附近的设备信息不对: %+v", got[0])
+ }
+ waitNearby(t, b, 1)
+
+ hideB()
+ hideB() // 多调一次不该出错
+ waitNearby(t, a, 0)
+}
+
+// 已配对的设备也显示,按令牌认出来是谁。
+func TestNearbyRecognizesPairedDevice(t *testing.T) {
+ net := NewMemoryNetwork()
+ a, b := newNode(t, net), newNode(t, net)
+ pair(a, b)
+ defer a.t.ShowNearby()()
+ defer b.t.ShowNearby()()
+
+ if got := waitNearby(t, a, 1); got[0].PeerID != b.id.DeviceID {
+ t.Fatalf("应当认出已配对的设备: %+v", got[0])
+ }
+}
+
+// 点了附近的设备:不用配对码就交换身份,对方的上层收到请求、由用户决定。
+func TestNearbyPairing(t *testing.T) {
+ net := NewMemoryNetwork()
+ a, b := newNode(t, net), newNode(t, net)
+ defer a.t.ShowNearby()()
+ hideB := b.t.ShowNearby()
+ defer hideB()
+
+ target := waitNearby(t, a, 1)[0]
+ ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
+ defer cancel()
+ peer, err := a.t.PairNearby(ctx, target.ID)
+ if err != nil {
+ t.Fatalf("配对失败: %v", err)
+ }
+ if peer.ID != b.id.DeviceID || string(peer.PublicKey) != string(b.id.PublicKey) {
+ t.Fatalf("拿到的不是对方的身份: %+v", peer)
+ }
+ b.mu.Lock()
+ got := b.nearbyReq
+ b.mu.Unlock()
+ if len(got) != 1 || got[0].ID != a.id.DeviceID {
+ t.Fatalf("对方应当收到一次配对请求,得到 %+v", got)
+ }
+ if len(b.accepted) != 0 {
+ t.Fatal("不该走配对码那条路")
+ }
+
+ // 对方关掉了窗口:拒收,很快返回「找不到」,而不是等到超时
+ hideB()
+ start := time.Now()
+ ctx2, cancel2 := context.WithTimeout(context.Background(), 3*time.Second)
+ defer cancel2()
+ if _, err := a.t.PairNearby(ctx2, target.ID); !errors.Is(err, ErrNotFound) {
+ t.Fatalf("对方关掉窗口后应当找不到,得到 %v", err)
+ }
+ if time.Since(start) > 2*time.Second {
+ t.Errorf("被拒收后应当很快返回,用了 %v", time.Since(start))
+ }
+ if _, err := a.t.PairNearby(ctx2, "copysync-nobody"); !errors.Is(err, ErrNotFound) {
+ t.Fatalf("不认识的实例应当找不到,得到 %v", err)
+ }
+}
+
+// mDNS 不报下线:对方不再发 ping,几秒后就从列表里消失;一直发着就一直在。
+func TestNearbyNeedsPings(t *testing.T) {
+ net := NewMemoryNetwork()
+ a, b := newNode(t, net), newNode(t, net)
+ defer a.t.ShowNearby()()
+ defer b.t.ShowNearby()()
+ target := waitNearby(t, a, 1)[0]
+
+ age := func() {
+ a.t.mu.Lock()
+ si := a.t.instances[target.ID]
+ si.seen = time.Now().Add(-time.Minute)
+ a.t.instances[target.ID] = si
+ a.t.mu.Unlock()
+ }
+ age()
+ if got := a.t.Nearby(); len(got) != 0 {
+ t.Fatalf("太久没有消息的设备应当消失: %+v", got)
+ }
+ age()
+ b.t.pingNearby()
+ waitNearby(t, a, 1)
+}
+
+func TestNearbyNameEncoding(t *testing.T) {
+ text := map[string]string{}
+ tr := &Transport{visible: 1, visibleName: "光光的 MacBook Pro(公司)"}
+ tr.nearbyAdvertLocked(text)
+ if name, ok := nearbyName(text); !ok || name != "光光的 MacBook Pro(公司)" {
+ t.Fatalf("设备名往返后不一致: %q %v", name, ok)
+ }
+
+ long := ""
+ for i := 0; i < 40; i++ {
+ long += "设"
+ }
+ got := truncateUTF8(long, maxNearbyName)
+ if len(got) > maxNearbyName || len(got)%3 != 0 {
+ t.Fatalf("截断要落在字符边界上: %d 字节", len(got))
+ }
+ if _, ok := nearbyName(map[string]string{"n": "!!"}); ok {
+ t.Fatal("编码不对的设备名不该接受")
+ }
+}
diff --git a/client-core/internal/transport/lan/pairing.go b/client-core/internal/transport/lan/pairing.go
index 3ff6e49..1763be1 100644
--- a/client-core/internal/transport/lan/pairing.go
+++ b/client-core/internal/transport/lan/pairing.go
@@ -83,14 +83,21 @@ func (t *Transport) Pair(ctx context.Context, code string, extra []netip.AddrPor
if !t.Running() {
return PeerInfo{}, ErrDisabled
}
+ req := t.selfPairInfo()
+ req.Code = pairingcode.Normalize(code)
+ return t.exchange(ctx, req, pairRequest, func() []netip.AddrPort { return t.pairTargets(extra) }, true)
+}
+
+// exchange 每 500 毫秒把配对请求发往 targets 给出的地址,直到收到回复、被明确拒绝或 ctx 结束。
+// seek 为真时广播里带上 s=1,显示码的一方会先往本机发包,见 found。
+func (t *Transport) exchange(ctx context.Context, req *pb.LanPairInfo, kind pairKind,
+ targets func() []netip.AddrPort, seek bool) (PeerInfo, error) {
nonce := make([]byte, 16)
if _, err := cryptorand.Read(nonce); err != nil {
return PeerInfo{}, err
}
- req := t.selfPairInfo()
- req.Code = pairingcode.Normalize(code)
req.Nonce = nonce
- pkt, err := t.encodePairInfo(req, true)
+ pkt, err := t.encodePairInfo(req, kind)
if err != nil {
return PeerInfo{}, err
}
@@ -99,38 +106,40 @@ func (t *Transport) Pair(ctx context.Context, code string, extra []netip.AddrPor
w := &pairWaiter{resp: make(chan pairResult, 1), rejects: make(map[string]bool)}
t.mu.Lock()
t.waiters[key] = w
- t.seeking++
+ if seek {
+ t.seeking++
+ }
t.mu.Unlock()
- t.updateAdvert() // 广播里带上 s=1,显示码的一方会先往本机发包,见 found
+ if seek {
+ t.updateAdvert()
+ }
defer func() {
t.mu.Lock()
delete(t.waiters, key)
- t.seeking--
+ if seek {
+ t.seeking--
+ }
t.mu.Unlock()
- t.updateAdvert()
+ if seek {
+ t.updateAdvert()
+ }
}()
tk := time.NewTicker(500 * time.Millisecond)
defer tk.Stop()
for round := 0; ; round++ {
- targets := t.pairTargets(extra)
+ dsts := targets()
if round%4 == 0 {
- t.log.Debug("发送配对请求", "目标", targets)
+ t.log.Debug("发送配对请求", "目标", dsts)
}
- for _, dst := range targets {
+ for _, dst := range dsts {
_ = t.write(dst, pkt)
}
select {
case r := <-w.resp:
// 回复带着对方的签名:它此刻就在这个地址,确认配对后的第一次连接不必再等打招呼
t.sawPeer(r.info.GetDeviceId(), r.src, nil)
- return PeerInfo{
- ID: r.info.GetDeviceId(),
- Name: r.info.GetDeviceName(),
- Platform: r.info.GetPlatform(),
- PublicKey: r.info.GetPublicKey(),
- Addrs: mergeAddrs(r.info.GetAddresses(), r.src),
- }, nil
+ return peerFromInfo(r.info, r.src), nil
case <-ctx.Done():
if err := t.rejectError(w, true); err != nil {
return PeerInfo{}, err
@@ -180,18 +189,12 @@ func (t *Transport) pairTargets(extra []netip.AddrPort) []netip.AddrPort {
func (t *Transport) handlePairRequest(ps *pb.LanPairSigned, src netip.AddrPort) {
info, ok := t.openPairInfo(ps)
- if !ok || len(info.GetNonce()) < 8 {
+ if !ok || len(info.GetNonce()) < 8 || t.resendResponse(info.GetNonce(), src) {
return
}
- key := hex.EncodeToString(info.GetNonce())
now := time.Now()
t.mu.Lock()
- if cached, ok := t.responses[key]; ok {
- t.mu.Unlock()
- _ = t.write(src, cached.pkt)
- return
- }
p := t.pairing
reason := ""
closeAdvert := false
@@ -218,35 +221,54 @@ func (t *Transport) handlePairRequest(ps *pb.LanPairSigned, src netip.AddrPort)
return
}
- peer := PeerInfo{
- ID: info.GetDeviceId(),
- Name: info.GetDeviceName(),
- Platform: info.GetPlatform(),
- PublicKey: info.GetPublicKey(),
- Addrs: mergeAddrs(info.GetAddresses(), src),
- }
+ peer := peerFromInfo(info, src)
if t.opts.AcceptPair != nil && !t.opts.AcceptPair(peer) {
t.reject(src, info.GetNonce(), "closed")
return
}
+ t.log.Info("局域网配对请求已接受,等待用户核对指纹", "peer", peer.Name, "src", src)
+ t.respondPair(info, peer, src)
+}
+// resendResponse:对方没收到回复而重发了同一个请求时,把那份回复原样再发一次。
+func (t *Transport) resendResponse(nonce []byte, src netip.AddrPort) bool {
+ t.mu.Lock()
+ cached, ok := t.responses[hex.EncodeToString(nonce)]
+ t.mu.Unlock()
+ if ok {
+ _ = t.write(src, cached.pkt)
+ }
+ return ok
+}
+
+// respondPair 回复一个已接受的配对请求:本机的信息,回显请求的 nonce。
+func (t *Transport) respondPair(info *pb.LanPairInfo, peer PeerInfo, src netip.AddrPort) {
resp := t.selfPairInfo()
resp.Nonce = make([]byte, 16)
_, _ = cryptorand.Read(resp.Nonce)
resp.RequestNonce = info.GetNonce()
- pkt, err := t.encodePairInfo(resp, false)
+ pkt, err := t.encodePairInfo(resp, pairResponse)
if err != nil {
return
}
t.mu.Lock()
- t.responses[key] = cachedResponse{pkt: pkt, at: now}
+ t.responses[hex.EncodeToString(info.GetNonce())] = cachedResponse{pkt: pkt, at: time.Now()}
t.mu.Unlock()
- t.log.Info("局域网配对请求已接受,等待用户核对指纹", "peer", peer.Name, "src", src)
t.sawPeer(peer.ID, src, nil)
_ = t.write(src, pkt)
time.AfterFunc(resendDelay, func() { _ = t.write(src, pkt) })
}
+func peerFromInfo(info *pb.LanPairInfo, src netip.AddrPort) PeerInfo {
+ return PeerInfo{
+ ID: info.GetDeviceId(),
+ Name: info.GetDeviceName(),
+ Platform: info.GetPlatform(),
+ PublicKey: info.GetPublicKey(),
+ Addrs: mergeAddrs(info.GetAddresses(), src),
+ }
+}
+
func (t *Transport) handlePairResponse(ps *pb.LanPairSigned, src netip.AddrPort) {
info, ok := t.openPairInfo(ps)
if !ok {
@@ -304,14 +326,26 @@ func (t *Transport) selfPairInfo() *pb.LanPairInfo {
}
}
-func (t *Transport) encodePairInfo(info *pb.LanPairInfo, request bool) ([]byte, error) {
+// pairKind 是签名的配对消息放在 LanPacket 的哪个位置。
+type pairKind int
+
+const (
+ pairRequest pairKind = iota
+ pairResponse
+ nearbyRequest // 在「搜索附近设备」里点了对方,不带配对码
+)
+
+func (t *Transport) encodePairInfo(info *pb.LanPairInfo, kind pairKind) ([]byte, error) {
payload, err := proto.Marshal(info)
if err != nil {
return nil, err
}
ps := &pb.LanPairSigned{Payload: payload, Signature: t.id.Sign(payload)}
- if request {
+ switch kind {
+ case pairRequest:
return encode(&pb.LanPacket{Payload: &pb.LanPacket_PairRequest{PairRequest: ps}})
+ case nearbyRequest:
+ return encode(&pb.LanPacket{Payload: &pb.LanPacket_NearbyRequest{NearbyRequest: ps}})
}
return encode(&pb.LanPacket{Payload: &pb.LanPacket_PairResponse{PairResponse: ps}})
}
diff --git a/proto/copysync/v1/daemon.proto b/proto/copysync/v1/daemon.proto
index 847dce1..2a715cc 100644
--- a/proto/copysync/v1/daemon.proto
+++ b/proto/copysync/v1/daemon.proto
@@ -31,6 +31,11 @@ service DaemonService {
rpc Unpair(UnpairRequest) returns (Empty);
// 手动告诉后台服务某台设备的局域网地址:跨网段、或两边都换了地址时用
rpc SetDeviceAddress(SetDeviceAddressRequest) returns (Empty);
+ // 「搜索附近设备」窗口打开期间保持这个调用,窗口关掉时取消。期间本机在局域网里公开设备名,
+ // 并在附近同样打开了这个窗口的设备有变化时推送最新的列表
+ rpc WatchNearby(Empty) returns (stream NearbyDevices);
+ // 向附近的一台设备发起配对。之后与 RedeemPairingCode 一样,双方核对指纹后各自 ConfirmPairing
+ rpc PairNearby(PairNearbyRequest) returns (RedeemPairingCodeResponse);
rpc GetConfig(Empty) returns (Config);
rpc UpdateConfig(Config) returns (Config);
@@ -215,6 +220,22 @@ message ConfirmPairingRequest {
bool accept = 2;
}
+// 附近一台打开了「搜索附近设备」窗口的设备。
+message NearbyDevice {
+ string id = 1; // 对方这次启动的 mDNS 实例名,用来发起配对
+ string name = 2;
+ string platform = 3; // darwin / windows
+ bool paired = 4; // 已经与本机配对
+}
+
+message NearbyDevices {
+ repeated NearbyDevice devices = 1;
+}
+
+message PairNearbyRequest {
+ string id = 1;
+}
+
message UnpairRequest {
string device_id = 1;
}
diff --git a/proto/copysync/v1/wire.proto b/proto/copysync/v1/wire.proto
index 98af059..be6b8f3 100644
--- a/proto/copysync/v1/wire.proto
+++ b/proto/copysync/v1/wire.proto
@@ -173,6 +173,12 @@ message ServerError {
// 先往对方发一个,让本机的有状态防火墙放行对方随后的配对请求。收到的一方直接忽略。
// 配对请求与回复各自用发送方自带的公钥签名:这只能证明发送方持有那把私钥,
// 防中间人仍然靠双方肉眼核对指纹——与经服务器配对时一样。
+//
+// 「搜索附近设备」:窗口打开期间,mDNS 广播里带上设备名(n,base64url 编码的 UTF-8)
+// 和系统(o)。两台都打开时互相看得到,每 2 秒互发一个 LanNearbyPing:
+// mDNS 不会通知实例下线,靠它判断对方还在;它也是敲门,让对方的配对请求进得来。
+// 点了对方就发 nearby_request:与 pair_request 相同,只是不带配对码,
+// 对方只在窗口打开期间接受。回复仍是 pair_response 或 pair_reject。
message LanPacket {
oneof payload {
@@ -180,6 +186,8 @@ message LanPacket {
LanPairSigned pair_request = 2;
LanPairSigned pair_response = 3;
LanPairReject pair_reject = 4;
+ LanPairSigned nearby_request = 5;
+ LanNearbyPing nearby_ping = 6;
}
}
@@ -217,6 +225,10 @@ message LanPairReject {
string reason = 2; // wrong_code / closed / too_many_attempts
}
+message LanNearbyPing {
+ string instance = 1; // 发送方的 mDNS 实例名
+}
+
// ═══════════════════ 设备间协议(DataChannel 承载)═══════════════════
//
// 控制消息与数据流走不同的 DataChannel,避免大文件传输阻塞控制通道。
diff --git a/proto/gen/copysync/v1/daemon.pb.go b/proto/gen/copysync/v1/daemon.pb.go
index 04e851e..7affb1b 100644
--- a/proto/gen/copysync/v1/daemon.pb.go
+++ b/proto/gen/copysync/v1/daemon.pb.go
@@ -1401,6 +1401,163 @@ func (x *ConfirmPairingRequest) GetAccept() bool {
return false
}
+// 附近一台打开了「搜索附近设备」窗口的设备。
+type NearbyDevice struct {
+ state protoimpl.MessageState `protogen:"open.v1"`
+ Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` // 对方这次启动的 mDNS 实例名,用来发起配对
+ Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
+ Platform string `protobuf:"bytes,3,opt,name=platform,proto3" json:"platform,omitempty"` // darwin / windows
+ Paired bool `protobuf:"varint,4,opt,name=paired,proto3" json:"paired,omitempty"` // 已经与本机配对
+ unknownFields protoimpl.UnknownFields
+ sizeCache protoimpl.SizeCache
+}
+
+func (x *NearbyDevice) Reset() {
+ *x = NearbyDevice{}
+ mi := &file_copysync_v1_daemon_proto_msgTypes[17]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+}
+
+func (x *NearbyDevice) String() string {
+ return protoimpl.X.MessageStringOf(x)
+}
+
+func (*NearbyDevice) ProtoMessage() {}
+
+func (x *NearbyDevice) ProtoReflect() protoreflect.Message {
+ mi := &file_copysync_v1_daemon_proto_msgTypes[17]
+ if x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
+}
+
+// Deprecated: Use NearbyDevice.ProtoReflect.Descriptor instead.
+func (*NearbyDevice) Descriptor() ([]byte, []int) {
+ return file_copysync_v1_daemon_proto_rawDescGZIP(), []int{17}
+}
+
+func (x *NearbyDevice) GetId() string {
+ if x != nil {
+ return x.Id
+ }
+ return ""
+}
+
+func (x *NearbyDevice) GetName() string {
+ if x != nil {
+ return x.Name
+ }
+ return ""
+}
+
+func (x *NearbyDevice) GetPlatform() string {
+ if x != nil {
+ return x.Platform
+ }
+ return ""
+}
+
+func (x *NearbyDevice) GetPaired() bool {
+ if x != nil {
+ return x.Paired
+ }
+ return false
+}
+
+type NearbyDevices struct {
+ state protoimpl.MessageState `protogen:"open.v1"`
+ Devices []*NearbyDevice `protobuf:"bytes,1,rep,name=devices,proto3" json:"devices,omitempty"`
+ unknownFields protoimpl.UnknownFields
+ sizeCache protoimpl.SizeCache
+}
+
+func (x *NearbyDevices) Reset() {
+ *x = NearbyDevices{}
+ mi := &file_copysync_v1_daemon_proto_msgTypes[18]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+}
+
+func (x *NearbyDevices) String() string {
+ return protoimpl.X.MessageStringOf(x)
+}
+
+func (*NearbyDevices) ProtoMessage() {}
+
+func (x *NearbyDevices) ProtoReflect() protoreflect.Message {
+ mi := &file_copysync_v1_daemon_proto_msgTypes[18]
+ if x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
+}
+
+// Deprecated: Use NearbyDevices.ProtoReflect.Descriptor instead.
+func (*NearbyDevices) Descriptor() ([]byte, []int) {
+ return file_copysync_v1_daemon_proto_rawDescGZIP(), []int{18}
+}
+
+func (x *NearbyDevices) GetDevices() []*NearbyDevice {
+ if x != nil {
+ return x.Devices
+ }
+ return nil
+}
+
+type PairNearbyRequest struct {
+ state protoimpl.MessageState `protogen:"open.v1"`
+ Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
+ unknownFields protoimpl.UnknownFields
+ sizeCache protoimpl.SizeCache
+}
+
+func (x *PairNearbyRequest) Reset() {
+ *x = PairNearbyRequest{}
+ mi := &file_copysync_v1_daemon_proto_msgTypes[19]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+}
+
+func (x *PairNearbyRequest) String() string {
+ return protoimpl.X.MessageStringOf(x)
+}
+
+func (*PairNearbyRequest) ProtoMessage() {}
+
+func (x *PairNearbyRequest) ProtoReflect() protoreflect.Message {
+ mi := &file_copysync_v1_daemon_proto_msgTypes[19]
+ if x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
+}
+
+// Deprecated: Use PairNearbyRequest.ProtoReflect.Descriptor instead.
+func (*PairNearbyRequest) Descriptor() ([]byte, []int) {
+ return file_copysync_v1_daemon_proto_rawDescGZIP(), []int{19}
+}
+
+func (x *PairNearbyRequest) GetId() string {
+ if x != nil {
+ return x.Id
+ }
+ return ""
+}
+
type UnpairRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
DeviceId string `protobuf:"bytes,1,opt,name=device_id,json=deviceId,proto3" json:"device_id,omitempty"`
@@ -1410,7 +1567,7 @@ type UnpairRequest struct {
func (x *UnpairRequest) Reset() {
*x = UnpairRequest{}
- mi := &file_copysync_v1_daemon_proto_msgTypes[17]
+ mi := &file_copysync_v1_daemon_proto_msgTypes[20]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -1422,7 +1579,7 @@ func (x *UnpairRequest) String() string {
func (*UnpairRequest) ProtoMessage() {}
func (x *UnpairRequest) ProtoReflect() protoreflect.Message {
- mi := &file_copysync_v1_daemon_proto_msgTypes[17]
+ mi := &file_copysync_v1_daemon_proto_msgTypes[20]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -1435,7 +1592,7 @@ func (x *UnpairRequest) ProtoReflect() protoreflect.Message {
// Deprecated: Use UnpairRequest.ProtoReflect.Descriptor instead.
func (*UnpairRequest) Descriptor() ([]byte, []int) {
- return file_copysync_v1_daemon_proto_rawDescGZIP(), []int{17}
+ return file_copysync_v1_daemon_proto_rawDescGZIP(), []int{20}
}
func (x *UnpairRequest) GetDeviceId() string {
@@ -1455,7 +1612,7 @@ type SetDeviceAddressRequest struct {
func (x *SetDeviceAddressRequest) Reset() {
*x = SetDeviceAddressRequest{}
- mi := &file_copysync_v1_daemon_proto_msgTypes[18]
+ mi := &file_copysync_v1_daemon_proto_msgTypes[21]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -1467,7 +1624,7 @@ func (x *SetDeviceAddressRequest) String() string {
func (*SetDeviceAddressRequest) ProtoMessage() {}
func (x *SetDeviceAddressRequest) ProtoReflect() protoreflect.Message {
- mi := &file_copysync_v1_daemon_proto_msgTypes[18]
+ mi := &file_copysync_v1_daemon_proto_msgTypes[21]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -1480,7 +1637,7 @@ func (x *SetDeviceAddressRequest) ProtoReflect() protoreflect.Message {
// Deprecated: Use SetDeviceAddressRequest.ProtoReflect.Descriptor instead.
func (*SetDeviceAddressRequest) Descriptor() ([]byte, []int) {
- return file_copysync_v1_daemon_proto_rawDescGZIP(), []int{18}
+ return file_copysync_v1_daemon_proto_rawDescGZIP(), []int{21}
}
func (x *SetDeviceAddressRequest) GetDeviceId() string {
@@ -1527,7 +1684,7 @@ type Config struct {
func (x *Config) Reset() {
*x = Config{}
- mi := &file_copysync_v1_daemon_proto_msgTypes[19]
+ mi := &file_copysync_v1_daemon_proto_msgTypes[22]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -1539,7 +1696,7 @@ func (x *Config) String() string {
func (*Config) ProtoMessage() {}
func (x *Config) ProtoReflect() protoreflect.Message {
- mi := &file_copysync_v1_daemon_proto_msgTypes[19]
+ mi := &file_copysync_v1_daemon_proto_msgTypes[22]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -1552,7 +1709,7 @@ func (x *Config) ProtoReflect() protoreflect.Message {
// Deprecated: Use Config.ProtoReflect.Descriptor instead.
func (*Config) Descriptor() ([]byte, []int) {
- return file_copysync_v1_daemon_proto_rawDescGZIP(), []int{19}
+ return file_copysync_v1_daemon_proto_rawDescGZIP(), []int{22}
}
func (x *Config) GetAutoSyncThresholdBytes() int64 {
@@ -1668,7 +1825,7 @@ type NetworkInfo struct {
func (x *NetworkInfo) Reset() {
*x = NetworkInfo{}
- mi := &file_copysync_v1_daemon_proto_msgTypes[20]
+ mi := &file_copysync_v1_daemon_proto_msgTypes[23]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -1680,7 +1837,7 @@ func (x *NetworkInfo) String() string {
func (*NetworkInfo) ProtoMessage() {}
func (x *NetworkInfo) ProtoReflect() protoreflect.Message {
- mi := &file_copysync_v1_daemon_proto_msgTypes[20]
+ mi := &file_copysync_v1_daemon_proto_msgTypes[23]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -1693,7 +1850,7 @@ func (x *NetworkInfo) ProtoReflect() protoreflect.Message {
// Deprecated: Use NetworkInfo.ProtoReflect.Descriptor instead.
func (*NetworkInfo) Descriptor() ([]byte, []int) {
- return file_copysync_v1_daemon_proto_rawDescGZIP(), []int{20}
+ return file_copysync_v1_daemon_proto_rawDescGZIP(), []int{23}
}
func (x *NetworkInfo) GetLocalPort() int32 {
@@ -1753,7 +1910,7 @@ type LanInfo struct {
func (x *LanInfo) Reset() {
*x = LanInfo{}
- mi := &file_copysync_v1_daemon_proto_msgTypes[21]
+ mi := &file_copysync_v1_daemon_proto_msgTypes[24]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -1765,7 +1922,7 @@ func (x *LanInfo) String() string {
func (*LanInfo) ProtoMessage() {}
func (x *LanInfo) ProtoReflect() protoreflect.Message {
- mi := &file_copysync_v1_daemon_proto_msgTypes[21]
+ mi := &file_copysync_v1_daemon_proto_msgTypes[24]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -1778,7 +1935,7 @@ func (x *LanInfo) ProtoReflect() protoreflect.Message {
// Deprecated: Use LanInfo.ProtoReflect.Descriptor instead.
func (*LanInfo) Descriptor() ([]byte, []int) {
- return file_copysync_v1_daemon_proto_rawDescGZIP(), []int{21}
+ return file_copysync_v1_daemon_proto_rawDescGZIP(), []int{24}
}
func (x *LanInfo) GetEnabled() bool {
@@ -1837,7 +1994,7 @@ type LanPeer struct {
func (x *LanPeer) Reset() {
*x = LanPeer{}
- mi := &file_copysync_v1_daemon_proto_msgTypes[22]
+ mi := &file_copysync_v1_daemon_proto_msgTypes[25]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -1849,7 +2006,7 @@ func (x *LanPeer) String() string {
func (*LanPeer) ProtoMessage() {}
func (x *LanPeer) ProtoReflect() protoreflect.Message {
- mi := &file_copysync_v1_daemon_proto_msgTypes[22]
+ mi := &file_copysync_v1_daemon_proto_msgTypes[25]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -1862,7 +2019,7 @@ func (x *LanPeer) ProtoReflect() protoreflect.Message {
// Deprecated: Use LanPeer.ProtoReflect.Descriptor instead.
func (*LanPeer) Descriptor() ([]byte, []int) {
- return file_copysync_v1_daemon_proto_rawDescGZIP(), []int{22}
+ return file_copysync_v1_daemon_proto_rawDescGZIP(), []int{25}
}
func (x *LanPeer) GetDeviceId() string {
@@ -1919,7 +2076,7 @@ type NetworkEgress struct {
func (x *NetworkEgress) Reset() {
*x = NetworkEgress{}
- mi := &file_copysync_v1_daemon_proto_msgTypes[23]
+ mi := &file_copysync_v1_daemon_proto_msgTypes[26]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -1931,7 +2088,7 @@ func (x *NetworkEgress) String() string {
func (*NetworkEgress) ProtoMessage() {}
func (x *NetworkEgress) ProtoReflect() protoreflect.Message {
- mi := &file_copysync_v1_daemon_proto_msgTypes[23]
+ mi := &file_copysync_v1_daemon_proto_msgTypes[26]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -1944,7 +2101,7 @@ func (x *NetworkEgress) ProtoReflect() protoreflect.Message {
// Deprecated: Use NetworkEgress.ProtoReflect.Descriptor instead.
func (*NetworkEgress) Descriptor() ([]byte, []int) {
- return file_copysync_v1_daemon_proto_rawDescGZIP(), []int{23}
+ return file_copysync_v1_daemon_proto_rawDescGZIP(), []int{26}
}
func (x *NetworkEgress) GetAddress() string {
@@ -1995,7 +2152,7 @@ type Status struct {
func (x *Status) Reset() {
*x = Status{}
- mi := &file_copysync_v1_daemon_proto_msgTypes[24]
+ mi := &file_copysync_v1_daemon_proto_msgTypes[27]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -2007,7 +2164,7 @@ func (x *Status) String() string {
func (*Status) ProtoMessage() {}
func (x *Status) ProtoReflect() protoreflect.Message {
- mi := &file_copysync_v1_daemon_proto_msgTypes[24]
+ mi := &file_copysync_v1_daemon_proto_msgTypes[27]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -2020,7 +2177,7 @@ func (x *Status) ProtoReflect() protoreflect.Message {
// Deprecated: Use Status.ProtoReflect.Descriptor instead.
func (*Status) Descriptor() ([]byte, []int) {
- return file_copysync_v1_daemon_proto_rawDescGZIP(), []int{24}
+ return file_copysync_v1_daemon_proto_rawDescGZIP(), []int{27}
}
func (x *Status) GetDeviceId() string {
@@ -2103,7 +2260,7 @@ type GetImagePreviewRequest struct {
func (x *GetImagePreviewRequest) Reset() {
*x = GetImagePreviewRequest{}
- mi := &file_copysync_v1_daemon_proto_msgTypes[25]
+ mi := &file_copysync_v1_daemon_proto_msgTypes[28]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -2115,7 +2272,7 @@ func (x *GetImagePreviewRequest) String() string {
func (*GetImagePreviewRequest) ProtoMessage() {}
func (x *GetImagePreviewRequest) ProtoReflect() protoreflect.Message {
- mi := &file_copysync_v1_daemon_proto_msgTypes[25]
+ mi := &file_copysync_v1_daemon_proto_msgTypes[28]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -2128,7 +2285,7 @@ func (x *GetImagePreviewRequest) ProtoReflect() protoreflect.Message {
// Deprecated: Use GetImagePreviewRequest.ProtoReflect.Descriptor instead.
func (*GetImagePreviewRequest) Descriptor() ([]byte, []int) {
- return file_copysync_v1_daemon_proto_rawDescGZIP(), []int{25}
+ return file_copysync_v1_daemon_proto_rawDescGZIP(), []int{28}
}
func (x *GetImagePreviewRequest) GetClipId() string {
@@ -2156,7 +2313,7 @@ type GetImagePreviewResponse struct {
func (x *GetImagePreviewResponse) Reset() {
*x = GetImagePreviewResponse{}
- mi := &file_copysync_v1_daemon_proto_msgTypes[26]
+ mi := &file_copysync_v1_daemon_proto_msgTypes[29]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -2168,7 +2325,7 @@ func (x *GetImagePreviewResponse) String() string {
func (*GetImagePreviewResponse) ProtoMessage() {}
func (x *GetImagePreviewResponse) ProtoReflect() protoreflect.Message {
- mi := &file_copysync_v1_daemon_proto_msgTypes[26]
+ mi := &file_copysync_v1_daemon_proto_msgTypes[29]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -2181,7 +2338,7 @@ func (x *GetImagePreviewResponse) ProtoReflect() protoreflect.Message {
// Deprecated: Use GetImagePreviewResponse.ProtoReflect.Descriptor instead.
func (*GetImagePreviewResponse) Descriptor() ([]byte, []int) {
- return file_copysync_v1_daemon_proto_rawDescGZIP(), []int{26}
+ return file_copysync_v1_daemon_proto_rawDescGZIP(), []int{29}
}
func (x *GetImagePreviewResponse) GetPath() string {
@@ -2294,7 +2451,16 @@ const file_copysync_v1_daemon_proto_rawDesc = "" +
"\x0fpairing_session\x18\x02 \x01(\tR\x0epairingSession\"X\n" +
"\x15ConfirmPairingRequest\x12'\n" +
"\x0fpairing_session\x18\x01 \x01(\tR\x0epairingSession\x12\x16\n" +
- "\x06accept\x18\x02 \x01(\bR\x06accept\",\n" +
+ "\x06accept\x18\x02 \x01(\bR\x06accept\"f\n" +
+ "\fNearbyDevice\x12\x0e\n" +
+ "\x02id\x18\x01 \x01(\tR\x02id\x12\x12\n" +
+ "\x04name\x18\x02 \x01(\tR\x04name\x12\x1a\n" +
+ "\bplatform\x18\x03 \x01(\tR\bplatform\x12\x16\n" +
+ "\x06paired\x18\x04 \x01(\bR\x06paired\"D\n" +
+ "\rNearbyDevices\x123\n" +
+ "\adevices\x18\x01 \x03(\v2\x19.copysync.v1.NearbyDeviceR\adevices\"#\n" +
+ "\x11PairNearbyRequest\x12\x0e\n" +
+ "\x02id\x18\x01 \x01(\tR\x02id\",\n" +
"\rUnpairRequest\x12\x1b\n" +
"\tdevice_id\x18\x01 \x01(\tR\bdeviceId\"P\n" +
"\x17SetDeviceAddressRequest\x12\x1b\n" +
@@ -2395,8 +2561,7 @@ const file_copysync_v1_daemon_proto_rawDesc = "" +
"\x1cCLIPBOARD_PERMISSION_DEFAULT\x10\x02\x12\x1c\n" +
"\x18CLIPBOARD_PERMISSION_ASK\x10\x03\x12%\n" +
"!CLIPBOARD_PERMISSION_ALWAYS_ALLOW\x10\x04\x12$\n" +
- " CLIPBOARD_PERMISSION_ALWAYS_DENY\x10\x052\x8c\n" +
- "\n" +
+ " CLIPBOARD_PERMISSION_ALWAYS_DENY\x10\x052\xa3\v\n" +
"\rDaemonService\x12@\n" +
"\tSubscribe\x12\x1d.copysync.v1.SubscribeRequest\x1a\x12.copysync.v1.Event0\x01\x12P\n" +
"\vListHistory\x12\x1f.copysync.v1.ListHistoryRequest\x1a .copysync.v1.ListHistoryResponse\x12F\n" +
@@ -2409,7 +2574,10 @@ const file_copysync_v1_daemon_proto_rawDesc = "" +
"\x11RedeemPairingCode\x12%.copysync.v1.RedeemPairingCodeRequest\x1a&.copysync.v1.RedeemPairingCodeResponse\x12H\n" +
"\x0eConfirmPairing\x12\".copysync.v1.ConfirmPairingRequest\x1a\x12.copysync.v1.Empty\x128\n" +
"\x06Unpair\x12\x1a.copysync.v1.UnpairRequest\x1a\x12.copysync.v1.Empty\x12L\n" +
- "\x10SetDeviceAddress\x12$.copysync.v1.SetDeviceAddressRequest\x1a\x12.copysync.v1.Empty\x124\n" +
+ "\x10SetDeviceAddress\x12$.copysync.v1.SetDeviceAddressRequest\x1a\x12.copysync.v1.Empty\x12?\n" +
+ "\vWatchNearby\x12\x12.copysync.v1.Empty\x1a\x1a.copysync.v1.NearbyDevices0\x01\x12T\n" +
+ "\n" +
+ "PairNearby\x12\x1e.copysync.v1.PairNearbyRequest\x1a&.copysync.v1.RedeemPairingCodeResponse\x124\n" +
"\tGetConfig\x12\x12.copysync.v1.Empty\x1a\x13.copysync.v1.Config\x128\n" +
"\fUpdateConfig\x12\x13.copysync.v1.Config\x1a\x13.copysync.v1.Config\x124\n" +
"\tGetStatus\x12\x12.copysync.v1.Empty\x1a\x13.copysync.v1.Status\x12D\n" +
@@ -2431,7 +2599,7 @@ func file_copysync_v1_daemon_proto_rawDescGZIP() []byte {
}
var file_copysync_v1_daemon_proto_enumTypes = make([]protoimpl.EnumInfo, 4)
-var file_copysync_v1_daemon_proto_msgTypes = make([]protoimpl.MessageInfo, 27)
+var file_copysync_v1_daemon_proto_msgTypes = make([]protoimpl.MessageInfo, 30)
var file_copysync_v1_daemon_proto_goTypes = []any{
(ClipKind)(0), // 0: copysync.v1.ClipKind
(ClipStatus)(0), // 1: copysync.v1.ClipStatus
@@ -2454,16 +2622,19 @@ var file_copysync_v1_daemon_proto_goTypes = []any{
(*RedeemPairingCodeRequest)(nil), // 18: copysync.v1.RedeemPairingCodeRequest
(*RedeemPairingCodeResponse)(nil), // 19: copysync.v1.RedeemPairingCodeResponse
(*ConfirmPairingRequest)(nil), // 20: copysync.v1.ConfirmPairingRequest
- (*UnpairRequest)(nil), // 21: copysync.v1.UnpairRequest
- (*SetDeviceAddressRequest)(nil), // 22: copysync.v1.SetDeviceAddressRequest
- (*Config)(nil), // 23: copysync.v1.Config
- (*NetworkInfo)(nil), // 24: copysync.v1.NetworkInfo
- (*LanInfo)(nil), // 25: copysync.v1.LanInfo
- (*LanPeer)(nil), // 26: copysync.v1.LanPeer
- (*NetworkEgress)(nil), // 27: copysync.v1.NetworkEgress
- (*Status)(nil), // 28: copysync.v1.Status
- (*GetImagePreviewRequest)(nil), // 29: copysync.v1.GetImagePreviewRequest
- (*GetImagePreviewResponse)(nil), // 30: copysync.v1.GetImagePreviewResponse
+ (*NearbyDevice)(nil), // 21: copysync.v1.NearbyDevice
+ (*NearbyDevices)(nil), // 22: copysync.v1.NearbyDevices
+ (*PairNearbyRequest)(nil), // 23: copysync.v1.PairNearbyRequest
+ (*UnpairRequest)(nil), // 24: copysync.v1.UnpairRequest
+ (*SetDeviceAddressRequest)(nil), // 25: copysync.v1.SetDeviceAddressRequest
+ (*Config)(nil), // 26: copysync.v1.Config
+ (*NetworkInfo)(nil), // 27: copysync.v1.NetworkInfo
+ (*LanInfo)(nil), // 28: copysync.v1.LanInfo
+ (*LanPeer)(nil), // 29: copysync.v1.LanPeer
+ (*NetworkEgress)(nil), // 30: copysync.v1.NetworkEgress
+ (*Status)(nil), // 31: copysync.v1.Status
+ (*GetImagePreviewRequest)(nil), // 32: copysync.v1.GetImagePreviewRequest
+ (*GetImagePreviewResponse)(nil), // 33: copysync.v1.GetImagePreviewResponse
}
var file_copysync_v1_daemon_proto_depIdxs = []int32{
0, // 0: copysync.v1.ClipRecord.kind:type_name -> copysync.v1.ClipKind
@@ -2475,57 +2646,62 @@ var file_copysync_v1_daemon_proto_depIdxs = []int32{
8, // 6: copysync.v1.Event.progress:type_name -> copysync.v1.TransferProgress
9, // 7: copysync.v1.Event.device_changed:type_name -> copysync.v1.Device
3, // 8: copysync.v1.Event.permission_changed:type_name -> copysync.v1.ClipboardPermission
- 28, // 9: copysync.v1.Event.status_changed:type_name -> copysync.v1.Status
+ 31, // 9: copysync.v1.Event.status_changed:type_name -> copysync.v1.Status
0, // 10: copysync.v1.ListHistoryRequest.kind_filter:type_name -> copysync.v1.ClipKind
6, // 11: copysync.v1.ListHistoryResponse.records:type_name -> copysync.v1.ClipRecord
9, // 12: copysync.v1.ListDevicesResponse.self:type_name -> copysync.v1.Device
9, // 13: copysync.v1.ListDevicesResponse.peers:type_name -> copysync.v1.Device
9, // 14: copysync.v1.RedeemPairingCodeResponse.peer:type_name -> copysync.v1.Device
- 27, // 15: copysync.v1.NetworkInfo.egresses:type_name -> copysync.v1.NetworkEgress
- 25, // 16: copysync.v1.NetworkInfo.lan:type_name -> copysync.v1.LanInfo
- 26, // 17: copysync.v1.LanInfo.peers:type_name -> copysync.v1.LanPeer
- 3, // 18: copysync.v1.Status.clipboard_permission:type_name -> copysync.v1.ClipboardPermission
- 7, // 19: copysync.v1.DaemonService.Subscribe:input_type -> copysync.v1.SubscribeRequest
- 11, // 20: copysync.v1.DaemonService.ListHistory:input_type -> copysync.v1.ListHistoryRequest
- 13, // 21: copysync.v1.DaemonService.DeleteHistory:input_type -> copysync.v1.DeleteHistoryRequest
- 14, // 22: copysync.v1.DaemonService.Fetch:input_type -> copysync.v1.FetchRequest
- 15, // 23: copysync.v1.DaemonService.ApplyToClipboard:input_type -> copysync.v1.ApplyToClipboardRequest
- 29, // 24: copysync.v1.DaemonService.GetImagePreview:input_type -> copysync.v1.GetImagePreviewRequest
- 4, // 25: copysync.v1.DaemonService.ListDevices:input_type -> copysync.v1.Empty
- 4, // 26: copysync.v1.DaemonService.CreatePairingCode:input_type -> copysync.v1.Empty
- 18, // 27: copysync.v1.DaemonService.RedeemPairingCode:input_type -> copysync.v1.RedeemPairingCodeRequest
- 20, // 28: copysync.v1.DaemonService.ConfirmPairing:input_type -> copysync.v1.ConfirmPairingRequest
- 21, // 29: copysync.v1.DaemonService.Unpair:input_type -> copysync.v1.UnpairRequest
- 22, // 30: copysync.v1.DaemonService.SetDeviceAddress:input_type -> copysync.v1.SetDeviceAddressRequest
- 4, // 31: copysync.v1.DaemonService.GetConfig:input_type -> copysync.v1.Empty
- 23, // 32: copysync.v1.DaemonService.UpdateConfig:input_type -> copysync.v1.Config
- 4, // 33: copysync.v1.DaemonService.GetStatus:input_type -> copysync.v1.Empty
- 4, // 34: copysync.v1.DaemonService.RequestClipboardPermission:input_type -> copysync.v1.Empty
- 4, // 35: copysync.v1.DaemonService.RequestLocalNetworkPermission:input_type -> copysync.v1.Empty
- 4, // 36: copysync.v1.DaemonService.GetNetwork:input_type -> copysync.v1.Empty
- 10, // 37: copysync.v1.DaemonService.Subscribe:output_type -> copysync.v1.Event
- 12, // 38: copysync.v1.DaemonService.ListHistory:output_type -> copysync.v1.ListHistoryResponse
- 4, // 39: copysync.v1.DaemonService.DeleteHistory:output_type -> copysync.v1.Empty
- 4, // 40: copysync.v1.DaemonService.Fetch:output_type -> copysync.v1.Empty
- 4, // 41: copysync.v1.DaemonService.ApplyToClipboard:output_type -> copysync.v1.Empty
- 30, // 42: copysync.v1.DaemonService.GetImagePreview:output_type -> copysync.v1.GetImagePreviewResponse
- 16, // 43: copysync.v1.DaemonService.ListDevices:output_type -> copysync.v1.ListDevicesResponse
- 17, // 44: copysync.v1.DaemonService.CreatePairingCode:output_type -> copysync.v1.CreatePairingCodeResponse
- 19, // 45: copysync.v1.DaemonService.RedeemPairingCode:output_type -> copysync.v1.RedeemPairingCodeResponse
- 4, // 46: copysync.v1.DaemonService.ConfirmPairing:output_type -> copysync.v1.Empty
- 4, // 47: copysync.v1.DaemonService.Unpair:output_type -> copysync.v1.Empty
- 4, // 48: copysync.v1.DaemonService.SetDeviceAddress:output_type -> copysync.v1.Empty
- 23, // 49: copysync.v1.DaemonService.GetConfig:output_type -> copysync.v1.Config
- 23, // 50: copysync.v1.DaemonService.UpdateConfig:output_type -> copysync.v1.Config
- 28, // 51: copysync.v1.DaemonService.GetStatus:output_type -> copysync.v1.Status
- 4, // 52: copysync.v1.DaemonService.RequestClipboardPermission:output_type -> copysync.v1.Empty
- 4, // 53: copysync.v1.DaemonService.RequestLocalNetworkPermission:output_type -> copysync.v1.Empty
- 24, // 54: copysync.v1.DaemonService.GetNetwork:output_type -> copysync.v1.NetworkInfo
- 37, // [37:55] is the sub-list for method output_type
- 19, // [19:37] is the sub-list for method input_type
- 19, // [19:19] is the sub-list for extension type_name
- 19, // [19:19] is the sub-list for extension extendee
- 0, // [0:19] is the sub-list for field type_name
+ 21, // 15: copysync.v1.NearbyDevices.devices:type_name -> copysync.v1.NearbyDevice
+ 30, // 16: copysync.v1.NetworkInfo.egresses:type_name -> copysync.v1.NetworkEgress
+ 28, // 17: copysync.v1.NetworkInfo.lan:type_name -> copysync.v1.LanInfo
+ 29, // 18: copysync.v1.LanInfo.peers:type_name -> copysync.v1.LanPeer
+ 3, // 19: copysync.v1.Status.clipboard_permission:type_name -> copysync.v1.ClipboardPermission
+ 7, // 20: copysync.v1.DaemonService.Subscribe:input_type -> copysync.v1.SubscribeRequest
+ 11, // 21: copysync.v1.DaemonService.ListHistory:input_type -> copysync.v1.ListHistoryRequest
+ 13, // 22: copysync.v1.DaemonService.DeleteHistory:input_type -> copysync.v1.DeleteHistoryRequest
+ 14, // 23: copysync.v1.DaemonService.Fetch:input_type -> copysync.v1.FetchRequest
+ 15, // 24: copysync.v1.DaemonService.ApplyToClipboard:input_type -> copysync.v1.ApplyToClipboardRequest
+ 32, // 25: copysync.v1.DaemonService.GetImagePreview:input_type -> copysync.v1.GetImagePreviewRequest
+ 4, // 26: copysync.v1.DaemonService.ListDevices:input_type -> copysync.v1.Empty
+ 4, // 27: copysync.v1.DaemonService.CreatePairingCode:input_type -> copysync.v1.Empty
+ 18, // 28: copysync.v1.DaemonService.RedeemPairingCode:input_type -> copysync.v1.RedeemPairingCodeRequest
+ 20, // 29: copysync.v1.DaemonService.ConfirmPairing:input_type -> copysync.v1.ConfirmPairingRequest
+ 24, // 30: copysync.v1.DaemonService.Unpair:input_type -> copysync.v1.UnpairRequest
+ 25, // 31: copysync.v1.DaemonService.SetDeviceAddress:input_type -> copysync.v1.SetDeviceAddressRequest
+ 4, // 32: copysync.v1.DaemonService.WatchNearby:input_type -> copysync.v1.Empty
+ 23, // 33: copysync.v1.DaemonService.PairNearby:input_type -> copysync.v1.PairNearbyRequest
+ 4, // 34: copysync.v1.DaemonService.GetConfig:input_type -> copysync.v1.Empty
+ 26, // 35: copysync.v1.DaemonService.UpdateConfig:input_type -> copysync.v1.Config
+ 4, // 36: copysync.v1.DaemonService.GetStatus:input_type -> copysync.v1.Empty
+ 4, // 37: copysync.v1.DaemonService.RequestClipboardPermission:input_type -> copysync.v1.Empty
+ 4, // 38: copysync.v1.DaemonService.RequestLocalNetworkPermission:input_type -> copysync.v1.Empty
+ 4, // 39: copysync.v1.DaemonService.GetNetwork:input_type -> copysync.v1.Empty
+ 10, // 40: copysync.v1.DaemonService.Subscribe:output_type -> copysync.v1.Event
+ 12, // 41: copysync.v1.DaemonService.ListHistory:output_type -> copysync.v1.ListHistoryResponse
+ 4, // 42: copysync.v1.DaemonService.DeleteHistory:output_type -> copysync.v1.Empty
+ 4, // 43: copysync.v1.DaemonService.Fetch:output_type -> copysync.v1.Empty
+ 4, // 44: copysync.v1.DaemonService.ApplyToClipboard:output_type -> copysync.v1.Empty
+ 33, // 45: copysync.v1.DaemonService.GetImagePreview:output_type -> copysync.v1.GetImagePreviewResponse
+ 16, // 46: copysync.v1.DaemonService.ListDevices:output_type -> copysync.v1.ListDevicesResponse
+ 17, // 47: copysync.v1.DaemonService.CreatePairingCode:output_type -> copysync.v1.CreatePairingCodeResponse
+ 19, // 48: copysync.v1.DaemonService.RedeemPairingCode:output_type -> copysync.v1.RedeemPairingCodeResponse
+ 4, // 49: copysync.v1.DaemonService.ConfirmPairing:output_type -> copysync.v1.Empty
+ 4, // 50: copysync.v1.DaemonService.Unpair:output_type -> copysync.v1.Empty
+ 4, // 51: copysync.v1.DaemonService.SetDeviceAddress:output_type -> copysync.v1.Empty
+ 22, // 52: copysync.v1.DaemonService.WatchNearby:output_type -> copysync.v1.NearbyDevices
+ 19, // 53: copysync.v1.DaemonService.PairNearby:output_type -> copysync.v1.RedeemPairingCodeResponse
+ 26, // 54: copysync.v1.DaemonService.GetConfig:output_type -> copysync.v1.Config
+ 26, // 55: copysync.v1.DaemonService.UpdateConfig:output_type -> copysync.v1.Config
+ 31, // 56: copysync.v1.DaemonService.GetStatus:output_type -> copysync.v1.Status
+ 4, // 57: copysync.v1.DaemonService.RequestClipboardPermission:output_type -> copysync.v1.Empty
+ 4, // 58: copysync.v1.DaemonService.RequestLocalNetworkPermission:output_type -> copysync.v1.Empty
+ 27, // 59: copysync.v1.DaemonService.GetNetwork:output_type -> copysync.v1.NetworkInfo
+ 40, // [40:60] is the sub-list for method output_type
+ 20, // [20:40] is the sub-list for method input_type
+ 20, // [20:20] is the sub-list for extension type_name
+ 20, // [20:20] is the sub-list for extension extendee
+ 0, // [0:20] is the sub-list for field type_name
}
func init() { file_copysync_v1_daemon_proto_init() }
@@ -2548,7 +2724,7 @@ func file_copysync_v1_daemon_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_copysync_v1_daemon_proto_rawDesc), len(file_copysync_v1_daemon_proto_rawDesc)),
NumEnums: 4,
- NumMessages: 27,
+ NumMessages: 30,
NumExtensions: 0,
NumServices: 1,
},
diff --git a/proto/gen/copysync/v1/daemon_grpc.pb.go b/proto/gen/copysync/v1/daemon_grpc.pb.go
index d3c495b..656291c 100644
--- a/proto/gen/copysync/v1/daemon_grpc.pb.go
+++ b/proto/gen/copysync/v1/daemon_grpc.pb.go
@@ -36,6 +36,8 @@ const (
DaemonService_ConfirmPairing_FullMethodName = "/copysync.v1.DaemonService/ConfirmPairing"
DaemonService_Unpair_FullMethodName = "/copysync.v1.DaemonService/Unpair"
DaemonService_SetDeviceAddress_FullMethodName = "/copysync.v1.DaemonService/SetDeviceAddress"
+ DaemonService_WatchNearby_FullMethodName = "/copysync.v1.DaemonService/WatchNearby"
+ DaemonService_PairNearby_FullMethodName = "/copysync.v1.DaemonService/PairNearby"
DaemonService_GetConfig_FullMethodName = "/copysync.v1.DaemonService/GetConfig"
DaemonService_UpdateConfig_FullMethodName = "/copysync.v1.DaemonService/UpdateConfig"
DaemonService_GetStatus_FullMethodName = "/copysync.v1.DaemonService/GetStatus"
@@ -66,6 +68,11 @@ type DaemonServiceClient interface {
Unpair(ctx context.Context, in *UnpairRequest, opts ...grpc.CallOption) (*Empty, error)
// 手动告诉后台服务某台设备的局域网地址:跨网段、或两边都换了地址时用
SetDeviceAddress(ctx context.Context, in *SetDeviceAddressRequest, opts ...grpc.CallOption) (*Empty, error)
+ // 「搜索附近设备」窗口打开期间保持这个调用,窗口关掉时取消。期间本机在局域网里公开设备名,
+ // 并在附近同样打开了这个窗口的设备有变化时推送最新的列表
+ WatchNearby(ctx context.Context, in *Empty, opts ...grpc.CallOption) (grpc.ServerStreamingClient[NearbyDevices], error)
+ // 向附近的一台设备发起配对。之后与 RedeemPairingCode 一样,双方核对指纹后各自 ConfirmPairing
+ PairNearby(ctx context.Context, in *PairNearbyRequest, opts ...grpc.CallOption) (*RedeemPairingCodeResponse, error)
GetConfig(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Config, error)
UpdateConfig(ctx context.Context, in *Config, opts ...grpc.CallOption) (*Config, error)
GetStatus(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Status, error)
@@ -215,6 +222,35 @@ func (c *daemonServiceClient) SetDeviceAddress(ctx context.Context, in *SetDevic
return out, nil
}
+func (c *daemonServiceClient) WatchNearby(ctx context.Context, in *Empty, opts ...grpc.CallOption) (grpc.ServerStreamingClient[NearbyDevices], error) {
+ cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
+ stream, err := c.cc.NewStream(ctx, &DaemonService_ServiceDesc.Streams[1], DaemonService_WatchNearby_FullMethodName, cOpts...)
+ if err != nil {
+ return nil, err
+ }
+ x := &grpc.GenericClientStream[Empty, NearbyDevices]{ClientStream: stream}
+ if err := x.ClientStream.SendMsg(in); err != nil {
+ return nil, err
+ }
+ if err := x.ClientStream.CloseSend(); err != nil {
+ return nil, err
+ }
+ return x, nil
+}
+
+// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
+type DaemonService_WatchNearbyClient = grpc.ServerStreamingClient[NearbyDevices]
+
+func (c *daemonServiceClient) PairNearby(ctx context.Context, in *PairNearbyRequest, opts ...grpc.CallOption) (*RedeemPairingCodeResponse, error) {
+ cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
+ out := new(RedeemPairingCodeResponse)
+ err := c.cc.Invoke(ctx, DaemonService_PairNearby_FullMethodName, in, out, cOpts...)
+ if err != nil {
+ return nil, err
+ }
+ return out, nil
+}
+
func (c *daemonServiceClient) GetConfig(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Config, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(Config)
@@ -297,6 +333,11 @@ type DaemonServiceServer interface {
Unpair(context.Context, *UnpairRequest) (*Empty, error)
// 手动告诉后台服务某台设备的局域网地址:跨网段、或两边都换了地址时用
SetDeviceAddress(context.Context, *SetDeviceAddressRequest) (*Empty, error)
+ // 「搜索附近设备」窗口打开期间保持这个调用,窗口关掉时取消。期间本机在局域网里公开设备名,
+ // 并在附近同样打开了这个窗口的设备有变化时推送最新的列表
+ WatchNearby(*Empty, grpc.ServerStreamingServer[NearbyDevices]) error
+ // 向附近的一台设备发起配对。之后与 RedeemPairingCode 一样,双方核对指纹后各自 ConfirmPairing
+ PairNearby(context.Context, *PairNearbyRequest) (*RedeemPairingCodeResponse, error)
GetConfig(context.Context, *Empty) (*Config, error)
UpdateConfig(context.Context, *Config) (*Config, error)
GetStatus(context.Context, *Empty) (*Status, error)
@@ -353,6 +394,12 @@ func (UnimplementedDaemonServiceServer) Unpair(context.Context, *UnpairRequest)
func (UnimplementedDaemonServiceServer) SetDeviceAddress(context.Context, *SetDeviceAddressRequest) (*Empty, error) {
return nil, status.Error(codes.Unimplemented, "method SetDeviceAddress not implemented")
}
+func (UnimplementedDaemonServiceServer) WatchNearby(*Empty, grpc.ServerStreamingServer[NearbyDevices]) error {
+ return status.Error(codes.Unimplemented, "method WatchNearby not implemented")
+}
+func (UnimplementedDaemonServiceServer) PairNearby(context.Context, *PairNearbyRequest) (*RedeemPairingCodeResponse, error) {
+ return nil, status.Error(codes.Unimplemented, "method PairNearby not implemented")
+}
func (UnimplementedDaemonServiceServer) GetConfig(context.Context, *Empty) (*Config, error) {
return nil, status.Error(codes.Unimplemented, "method GetConfig not implemented")
}
@@ -601,6 +648,35 @@ func _DaemonService_SetDeviceAddress_Handler(srv interface{}, ctx context.Contex
return interceptor(ctx, in, info, handler)
}
+func _DaemonService_WatchNearby_Handler(srv interface{}, stream grpc.ServerStream) error {
+ m := new(Empty)
+ if err := stream.RecvMsg(m); err != nil {
+ return err
+ }
+ return srv.(DaemonServiceServer).WatchNearby(m, &grpc.GenericServerStream[Empty, NearbyDevices]{ServerStream: stream})
+}
+
+// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
+type DaemonService_WatchNearbyServer = grpc.ServerStreamingServer[NearbyDevices]
+
+func _DaemonService_PairNearby_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+ in := new(PairNearbyRequest)
+ if err := dec(in); err != nil {
+ return nil, err
+ }
+ if interceptor == nil {
+ return srv.(DaemonServiceServer).PairNearby(ctx, in)
+ }
+ info := &grpc.UnaryServerInfo{
+ Server: srv,
+ FullMethod: DaemonService_PairNearby_FullMethodName,
+ }
+ handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+ return srv.(DaemonServiceServer).PairNearby(ctx, req.(*PairNearbyRequest))
+ }
+ return interceptor(ctx, in, info, handler)
+}
+
func _DaemonService_GetConfig_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(Empty)
if err := dec(in); err != nil {
@@ -760,6 +836,10 @@ var DaemonService_ServiceDesc = grpc.ServiceDesc{
MethodName: "SetDeviceAddress",
Handler: _DaemonService_SetDeviceAddress_Handler,
},
+ {
+ MethodName: "PairNearby",
+ Handler: _DaemonService_PairNearby_Handler,
+ },
{
MethodName: "GetConfig",
Handler: _DaemonService_GetConfig_Handler,
@@ -791,6 +871,11 @@ var DaemonService_ServiceDesc = grpc.ServiceDesc{
Handler: _DaemonService_Subscribe_Handler,
ServerStreams: true,
},
+ {
+ StreamName: "WatchNearby",
+ Handler: _DaemonService_WatchNearby_Handler,
+ ServerStreams: true,
+ },
},
Metadata: "copysync/v1/daemon.proto",
}
diff --git a/proto/gen/copysync/v1/wire.pb.go b/proto/gen/copysync/v1/wire.pb.go
index 41753d5..b5d7090 100644
--- a/proto/gen/copysync/v1/wire.pb.go
+++ b/proto/gen/copysync/v1/wire.pb.go
@@ -1537,6 +1537,8 @@ type LanPacket struct {
// *LanPacket_PairRequest
// *LanPacket_PairResponse
// *LanPacket_PairReject
+ // *LanPacket_NearbyRequest
+ // *LanPacket_NearbyPing
Payload isLanPacket_Payload `protobuf_oneof:"payload"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
@@ -1615,6 +1617,24 @@ func (x *LanPacket) GetPairReject() *LanPairReject {
return nil
}
+func (x *LanPacket) GetNearbyRequest() *LanPairSigned {
+ if x != nil {
+ if x, ok := x.Payload.(*LanPacket_NearbyRequest); ok {
+ return x.NearbyRequest
+ }
+ }
+ return nil
+}
+
+func (x *LanPacket) GetNearbyPing() *LanNearbyPing {
+ if x != nil {
+ if x, ok := x.Payload.(*LanPacket_NearbyPing); ok {
+ return x.NearbyPing
+ }
+ }
+ return nil
+}
+
type isLanPacket_Payload interface {
isLanPacket_Payload()
}
@@ -1635,6 +1655,14 @@ type LanPacket_PairReject struct {
PairReject *LanPairReject `protobuf:"bytes,4,opt,name=pair_reject,json=pairReject,proto3,oneof"`
}
+type LanPacket_NearbyRequest struct {
+ NearbyRequest *LanPairSigned `protobuf:"bytes,5,opt,name=nearby_request,json=nearbyRequest,proto3,oneof"`
+}
+
+type LanPacket_NearbyPing struct {
+ NearbyPing *LanNearbyPing `protobuf:"bytes,6,opt,name=nearby_ping,json=nearbyPing,proto3,oneof"`
+}
+
func (*LanPacket_Signal) isLanPacket_Payload() {}
func (*LanPacket_PairRequest) isLanPacket_Payload() {}
@@ -1643,6 +1671,10 @@ func (*LanPacket_PairResponse) isLanPacket_Payload() {}
func (*LanPacket_PairReject) isLanPacket_Payload() {}
+func (*LanPacket_NearbyRequest) isLanPacket_Payload() {}
+
+func (*LanPacket_NearbyPing) isLanPacket_Payload() {}
+
// 已配对设备之间的上线通知。还没连通时定期发,连通后低频保活。
// 两端都往对方发,有状态的防火墙(Windows)会放行对方的包。
type LanHello struct {
@@ -1928,6 +1960,50 @@ func (x *LanPairReject) GetReason() string {
return ""
}
+type LanNearbyPing struct {
+ state protoimpl.MessageState `protogen:"open.v1"`
+ Instance string `protobuf:"bytes,1,opt,name=instance,proto3" json:"instance,omitempty"` // 发送方的 mDNS 实例名
+ unknownFields protoimpl.UnknownFields
+ sizeCache protoimpl.SizeCache
+}
+
+func (x *LanNearbyPing) Reset() {
+ *x = LanNearbyPing{}
+ mi := &file_copysync_v1_wire_proto_msgTypes[24]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+}
+
+func (x *LanNearbyPing) String() string {
+ return protoimpl.X.MessageStringOf(x)
+}
+
+func (*LanNearbyPing) ProtoMessage() {}
+
+func (x *LanNearbyPing) ProtoReflect() protoreflect.Message {
+ mi := &file_copysync_v1_wire_proto_msgTypes[24]
+ if x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
+}
+
+// Deprecated: Use LanNearbyPing.ProtoReflect.Descriptor instead.
+func (*LanNearbyPing) Descriptor() ([]byte, []int) {
+ return file_copysync_v1_wire_proto_rawDescGZIP(), []int{24}
+}
+
+func (x *LanNearbyPing) GetInstance() string {
+ if x != nil {
+ return x.Instance
+ }
+ return ""
+}
+
// 控制通道消息
type PeerMessage struct {
state protoimpl.MessageState `protogen:"open.v1"`
@@ -1946,7 +2022,7 @@ type PeerMessage struct {
func (x *PeerMessage) Reset() {
*x = PeerMessage{}
- mi := &file_copysync_v1_wire_proto_msgTypes[24]
+ mi := &file_copysync_v1_wire_proto_msgTypes[25]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -1958,7 +2034,7 @@ func (x *PeerMessage) String() string {
func (*PeerMessage) ProtoMessage() {}
func (x *PeerMessage) ProtoReflect() protoreflect.Message {
- mi := &file_copysync_v1_wire_proto_msgTypes[24]
+ mi := &file_copysync_v1_wire_proto_msgTypes[25]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -1971,7 +2047,7 @@ func (x *PeerMessage) ProtoReflect() protoreflect.Message {
// Deprecated: Use PeerMessage.ProtoReflect.Descriptor instead.
func (*PeerMessage) Descriptor() ([]byte, []int) {
- return file_copysync_v1_wire_proto_rawDescGZIP(), []int{24}
+ return file_copysync_v1_wire_proto_rawDescGZIP(), []int{25}
}
func (x *PeerMessage) GetPayload() isPeerMessage_Payload {
@@ -2087,7 +2163,7 @@ type LinkInfo struct {
func (x *LinkInfo) Reset() {
*x = LinkInfo{}
- mi := &file_copysync_v1_wire_proto_msgTypes[25]
+ mi := &file_copysync_v1_wire_proto_msgTypes[26]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -2099,7 +2175,7 @@ func (x *LinkInfo) String() string {
func (*LinkInfo) ProtoMessage() {}
func (x *LinkInfo) ProtoReflect() protoreflect.Message {
- mi := &file_copysync_v1_wire_proto_msgTypes[25]
+ mi := &file_copysync_v1_wire_proto_msgTypes[26]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -2112,7 +2188,7 @@ func (x *LinkInfo) ProtoReflect() protoreflect.Message {
// Deprecated: Use LinkInfo.ProtoReflect.Descriptor instead.
func (*LinkInfo) Descriptor() ([]byte, []int) {
- return file_copysync_v1_wire_proto_rawDescGZIP(), []int{25}
+ return file_copysync_v1_wire_proto_rawDescGZIP(), []int{26}
}
func (x *LinkInfo) GetRelayed() bool {
@@ -2145,7 +2221,7 @@ type ClipOffer struct {
func (x *ClipOffer) Reset() {
*x = ClipOffer{}
- mi := &file_copysync_v1_wire_proto_msgTypes[26]
+ mi := &file_copysync_v1_wire_proto_msgTypes[27]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -2157,7 +2233,7 @@ func (x *ClipOffer) String() string {
func (*ClipOffer) ProtoMessage() {}
func (x *ClipOffer) ProtoReflect() protoreflect.Message {
- mi := &file_copysync_v1_wire_proto_msgTypes[26]
+ mi := &file_copysync_v1_wire_proto_msgTypes[27]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -2170,7 +2246,7 @@ func (x *ClipOffer) ProtoReflect() protoreflect.Message {
// Deprecated: Use ClipOffer.ProtoReflect.Descriptor instead.
func (*ClipOffer) Descriptor() ([]byte, []int) {
- return file_copysync_v1_wire_proto_rawDescGZIP(), []int{26}
+ return file_copysync_v1_wire_proto_rawDescGZIP(), []int{27}
}
func (x *ClipOffer) GetClipId() string {
@@ -2246,7 +2322,7 @@ type PeerFetch struct {
func (x *PeerFetch) Reset() {
*x = PeerFetch{}
- mi := &file_copysync_v1_wire_proto_msgTypes[27]
+ mi := &file_copysync_v1_wire_proto_msgTypes[28]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -2258,7 +2334,7 @@ func (x *PeerFetch) String() string {
func (*PeerFetch) ProtoMessage() {}
func (x *PeerFetch) ProtoReflect() protoreflect.Message {
- mi := &file_copysync_v1_wire_proto_msgTypes[27]
+ mi := &file_copysync_v1_wire_proto_msgTypes[28]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -2271,7 +2347,7 @@ func (x *PeerFetch) ProtoReflect() protoreflect.Message {
// Deprecated: Use PeerFetch.ProtoReflect.Descriptor instead.
func (*PeerFetch) Descriptor() ([]byte, []int) {
- return file_copysync_v1_wire_proto_rawDescGZIP(), []int{27}
+ return file_copysync_v1_wire_proto_rawDescGZIP(), []int{28}
}
func (x *PeerFetch) GetClipId() string {
@@ -2291,7 +2367,7 @@ type FetchReject struct {
func (x *FetchReject) Reset() {
*x = FetchReject{}
- mi := &file_copysync_v1_wire_proto_msgTypes[28]
+ mi := &file_copysync_v1_wire_proto_msgTypes[29]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -2303,7 +2379,7 @@ func (x *FetchReject) String() string {
func (*FetchReject) ProtoMessage() {}
func (x *FetchReject) ProtoReflect() protoreflect.Message {
- mi := &file_copysync_v1_wire_proto_msgTypes[28]
+ mi := &file_copysync_v1_wire_proto_msgTypes[29]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -2316,7 +2392,7 @@ func (x *FetchReject) ProtoReflect() protoreflect.Message {
// Deprecated: Use FetchReject.ProtoReflect.Descriptor instead.
func (*FetchReject) Descriptor() ([]byte, []int) {
- return file_copysync_v1_wire_proto_rawDescGZIP(), []int{28}
+ return file_copysync_v1_wire_proto_rawDescGZIP(), []int{29}
}
func (x *FetchReject) GetClipId() string {
@@ -2347,7 +2423,7 @@ type TransferHeader struct {
func (x *TransferHeader) Reset() {
*x = TransferHeader{}
- mi := &file_copysync_v1_wire_proto_msgTypes[29]
+ mi := &file_copysync_v1_wire_proto_msgTypes[30]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -2359,7 +2435,7 @@ func (x *TransferHeader) String() string {
func (*TransferHeader) ProtoMessage() {}
func (x *TransferHeader) ProtoReflect() protoreflect.Message {
- mi := &file_copysync_v1_wire_proto_msgTypes[29]
+ mi := &file_copysync_v1_wire_proto_msgTypes[30]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -2372,7 +2448,7 @@ func (x *TransferHeader) ProtoReflect() protoreflect.Message {
// Deprecated: Use TransferHeader.ProtoReflect.Descriptor instead.
func (*TransferHeader) Descriptor() ([]byte, []int) {
- return file_copysync_v1_wire_proto_rawDescGZIP(), []int{29}
+ return file_copysync_v1_wire_proto_rawDescGZIP(), []int{30}
}
func (x *TransferHeader) GetClipId() string {
@@ -2423,7 +2499,7 @@ type TransferDone struct {
func (x *TransferDone) Reset() {
*x = TransferDone{}
- mi := &file_copysync_v1_wire_proto_msgTypes[30]
+ mi := &file_copysync_v1_wire_proto_msgTypes[31]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -2435,7 +2511,7 @@ func (x *TransferDone) String() string {
func (*TransferDone) ProtoMessage() {}
func (x *TransferDone) ProtoReflect() protoreflect.Message {
- mi := &file_copysync_v1_wire_proto_msgTypes[30]
+ mi := &file_copysync_v1_wire_proto_msgTypes[31]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -2448,7 +2524,7 @@ func (x *TransferDone) ProtoReflect() protoreflect.Message {
// Deprecated: Use TransferDone.ProtoReflect.Descriptor instead.
func (*TransferDone) Descriptor() ([]byte, []int) {
- return file_copysync_v1_wire_proto_rawDescGZIP(), []int{30}
+ return file_copysync_v1_wire_proto_rawDescGZIP(), []int{31}
}
func (x *TransferDone) GetClipId() string {
@@ -2592,13 +2668,16 @@ const file_copysync_v1_wire_proto_rawDesc = "" +
"\apayload\";\n" +
"\vServerError\x12\x12\n" +
"\x04code\x18\x01 \x01(\tR\x04code\x12\x18\n" +
- "\amessage\x18\x02 \x01(\tR\amessage\"\x88\x02\n" +
+ "\amessage\x18\x02 \x01(\tR\amessage\"\x8c\x03\n" +
"\tLanPacket\x12-\n" +
"\x06signal\x18\x01 \x01(\v2\x13.copysync.v1.SignedH\x00R\x06signal\x12?\n" +
"\fpair_request\x18\x02 \x01(\v2\x1a.copysync.v1.LanPairSignedH\x00R\vpairRequest\x12A\n" +
"\rpair_response\x18\x03 \x01(\v2\x1a.copysync.v1.LanPairSignedH\x00R\fpairResponse\x12=\n" +
"\vpair_reject\x18\x04 \x01(\v2\x1a.copysync.v1.LanPairRejectH\x00R\n" +
- "pairRejectB\t\n" +
+ "pairReject\x12C\n" +
+ "\x0enearby_request\x18\x05 \x01(\v2\x1a.copysync.v1.LanPairSignedH\x00R\rnearbyRequest\x12=\n" +
+ "\vnearby_ping\x18\x06 \x01(\v2\x1a.copysync.v1.LanNearbyPingH\x00R\n" +
+ "nearbyPingB\t\n" +
"\apayload\"\x8a\x01\n" +
"\bLanHello\x12\x1c\n" +
"\taddresses\x18\x01 \x03(\tR\taddresses\x12!\n" +
@@ -2622,7 +2701,9 @@ const file_copysync_v1_wire_proto_rawDesc = "" +
"\rrequest_nonce\x18\t \x01(\fR\frequestNonce\"L\n" +
"\rLanPairReject\x12#\n" +
"\rrequest_nonce\x18\x01 \x01(\fR\frequestNonce\x12\x16\n" +
- "\x06reason\x18\x02 \x01(\tR\x06reason\"\xc1\x02\n" +
+ "\x06reason\x18\x02 \x01(\tR\x06reason\"+\n" +
+ "\rLanNearbyPing\x12\x1a\n" +
+ "\binstance\x18\x01 \x01(\tR\binstance\"\xc1\x02\n" +
"\vPeerMessage\x12.\n" +
"\x05offer\x18\x01 \x01(\v2\x16.copysync.v1.ClipOfferH\x00R\x05offer\x12.\n" +
"\x05fetch\x18\x02 \x01(\v2\x16.copysync.v1.PeerFetchH\x00R\x05fetch\x122\n" +
@@ -2685,7 +2766,7 @@ func file_copysync_v1_wire_proto_rawDescGZIP() []byte {
}
var file_copysync_v1_wire_proto_enumTypes = make([]protoimpl.EnumInfo, 2)
-var file_copysync_v1_wire_proto_msgTypes = make([]protoimpl.MessageInfo, 31)
+var file_copysync_v1_wire_proto_msgTypes = make([]protoimpl.MessageInfo, 32)
var file_copysync_v1_wire_proto_goTypes = []any{
(Compression)(0), // 0: copysync.v1.Compression
(Packaging)(0), // 1: copysync.v1.Packaging
@@ -2713,15 +2794,16 @@ var file_copysync_v1_wire_proto_goTypes = []any{
(*LanPairSigned)(nil), // 23: copysync.v1.LanPairSigned
(*LanPairInfo)(nil), // 24: copysync.v1.LanPairInfo
(*LanPairReject)(nil), // 25: copysync.v1.LanPairReject
- (*PeerMessage)(nil), // 26: copysync.v1.PeerMessage
- (*LinkInfo)(nil), // 27: copysync.v1.LinkInfo
- (*ClipOffer)(nil), // 28: copysync.v1.ClipOffer
- (*PeerFetch)(nil), // 29: copysync.v1.PeerFetch
- (*FetchReject)(nil), // 30: copysync.v1.FetchReject
- (*TransferHeader)(nil), // 31: copysync.v1.TransferHeader
- (*TransferDone)(nil), // 32: copysync.v1.TransferDone
- (ClipKind)(0), // 33: copysync.v1.ClipKind
- (*ClipItem)(nil), // 34: copysync.v1.ClipItem
+ (*LanNearbyPing)(nil), // 26: copysync.v1.LanNearbyPing
+ (*PeerMessage)(nil), // 27: copysync.v1.PeerMessage
+ (*LinkInfo)(nil), // 28: copysync.v1.LinkInfo
+ (*ClipOffer)(nil), // 29: copysync.v1.ClipOffer
+ (*PeerFetch)(nil), // 30: copysync.v1.PeerFetch
+ (*FetchReject)(nil), // 31: copysync.v1.FetchReject
+ (*TransferHeader)(nil), // 32: copysync.v1.TransferHeader
+ (*TransferDone)(nil), // 33: copysync.v1.TransferDone
+ (ClipKind)(0), // 34: copysync.v1.ClipKind
+ (*ClipItem)(nil), // 35: copysync.v1.ClipItem
}
var file_copysync_v1_wire_proto_depIdxs = []int32{
4, // 0: copysync.v1.SignalMessage.offer:type_name -> copysync.v1.SdpOffer
@@ -2747,21 +2829,23 @@ var file_copysync_v1_wire_proto_depIdxs = []int32{
23, // 20: copysync.v1.LanPacket.pair_request:type_name -> copysync.v1.LanPairSigned
23, // 21: copysync.v1.LanPacket.pair_response:type_name -> copysync.v1.LanPairSigned
25, // 22: copysync.v1.LanPacket.pair_reject:type_name -> copysync.v1.LanPairReject
- 28, // 23: copysync.v1.PeerMessage.offer:type_name -> copysync.v1.ClipOffer
- 29, // 24: copysync.v1.PeerMessage.fetch:type_name -> copysync.v1.PeerFetch
- 30, // 25: copysync.v1.PeerMessage.reject:type_name -> copysync.v1.FetchReject
- 31, // 26: copysync.v1.PeerMessage.header:type_name -> copysync.v1.TransferHeader
- 32, // 27: copysync.v1.PeerMessage.done:type_name -> copysync.v1.TransferDone
- 27, // 28: copysync.v1.PeerMessage.link:type_name -> copysync.v1.LinkInfo
- 33, // 29: copysync.v1.ClipOffer.kind:type_name -> copysync.v1.ClipKind
- 34, // 30: copysync.v1.ClipOffer.items:type_name -> copysync.v1.ClipItem
- 0, // 31: copysync.v1.TransferHeader.compression:type_name -> copysync.v1.Compression
- 1, // 32: copysync.v1.TransferHeader.packaging:type_name -> copysync.v1.Packaging
- 33, // [33:33] is the sub-list for method output_type
- 33, // [33:33] is the sub-list for method input_type
- 33, // [33:33] is the sub-list for extension type_name
- 33, // [33:33] is the sub-list for extension extendee
- 0, // [0:33] is the sub-list for field type_name
+ 23, // 23: copysync.v1.LanPacket.nearby_request:type_name -> copysync.v1.LanPairSigned
+ 26, // 24: copysync.v1.LanPacket.nearby_ping:type_name -> copysync.v1.LanNearbyPing
+ 29, // 25: copysync.v1.PeerMessage.offer:type_name -> copysync.v1.ClipOffer
+ 30, // 26: copysync.v1.PeerMessage.fetch:type_name -> copysync.v1.PeerFetch
+ 31, // 27: copysync.v1.PeerMessage.reject:type_name -> copysync.v1.FetchReject
+ 32, // 28: copysync.v1.PeerMessage.header:type_name -> copysync.v1.TransferHeader
+ 33, // 29: copysync.v1.PeerMessage.done:type_name -> copysync.v1.TransferDone
+ 28, // 30: copysync.v1.PeerMessage.link:type_name -> copysync.v1.LinkInfo
+ 34, // 31: copysync.v1.ClipOffer.kind:type_name -> copysync.v1.ClipKind
+ 35, // 32: copysync.v1.ClipOffer.items:type_name -> copysync.v1.ClipItem
+ 0, // 33: copysync.v1.TransferHeader.compression:type_name -> copysync.v1.Compression
+ 1, // 34: copysync.v1.TransferHeader.packaging:type_name -> copysync.v1.Packaging
+ 35, // [35:35] is the sub-list for method output_type
+ 35, // [35:35] is the sub-list for method input_type
+ 35, // [35:35] is the sub-list for extension type_name
+ 35, // [35:35] is the sub-list for extension extendee
+ 0, // [0:35] is the sub-list for field type_name
}
func init() { file_copysync_v1_wire_proto_init() }
@@ -2798,8 +2882,10 @@ func file_copysync_v1_wire_proto_init() {
(*LanPacket_PairRequest)(nil),
(*LanPacket_PairResponse)(nil),
(*LanPacket_PairReject)(nil),
+ (*LanPacket_NearbyRequest)(nil),
+ (*LanPacket_NearbyPing)(nil),
}
- file_copysync_v1_wire_proto_msgTypes[24].OneofWrappers = []any{
+ file_copysync_v1_wire_proto_msgTypes[25].OneofWrappers = []any{
(*PeerMessage_Offer)(nil),
(*PeerMessage_Fetch)(nil),
(*PeerMessage_Reject)(nil),
@@ -2813,7 +2899,7 @@ func file_copysync_v1_wire_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_copysync_v1_wire_proto_rawDesc), len(file_copysync_v1_wire_proto_rawDesc)),
NumEnums: 2,
- NumMessages: 31,
+ NumMessages: 32,
NumExtensions: 0,
NumServices: 0,
},
diff --git a/ui/lib/gen/copysync/v1/daemon.pb.dart b/ui/lib/gen/copysync/v1/daemon.pb.dart
index 0226f90..618c6e8 100644
--- a/ui/lib/gen/copysync/v1/daemon.pb.dart
+++ b/ui/lib/gen/copysync/v1/daemon.pb.dart
@@ -1525,6 +1525,209 @@ class ConfirmPairingRequest extends $pb.GeneratedMessage {
void clearAccept() => $_clearField(2);
}
+/// 附近一台打开了「搜索附近设备」窗口的设备。
+class NearbyDevice extends $pb.GeneratedMessage {
+ factory NearbyDevice({
+ $core.String? id,
+ $core.String? name,
+ $core.String? platform,
+ $core.bool? paired,
+ }) {
+ final result = NearbyDevice._();
+ if (id != null) result.id = id;
+ if (name != null) result.name = name;
+ if (platform != null) result.platform = platform;
+ if (paired != null) result.paired = paired;
+ return result;
+ }
+
+ NearbyDevice._();
+
+ factory NearbyDevice.fromBuffer($core.List<$core.int> data,
+ [$pb.ExtensionRegistry registry = $pb.ExtensionRegistry.EMPTY]) =>
+ NearbyDevice()..mergeFromBuffer(data, registry);
+ factory NearbyDevice.fromJson($core.String json,
+ [$pb.ExtensionRegistry registry = $pb.ExtensionRegistry.EMPTY]) =>
+ NearbyDevice()..mergeFromJson(json, registry);
+
+ static final $pb.BuilderInfo _i = $pb.BuilderInfo(
+ _omitMessageNames ? '' : 'NearbyDevice',
+ package: const $pb.PackageName(_omitMessageNames ? '' : 'copysync.v1'),
+ createEmptyInstance: NearbyDevice.$_createMessage)
+ ..aOS(1, _omitFieldNames ? '' : 'id')
+ ..aOS(2, _omitFieldNames ? '' : 'name')
+ ..aOS(3, _omitFieldNames ? '' : 'platform')
+ ..aOB(4, _omitFieldNames ? '' : 'paired')
+ ..hasRequiredFields = false;
+
+ @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.')
+ NearbyDevice clone() => deepCopy();
+ @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.')
+ NearbyDevice copyWith(void Function(NearbyDevice) updates) =>
+ super.copyWith((message) => updates(message as NearbyDevice))
+ as NearbyDevice;
+
+ @$core.override
+ $pb.BuilderInfo get info_ => _i;
+
+ @$core.pragma('dart2js:noInline')
+ @$core.Deprecated('Use NearbyDevice() / NearbyDevice.new instead')
+ static NearbyDevice create() => NearbyDevice._();
+ static $pb.GeneratedMessage $_createMessage() => NearbyDevice._();
+ @$core.override
+ NearbyDevice createEmptyInstance() => NearbyDevice._();
+ @$core.pragma('dart2js:noInline')
+ static NearbyDevice getDefault() =>
+ _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<NearbyDevice>(
+ NearbyDevice.$_createMessage);
+ static NearbyDevice? _defaultInstance;
+
+ @$pb.TagNumber(1)
+ $core.String get id => $_getSZ(0);
+ @$pb.TagNumber(1)
+ set id($core.String value) => $_setString(0, value);
+ @$pb.TagNumber(1)
+ $core.bool hasId() => $_has(0);
+ @$pb.TagNumber(1)
+ void clearId() => $_clearField(1);
+
+ @$pb.TagNumber(2)
+ $core.String get name => $_getSZ(1);
+ @$pb.TagNumber(2)
+ set name($core.String value) => $_setString(1, value);
+ @$pb.TagNumber(2)
+ $core.bool hasName() => $_has(1);
+ @$pb.TagNumber(2)
+ void clearName() => $_clearField(2);
+
+ @$pb.TagNumber(3)
+ $core.String get platform => $_getSZ(2);
+ @$pb.TagNumber(3)
+ set platform($core.String value) => $_setString(2, value);
+ @$pb.TagNumber(3)
+ $core.bool hasPlatform() => $_has(2);
+ @$pb.TagNumber(3)
+ void clearPlatform() => $_clearField(3);
+
+ @$pb.TagNumber(4)
+ $core.bool get paired => $_getBF(3);
+ @$pb.TagNumber(4)
+ set paired($core.bool value) => $_setBool(3, value);
+ @$pb.TagNumber(4)
+ $core.bool hasPaired() => $_has(3);
+ @$pb.TagNumber(4)
+ void clearPaired() => $_clearField(4);
+}
+
+class NearbyDevices extends $pb.GeneratedMessage {
+ factory NearbyDevices({
+ $core.Iterable<NearbyDevice>? devices,
+ }) {
+ final result = NearbyDevices._();
+ if (devices != null) result.devices.addAll(devices);
+ return result;
+ }
+
+ NearbyDevices._();
+
+ factory NearbyDevices.fromBuffer($core.List<$core.int> data,
+ [$pb.ExtensionRegistry registry = $pb.ExtensionRegistry.EMPTY]) =>
+ NearbyDevices()..mergeFromBuffer(data, registry);
+ factory NearbyDevices.fromJson($core.String json,
+ [$pb.ExtensionRegistry registry = $pb.ExtensionRegistry.EMPTY]) =>
+ NearbyDevices()..mergeFromJson(json, registry);
+
+ static final $pb.BuilderInfo _i = $pb.BuilderInfo(
+ _omitMessageNames ? '' : 'NearbyDevices',
+ package: const $pb.PackageName(_omitMessageNames ? '' : 'copysync.v1'),
+ createEmptyInstance: NearbyDevices.$_createMessage)
+ ..pPM<NearbyDevice>(1, _omitFieldNames ? '' : 'devices',
+ subBuilder: NearbyDevice.$_createMessage)
+ ..hasRequiredFields = false;
+
+ @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.')
+ NearbyDevices clone() => deepCopy();
+ @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.')
+ NearbyDevices copyWith(void Function(NearbyDevices) updates) =>
+ super.copyWith((message) => updates(message as NearbyDevices))
+ as NearbyDevices;
+
+ @$core.override
+ $pb.BuilderInfo get info_ => _i;
+
+ @$core.pragma('dart2js:noInline')
+ @$core.Deprecated('Use NearbyDevices() / NearbyDevices.new instead')
+ static NearbyDevices create() => NearbyDevices._();
+ static $pb.GeneratedMessage $_createMessage() => NearbyDevices._();
+ @$core.override
+ NearbyDevices createEmptyInstance() => NearbyDevices._();
+ @$core.pragma('dart2js:noInline')
+ static NearbyDevices getDefault() =>
+ _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<NearbyDevices>(
+ NearbyDevices.$_createMessage);
+ static NearbyDevices? _defaultInstance;
+
+ @$pb.TagNumber(1)
+ $pb.PbList<NearbyDevice> get devices => $_getList(0);
+}
+
+class PairNearbyRequest extends $pb.GeneratedMessage {
+ factory PairNearbyRequest({
+ $core.String? id,
+ }) {
+ final result = PairNearbyRequest._();
+ if (id != null) result.id = id;
+ return result;
+ }
+
+ PairNearbyRequest._();
+
+ factory PairNearbyRequest.fromBuffer($core.List<$core.int> data,
+ [$pb.ExtensionRegistry registry = $pb.ExtensionRegistry.EMPTY]) =>
+ PairNearbyRequest()..mergeFromBuffer(data, registry);
+ factory PairNearbyRequest.fromJson($core.String json,
+ [$pb.ExtensionRegistry registry = $pb.ExtensionRegistry.EMPTY]) =>
+ PairNearbyRequest()..mergeFromJson(json, registry);
+
+ static final $pb.BuilderInfo _i = $pb.BuilderInfo(
+ _omitMessageNames ? '' : 'PairNearbyRequest',
+ package: const $pb.PackageName(_omitMessageNames ? '' : 'copysync.v1'),
+ createEmptyInstance: PairNearbyRequest.$_createMessage)
+ ..aOS(1, _omitFieldNames ? '' : 'id')
+ ..hasRequiredFields = false;
+
+ @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.')
+ PairNearbyRequest clone() => deepCopy();
+ @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.')
+ PairNearbyRequest copyWith(void Function(PairNearbyRequest) updates) =>
+ super.copyWith((message) => updates(message as PairNearbyRequest))
+ as PairNearbyRequest;
+
+ @$core.override
+ $pb.BuilderInfo get info_ => _i;
+
+ @$core.pragma('dart2js:noInline')
+ @$core.Deprecated('Use PairNearbyRequest() / PairNearbyRequest.new instead')
+ static PairNearbyRequest create() => PairNearbyRequest._();
+ static $pb.GeneratedMessage $_createMessage() => PairNearbyRequest._();
+ @$core.override
+ PairNearbyRequest createEmptyInstance() => PairNearbyRequest._();
+ @$core.pragma('dart2js:noInline')
+ static PairNearbyRequest getDefault() =>
+ _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<PairNearbyRequest>(
+ PairNearbyRequest.$_createMessage);
+ static PairNearbyRequest? _defaultInstance;
+
+ @$pb.TagNumber(1)
+ $core.String get id => $_getSZ(0);
+ @$pb.TagNumber(1)
+ set id($core.String value) => $_setString(0, value);
+ @$pb.TagNumber(1)
+ $core.bool hasId() => $_has(0);
+ @$pb.TagNumber(1)
+ void clearId() => $_clearField(1);
+}
+
class UnpairRequest extends $pb.GeneratedMessage {
factory UnpairRequest({
$core.String? deviceId,
diff --git a/ui/lib/gen/copysync/v1/daemon.pbgrpc.dart b/ui/lib/gen/copysync/v1/daemon.pbgrpc.dart
index 03d1533..231c914 100644
--- a/ui/lib/gen/copysync/v1/daemon.pbgrpc.dart
+++ b/ui/lib/gen/copysync/v1/daemon.pbgrpc.dart
@@ -124,6 +124,25 @@ class DaemonServiceClient extends $grpc.Client {
return $createUnaryCall(_$setDeviceAddress, request, options: options);
}
+ /// 「搜索附近设备」窗口打开期间保持这个调用,窗口关掉时取消。期间本机在局域网里公开设备名,
+ /// 并在附近同样打开了这个窗口的设备有变化时推送最新的列表
+ $grpc.ResponseStream<$0.NearbyDevices> watchNearby(
+ $0.Empty request, {
+ $grpc.CallOptions? options,
+ }) {
+ return $createStreamingCall(
+ _$watchNearby, $async.Stream.fromIterable([request]),
+ options: options);
+ }
+
+ /// 向附近的一台设备发起配对。之后与 RedeemPairingCode 一样,双方核对指纹后各自 ConfirmPairing
+ $grpc.ResponseFuture<$0.RedeemPairingCodeResponse> pairNearby(
+ $0.PairNearbyRequest request, {
+ $grpc.CallOptions? options,
+ }) {
+ return $createUnaryCall(_$pairNearby, request, options: options);
+ }
+
$grpc.ResponseFuture<$0.Config> getConfig(
$0.Empty request, {
$grpc.CallOptions? options,
@@ -231,6 +250,15 @@ class DaemonServiceClient extends $grpc.Client {
'/copysync.v1.DaemonService/SetDeviceAddress',
($0.SetDeviceAddressRequest value) => value.writeToBuffer(),
$0.Empty.fromBuffer);
+ static final _$watchNearby = $grpc.ClientMethod<$0.Empty, $0.NearbyDevices>(
+ '/copysync.v1.DaemonService/WatchNearby',
+ ($0.Empty value) => value.writeToBuffer(),
+ $0.NearbyDevices.fromBuffer);
+ static final _$pairNearby =
+ $grpc.ClientMethod<$0.PairNearbyRequest, $0.RedeemPairingCodeResponse>(
+ '/copysync.v1.DaemonService/PairNearby',
+ ($0.PairNearbyRequest value) => value.writeToBuffer(),
+ $0.RedeemPairingCodeResponse.fromBuffer);
static final _$getConfig = $grpc.ClientMethod<$0.Empty, $0.Config>(
'/copysync.v1.DaemonService/GetConfig',
($0.Empty value) => value.writeToBuffer(),
@@ -358,6 +386,22 @@ abstract class DaemonServiceBase extends $grpc.Service {
($core.List<$core.int> value) =>
$0.SetDeviceAddressRequest.fromBuffer(value),
($0.Empty value) => value.writeToBuffer()));
+ $addMethod($grpc.ServiceMethod<$0.Empty, $0.NearbyDevices>(
+ 'WatchNearby',
+ watchNearby_Pre,
+ false,
+ true,
+ ($core.List<$core.int> value) => $0.Empty.fromBuffer(value),
+ ($0.NearbyDevices value) => value.writeToBuffer()));
+ $addMethod(
+ $grpc.ServiceMethod<$0.PairNearbyRequest, $0.RedeemPairingCodeResponse>(
+ 'PairNearby',
+ pairNearby_Pre,
+ false,
+ false,
+ ($core.List<$core.int> value) =>
+ $0.PairNearbyRequest.fromBuffer(value),
+ ($0.RedeemPairingCodeResponse value) => value.writeToBuffer()));
$addMethod($grpc.ServiceMethod<$0.Empty, $0.Config>(
'GetConfig',
getConfig_Pre,
@@ -500,6 +544,23 @@ abstract class DaemonServiceBase extends $grpc.Service {
$async.Future<$0.Empty> setDeviceAddress(
$grpc.ServiceCall call, $0.SetDeviceAddressRequest request);
+ $async.Stream<$0.NearbyDevices> watchNearby_Pre(
+ $grpc.ServiceCall $call, $async.Future<$0.Empty> $request) async* {
+ yield* watchNearby($call, await $request);
+ }
+
+ $async.Stream<$0.NearbyDevices> watchNearby(
+ $grpc.ServiceCall call, $0.Empty request);
+
+ $async.Future<$0.RedeemPairingCodeResponse> pairNearby_Pre(
+ $grpc.ServiceCall $call,
+ $async.Future<$0.PairNearbyRequest> $request) async {
+ return pairNearby($call, await $request);
+ }
+
+ $async.Future<$0.RedeemPairingCodeResponse> pairNearby(
+ $grpc.ServiceCall call, $0.PairNearbyRequest request);
+
$async.Future<$0.Config> getConfig_Pre(
$grpc.ServiceCall $call, $async.Future<$0.Empty> $request) async {
return getConfig($call, await $request);
diff --git a/ui/lib/gen/copysync/v1/daemon.pbjson.dart b/ui/lib/gen/copysync/v1/daemon.pbjson.dart
index 19f18c6..8be821f 100644
--- a/ui/lib/gen/copysync/v1/daemon.pbjson.dart
+++ b/ui/lib/gen/copysync/v1/daemon.pbjson.dart
@@ -501,6 +501,54 @@ final $typed_data.Uint8List confirmPairingRequestDescriptor = $convert.base64Dec
'ChVDb25maXJtUGFpcmluZ1JlcXVlc3QSJwoPcGFpcmluZ19zZXNzaW9uGAEgASgJUg5wYWlyaW'
'5nU2Vzc2lvbhIWCgZhY2NlcHQYAiABKAhSBmFjY2VwdA==');
+@$core.Deprecated('Use nearbyDeviceDescriptor instead')
+const NearbyDevice$json = {
+ '1': 'NearbyDevice',
+ '2': [
+ {'1': 'id', '3': 1, '4': 1, '5': 9, '10': 'id'},
+ {'1': 'name', '3': 2, '4': 1, '5': 9, '10': 'name'},
+ {'1': 'platform', '3': 3, '4': 1, '5': 9, '10': 'platform'},
+ {'1': 'paired', '3': 4, '4': 1, '5': 8, '10': 'paired'},
+ ],
+};
+
+/// Descriptor for `NearbyDevice`. Decode as a `google.protobuf.DescriptorProto`.
+final $typed_data.Uint8List nearbyDeviceDescriptor = $convert.base64Decode(
+ 'CgxOZWFyYnlEZXZpY2USDgoCaWQYASABKAlSAmlkEhIKBG5hbWUYAiABKAlSBG5hbWUSGgoIcG'
+ 'xhdGZvcm0YAyABKAlSCHBsYXRmb3JtEhYKBnBhaXJlZBgEIAEoCFIGcGFpcmVk');
+
+@$core.Deprecated('Use nearbyDevicesDescriptor instead')
+const NearbyDevices$json = {
+ '1': 'NearbyDevices',
+ '2': [
+ {
+ '1': 'devices',
+ '3': 1,
+ '4': 3,
+ '5': 11,
+ '6': '.copysync.v1.NearbyDevice',
+ '10': 'devices'
+ },
+ ],
+};
+
+/// Descriptor for `NearbyDevices`. Decode as a `google.protobuf.DescriptorProto`.
+final $typed_data.Uint8List nearbyDevicesDescriptor = $convert.base64Decode(
+ 'Cg1OZWFyYnlEZXZpY2VzEjMKB2RldmljZXMYASADKAsyGS5jb3B5c3luYy52MS5OZWFyYnlEZX'
+ 'ZpY2VSB2RldmljZXM=');
+
+@$core.Deprecated('Use pairNearbyRequestDescriptor instead')
+const PairNearbyRequest$json = {
+ '1': 'PairNearbyRequest',
+ '2': [
+ {'1': 'id', '3': 1, '4': 1, '5': 9, '10': 'id'},
+ ],
+};
+
+/// Descriptor for `PairNearbyRequest`. Decode as a `google.protobuf.DescriptorProto`.
+final $typed_data.Uint8List pairNearbyRequestDescriptor =
+ $convert.base64Decode('ChFQYWlyTmVhcmJ5UmVxdWVzdBIOCgJpZBgBIAEoCVICaWQ=');
+
@$core.Deprecated('Use unpairRequestDescriptor instead')
const UnpairRequest$json = {
'1': 'UnpairRequest',
diff --git a/ui/lib/gen/copysync/v1/wire.pb.dart b/ui/lib/gen/copysync/v1/wire.pb.dart
index 6a0667f..dc409b7 100644
--- a/ui/lib/gen/copysync/v1/wire.pb.dart
+++ b/ui/lib/gen/copysync/v1/wire.pb.dart
@@ -1819,7 +1819,15 @@ class ServerError extends $pb.GeneratedMessage {
void clearMessage() => $_clearField(2);
}
-enum LanPacket_Payload { signal, pairRequest, pairResponse, pairReject, notSet }
+enum LanPacket_Payload {
+ signal,
+ pairRequest,
+ pairResponse,
+ pairReject,
+ nearbyRequest,
+ nearbyPing,
+ notSet
+}
class LanPacket extends $pb.GeneratedMessage {
factory LanPacket({
@@ -1827,12 +1835,16 @@ class LanPacket extends $pb.GeneratedMessage {
LanPairSigned? pairRequest,
LanPairSigned? pairResponse,
LanPairReject? pairReject,
+ LanPairSigned? nearbyRequest,
+ LanNearbyPing? nearbyPing,
}) {
final result = LanPacket._();
if (signal != null) result.signal = signal;
if (pairRequest != null) result.pairRequest = pairRequest;
if (pairResponse != null) result.pairResponse = pairResponse;
if (pairReject != null) result.pairReject = pairReject;
+ if (nearbyRequest != null) result.nearbyRequest = nearbyRequest;
+ if (nearbyPing != null) result.nearbyPing = nearbyPing;
return result;
}
@@ -1851,13 +1863,15 @@ class LanPacket extends $pb.GeneratedMessage {
2: LanPacket_Payload.pairRequest,
3: LanPacket_Payload.pairResponse,
4: LanPacket_Payload.pairReject,
+ 5: LanPacket_Payload.nearbyRequest,
+ 6: LanPacket_Payload.nearbyPing,
0: LanPacket_Payload.notSet
};
static final $pb.BuilderInfo _i = $pb.BuilderInfo(
_omitMessageNames ? '' : 'LanPacket',
package: const $pb.PackageName(_omitMessageNames ? '' : 'copysync.v1'),
createEmptyInstance: LanPacket.$_createMessage)
- ..oo(0, [1, 2, 3, 4])
+ ..oo(0, [1, 2, 3, 4, 5, 6])
..aOM<Signed>(1, _omitFieldNames ? '' : 'signal',
subBuilder: Signed.$_createMessage)
..aOM<LanPairSigned>(2, _omitFieldNames ? '' : 'pairRequest',
@@ -1866,6 +1880,10 @@ class LanPacket extends $pb.GeneratedMessage {
subBuilder: LanPairSigned.$_createMessage)
..aOM<LanPairReject>(4, _omitFieldNames ? '' : 'pairReject',
subBuilder: LanPairReject.$_createMessage)
+ ..aOM<LanPairSigned>(5, _omitFieldNames ? '' : 'nearbyRequest',
+ subBuilder: LanPairSigned.$_createMessage)
+ ..aOM<LanNearbyPing>(6, _omitFieldNames ? '' : 'nearbyPing',
+ subBuilder: LanNearbyPing.$_createMessage)
..hasRequiredFields = false;
@$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.')
@@ -1892,11 +1910,15 @@ class LanPacket extends $pb.GeneratedMessage {
@$pb.TagNumber(2)
@$pb.TagNumber(3)
@$pb.TagNumber(4)
+ @$pb.TagNumber(5)
+ @$pb.TagNumber(6)
LanPacket_Payload whichPayload() => _LanPacket_PayloadByTag[$_whichOneof(0)]!;
@$pb.TagNumber(1)
@$pb.TagNumber(2)
@$pb.TagNumber(3)
@$pb.TagNumber(4)
+ @$pb.TagNumber(5)
+ @$pb.TagNumber(6)
void clearPayload() => $_clearField($_whichOneof(0));
@$pb.TagNumber(1)
@@ -1942,6 +1964,28 @@ class LanPacket extends $pb.GeneratedMessage {
void clearPairReject() => $_clearField(4);
@$pb.TagNumber(4)
LanPairReject ensurePairReject() => $_ensure(3);
+
+ @$pb.TagNumber(5)
+ LanPairSigned get nearbyRequest => $_getN(4);
+ @$pb.TagNumber(5)
+ set nearbyRequest(LanPairSigned value) => $_setField(5, value);
+ @$pb.TagNumber(5)
+ $core.bool hasNearbyRequest() => $_has(4);
+ @$pb.TagNumber(5)
+ void clearNearbyRequest() => $_clearField(5);
+ @$pb.TagNumber(5)
+ LanPairSigned ensureNearbyRequest() => $_ensure(4);
+
+ @$pb.TagNumber(6)
+ LanNearbyPing get nearbyPing => $_getN(5);
+ @$pb.TagNumber(6)
+ set nearbyPing(LanNearbyPing value) => $_setField(6, value);
+ @$pb.TagNumber(6)
+ $core.bool hasNearbyPing() => $_has(5);
+ @$pb.TagNumber(6)
+ void clearNearbyPing() => $_clearField(6);
+ @$pb.TagNumber(6)
+ LanNearbyPing ensureNearbyPing() => $_ensure(5);
}
/// 已配对设备之间的上线通知。还没连通时定期发,连通后低频保活。
@@ -2327,6 +2371,63 @@ class LanPairReject extends $pb.GeneratedMessage {
void clearReason() => $_clearField(2);
}
+class LanNearbyPing extends $pb.GeneratedMessage {
+ factory LanNearbyPing({
+ $core.String? instance,
+ }) {
+ final result = LanNearbyPing._();
+ if (instance != null) result.instance = instance;
+ return result;
+ }
+
+ LanNearbyPing._();
+
+ factory LanNearbyPing.fromBuffer($core.List<$core.int> data,
+ [$pb.ExtensionRegistry registry = $pb.ExtensionRegistry.EMPTY]) =>
+ LanNearbyPing()..mergeFromBuffer(data, registry);
+ factory LanNearbyPing.fromJson($core.String json,
+ [$pb.ExtensionRegistry registry = $pb.ExtensionRegistry.EMPTY]) =>
+ LanNearbyPing()..mergeFromJson(json, registry);
+
+ static final $pb.BuilderInfo _i = $pb.BuilderInfo(
+ _omitMessageNames ? '' : 'LanNearbyPing',
+ package: const $pb.PackageName(_omitMessageNames ? '' : 'copysync.v1'),
+ createEmptyInstance: LanNearbyPing.$_createMessage)
+ ..aOS(1, _omitFieldNames ? '' : 'instance')
+ ..hasRequiredFields = false;
+
+ @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.')
+ LanNearbyPing clone() => deepCopy();
+ @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.')
+ LanNearbyPing copyWith(void Function(LanNearbyPing) updates) =>
+ super.copyWith((message) => updates(message as LanNearbyPing))
+ as LanNearbyPing;
+
+ @$core.override
+ $pb.BuilderInfo get info_ => _i;
+
+ @$core.pragma('dart2js:noInline')
+ @$core.Deprecated('Use LanNearbyPing() / LanNearbyPing.new instead')
+ static LanNearbyPing create() => LanNearbyPing._();
+ static $pb.GeneratedMessage $_createMessage() => LanNearbyPing._();
+ @$core.override
+ LanNearbyPing createEmptyInstance() => LanNearbyPing._();
+ @$core.pragma('dart2js:noInline')
+ static LanNearbyPing getDefault() =>
+ _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<LanNearbyPing>(
+ LanNearbyPing.$_createMessage);
+ static LanNearbyPing? _defaultInstance;
+
+ @$pb.TagNumber(1)
+ $core.String get instance => $_getSZ(0);
+ @$pb.TagNumber(1)
+ set instance($core.String value) => $_setString(0, value);
+ @$pb.TagNumber(1)
+ $core.bool hasInstance() => $_has(0);
+ @$pb.TagNumber(1)
+ void clearInstance() => $_clearField(1);
+}
+
enum PeerMessage_Payload { offer, fetch, reject, header, done, link, notSet }
/// 控制通道消息
diff --git a/ui/lib/gen/copysync/v1/wire.pbjson.dart b/ui/lib/gen/copysync/v1/wire.pbjson.dart
index eb97ca8..4d838a3 100644
--- a/ui/lib/gen/copysync/v1/wire.pbjson.dart
+++ b/ui/lib/gen/copysync/v1/wire.pbjson.dart
@@ -563,6 +563,24 @@ const LanPacket$json = {
'9': 0,
'10': 'pairReject'
},
+ {
+ '1': 'nearby_request',
+ '3': 5,
+ '4': 1,
+ '5': 11,
+ '6': '.copysync.v1.LanPairSigned',
+ '9': 0,
+ '10': 'nearbyRequest'
+ },
+ {
+ '1': 'nearby_ping',
+ '3': 6,
+ '4': 1,
+ '5': 11,
+ '6': '.copysync.v1.LanNearbyPing',
+ '9': 0,
+ '10': 'nearbyPing'
+ },
],
'8': [
{'1': 'payload'},
@@ -575,7 +593,10 @@ final $typed_data.Uint8List lanPacketDescriptor = $convert.base64Decode(
'5hbBI/CgxwYWlyX3JlcXVlc3QYAiABKAsyGi5jb3B5c3luYy52MS5MYW5QYWlyU2lnbmVkSABS'
'C3BhaXJSZXF1ZXN0EkEKDXBhaXJfcmVzcG9uc2UYAyABKAsyGi5jb3B5c3luYy52MS5MYW5QYW'
'lyU2lnbmVkSABSDHBhaXJSZXNwb25zZRI9CgtwYWlyX3JlamVjdBgEIAEoCzIaLmNvcHlzeW5j'
- 'LnYxLkxhblBhaXJSZWplY3RIAFIKcGFpclJlamVjdEIJCgdwYXlsb2Fk');
+ 'LnYxLkxhblBhaXJSZWplY3RIAFIKcGFpclJlamVjdBJDCg5uZWFyYnlfcmVxdWVzdBgFIAEoCz'
+ 'IaLmNvcHlzeW5jLnYxLkxhblBhaXJTaWduZWRIAFINbmVhcmJ5UmVxdWVzdBI9CgtuZWFyYnlf'
+ 'cGluZxgGIAEoCzIaLmNvcHlzeW5jLnYxLkxhbk5lYXJieVBpbmdIAFIKbmVhcmJ5UGluZ0IJCg'
+ 'dwYXlsb2Fk');
@$core.Deprecated('Use lanHelloDescriptor instead')
const LanHello$json = {
@@ -647,6 +668,18 @@ final $typed_data.Uint8List lanPairRejectDescriptor = $convert.base64Decode(
'Cg1MYW5QYWlyUmVqZWN0EiMKDXJlcXVlc3Rfbm9uY2UYASABKAxSDHJlcXVlc3ROb25jZRIWCg'
'ZyZWFzb24YAiABKAlSBnJlYXNvbg==');
+@$core.Deprecated('Use lanNearbyPingDescriptor instead')
+const LanNearbyPing$json = {
+ '1': 'LanNearbyPing',
+ '2': [
+ {'1': 'instance', '3': 1, '4': 1, '5': 9, '10': 'instance'},
+ ],
+};
+
+/// Descriptor for `LanNearbyPing`. Decode as a `google.protobuf.DescriptorProto`.
+final $typed_data.Uint8List lanNearbyPingDescriptor = $convert.base64Decode(
+ 'Cg1MYW5OZWFyYnlQaW5nEhoKCGluc3RhbmNlGAEgASgJUghpbnN0YW5jZQ==');
+
@$core.Deprecated('Use peerMessageDescriptor instead')
const PeerMessage$json = {
'1': 'PeerMessage',