libp2p-mesh 2026.5.22 → 2026.5.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/inbound.js +23 -0
- package/package.json +1 -1
- package/src/inbound.ts +23 -0
package/dist/src/inbound.js
CHANGED
|
@@ -58,6 +58,29 @@ export async function handleP2PInbound(msg, deps) {
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
else if (msg.type === "direct") {
|
|
61
|
+
// onPeerConnect 通过 sendToPeer 发送 identity 时会被包装成
|
|
62
|
+
// type=direct 的外壳,真正的 identity 消息藏在 payload 里。
|
|
63
|
+
// 先检测并处理这种情况,确保双向身份交换能完成。
|
|
64
|
+
try {
|
|
65
|
+
const raw = JSON.parse(msg.payload);
|
|
66
|
+
if (raw && raw.type === "identity") {
|
|
67
|
+
await handleIdentityMessage(msg, {
|
|
68
|
+
peerIdentityMap: deps.peerIdentityMap,
|
|
69
|
+
localPeerId: deps.peerIdentityMap.getLocalIdentity()?.sessionKey ?? "",
|
|
70
|
+
localAgentId: "",
|
|
71
|
+
localChannel: "",
|
|
72
|
+
localAccountId: "",
|
|
73
|
+
localInstanceId: deps.peerIdentityMap.getLocalIdentity()?.instanceId,
|
|
74
|
+
send: async () => { }, // no-op; 双方都通过 onPeerConnect 主动发送身份
|
|
75
|
+
logger,
|
|
76
|
+
});
|
|
77
|
+
// identity 处理完毕,不再走 direct 消息路由
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
// payload 不是 JSON,正常走 direct 消息逻辑
|
|
83
|
+
}
|
|
61
84
|
if (!msg.to) {
|
|
62
85
|
logger?.warn?.("[libp2p-mesh] Direct message missing 'to' field");
|
|
63
86
|
}
|
package/package.json
CHANGED
package/src/inbound.ts
CHANGED
|
@@ -75,6 +75,29 @@ export async function handleP2PInbound(msg: P2PMessage, deps?: InboundHandlerDep
|
|
|
75
75
|
logger?.error?.(`[libp2p-mesh] Identity message handler error: ${String(err)}`);
|
|
76
76
|
}
|
|
77
77
|
} else if (msg.type === "direct") {
|
|
78
|
+
// onPeerConnect 通过 sendToPeer 发送 identity 时会被包装成
|
|
79
|
+
// type=direct 的外壳,真正的 identity 消息藏在 payload 里。
|
|
80
|
+
// 先检测并处理这种情况,确保双向身份交换能完成。
|
|
81
|
+
try {
|
|
82
|
+
const raw = JSON.parse(msg.payload);
|
|
83
|
+
if (raw && raw.type === "identity") {
|
|
84
|
+
await handleIdentityMessage(msg, {
|
|
85
|
+
peerIdentityMap: deps.peerIdentityMap,
|
|
86
|
+
localPeerId: deps.peerIdentityMap.getLocalIdentity()?.sessionKey ?? "",
|
|
87
|
+
localAgentId: "",
|
|
88
|
+
localChannel: "",
|
|
89
|
+
localAccountId: "",
|
|
90
|
+
localInstanceId: deps.peerIdentityMap.getLocalIdentity()?.instanceId,
|
|
91
|
+
send: async () => {}, // no-op; 双方都通过 onPeerConnect 主动发送身份
|
|
92
|
+
logger,
|
|
93
|
+
});
|
|
94
|
+
// identity 处理完毕,不再走 direct 消息路由
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
} catch {
|
|
98
|
+
// payload 不是 JSON,正常走 direct 消息逻辑
|
|
99
|
+
}
|
|
100
|
+
|
|
78
101
|
if (!msg.to) {
|
|
79
102
|
logger?.warn?.("[libp2p-mesh] Direct message missing 'to' field");
|
|
80
103
|
} else {
|