feat: 接入端到端 demo 与签名变体
- Flutter 桌面端通过 dart:ffi 调用 Rust Core cdylib - 实现 ECDH P-256 密钥协商、HKDF 子密钥派生、AES-256-GCM 控制帧 - Android 被控端用派生密钥做控制帧加密与媒体包 MAC - 新增 libopus JNI 骨架,默认回退 MediaCodec - 新增 aosp/zhanxun/neutral 签名变体与系统 sharedUserId - 本机独立信令服务与设置页开关 - 新增 .gitignore 排除所有编译产物与打包目录
This commit is contained in:
commit
31b9a52eb4
154 files changed
+13287
No files matched your search
@@ -0,0 +1,75 @@
|
||||
package registry
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func sampleDevice(id string) Device {
|
||||
return Device{
|
||||
DeviceID: id,
|
||||
Name: "Pixel",
|
||||
IP: "192.168.1.10",
|
||||
MediaPort: 41000,
|
||||
ControlPort: 41001,
|
||||
FP: "sha256:ab12",
|
||||
Cap: []string{"h264", "file"},
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegisterAndList(t *testing.T) {
|
||||
reg := New(45 * time.Second)
|
||||
if _, err := reg.Register(sampleDevice("a")); err != nil {
|
||||
t.Fatalf("register: %v", err)
|
||||
}
|
||||
if _, err := reg.Register(sampleDevice("b")); err != nil {
|
||||
t.Fatalf("register: %v", err)
|
||||
}
|
||||
devices := reg.List()
|
||||
if len(devices) != 2 {
|
||||
t.Fatalf("期望 2 台设备,实际 %d", len(devices))
|
||||
}
|
||||
if devices[0].DeviceID != "a" {
|
||||
t.Fatalf("列表未按 deviceId 排序: %+v", devices)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHeartbeatAndExpiry(t *testing.T) {
|
||||
now := time.Now()
|
||||
reg := New(10 * time.Second)
|
||||
reg.now = func() time.Time { return now }
|
||||
|
||||
events, unsubscribe := reg.Subscribe()
|
||||
defer unsubscribe()
|
||||
if _, err := reg.Register(sampleDevice("a")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if event := <-events; event.Event != "online" {
|
||||
t.Fatalf("期望 online,实际 %s", event.Event)
|
||||
}
|
||||
|
||||
now = now.Add(8 * time.Second)
|
||||
if !reg.Heartbeat("a") {
|
||||
t.Fatal("心跳应成功")
|
||||
}
|
||||
if event := <-events; event.Event != "heartbeat" {
|
||||
t.Fatalf("期望 heartbeat,实际 %s", event.Event)
|
||||
}
|
||||
|
||||
now = now.Add(11 * time.Second)
|
||||
if devices := reg.List(); len(devices) != 0 {
|
||||
t.Fatalf("过期设备应被摘除,实际 %+v", devices)
|
||||
}
|
||||
if event := <-events; event.Event != "offline" {
|
||||
t.Fatalf("期望 offline,实际 %s", event.Event)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRejectInvalidDevice(t *testing.T) {
|
||||
reg := New(time.Minute)
|
||||
device := sampleDevice("a")
|
||||
device.MediaPort = 0
|
||||
if _, err := reg.Register(device); err == nil {
|
||||
t.Fatal("非法端口应被拒绝")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user