libp2p-mesh 2026.5.28 → 2026.5.29
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/plugin.js +13 -2
- package/package.json +1 -1
- package/src/plugin.ts +14 -2
package/dist/src/plugin.js
CHANGED
|
@@ -22,9 +22,13 @@ export function registerLibp2pMesh(api) {
|
|
|
22
22
|
api.registerService({
|
|
23
23
|
id: "libp2p-mesh",
|
|
24
24
|
start: async () => {
|
|
25
|
-
|
|
26
|
-
//
|
|
25
|
+
// Load persisted peer identities FIRST so dedup checks work when
|
|
26
|
+
// peers connect during mesh.start() (mDNS can fire peer:connect
|
|
27
|
+
// before this function's sequential code reaches onPeerConnect).
|
|
27
28
|
await peerIdentityMap.load();
|
|
29
|
+
await mesh.start();
|
|
30
|
+
const instanceIdentity = mesh.getInstanceIdentity();
|
|
31
|
+
const localInstanceId = instanceIdentity?.id;
|
|
28
32
|
// Register local identity so remote peers can route messages back to us
|
|
29
33
|
const config = api.pluginConfig;
|
|
30
34
|
const relayChannel = config?.relayChannel;
|
|
@@ -42,9 +46,13 @@ export function registerLibp2pMesh(api) {
|
|
|
42
46
|
channel: relayChannel,
|
|
43
47
|
accountId: relayAccountId,
|
|
44
48
|
sessionKey,
|
|
49
|
+
instanceId: localInstanceId,
|
|
45
50
|
});
|
|
46
51
|
api.logger.info?.(`[libp2p-mesh] Local identity registered: agent=${api.name}, channel=${relayChannel}, account=${relayAccountId}`);
|
|
47
52
|
// Announce identity to all currently-connected peers
|
|
53
|
+
// setLocalIdentity is called BEFORE this block, and localInstanceId
|
|
54
|
+
// is available from mesh.start(), so the identity message includes
|
|
55
|
+
// the instanceId.
|
|
48
56
|
const identityMsg = JSON.stringify({
|
|
49
57
|
id: crypto.randomUUID(),
|
|
50
58
|
type: "identity",
|
|
@@ -53,6 +61,7 @@ export function registerLibp2pMesh(api) {
|
|
|
53
61
|
agentId: api.name,
|
|
54
62
|
channel: relayChannel,
|
|
55
63
|
accountId: relayAccountId,
|
|
64
|
+
instanceId: localInstanceId,
|
|
56
65
|
}),
|
|
57
66
|
timestamp: Date.now(),
|
|
58
67
|
});
|
|
@@ -88,6 +97,7 @@ export function registerLibp2pMesh(api) {
|
|
|
88
97
|
agentId: api.name,
|
|
89
98
|
channel: relayChannel,
|
|
90
99
|
accountId: relayAccountId,
|
|
100
|
+
instanceId: localInstanceId,
|
|
91
101
|
}),
|
|
92
102
|
timestamp: Date.now(),
|
|
93
103
|
});
|
|
@@ -103,6 +113,7 @@ export function registerLibp2pMesh(api) {
|
|
|
103
113
|
agentId: api.name,
|
|
104
114
|
channel: relayChannel,
|
|
105
115
|
accountId: relayAccountId,
|
|
116
|
+
instanceId: localInstanceId,
|
|
106
117
|
}),
|
|
107
118
|
timestamp: Date.now(),
|
|
108
119
|
});
|
package/package.json
CHANGED
package/src/plugin.ts
CHANGED
|
@@ -30,10 +30,15 @@ export function registerLibp2pMesh(api: OpenClawPluginApi) {
|
|
|
30
30
|
api.registerService({
|
|
31
31
|
id: "libp2p-mesh",
|
|
32
32
|
start: async () => {
|
|
33
|
+
// Load persisted peer identities FIRST so dedup checks work when
|
|
34
|
+
// peers connect during mesh.start() (mDNS can fire peer:connect
|
|
35
|
+
// before this function's sequential code reaches onPeerConnect).
|
|
36
|
+
await peerIdentityMap.load();
|
|
37
|
+
|
|
33
38
|
await mesh.start();
|
|
34
39
|
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
const instanceIdentity = mesh.getInstanceIdentity();
|
|
41
|
+
const localInstanceId = instanceIdentity?.id;
|
|
37
42
|
|
|
38
43
|
// Register local identity so remote peers can route messages back to us
|
|
39
44
|
const config = api.pluginConfig as MeshConfig | undefined;
|
|
@@ -52,12 +57,16 @@ export function registerLibp2pMesh(api: OpenClawPluginApi) {
|
|
|
52
57
|
channel: relayChannel,
|
|
53
58
|
accountId: relayAccountId,
|
|
54
59
|
sessionKey,
|
|
60
|
+
instanceId: localInstanceId,
|
|
55
61
|
});
|
|
56
62
|
api.logger.info?.(
|
|
57
63
|
`[libp2p-mesh] Local identity registered: agent=${api.name}, channel=${relayChannel}, account=${relayAccountId}`,
|
|
58
64
|
);
|
|
59
65
|
|
|
60
66
|
// Announce identity to all currently-connected peers
|
|
67
|
+
// setLocalIdentity is called BEFORE this block, and localInstanceId
|
|
68
|
+
// is available from mesh.start(), so the identity message includes
|
|
69
|
+
// the instanceId.
|
|
61
70
|
const identityMsg = JSON.stringify({
|
|
62
71
|
id: crypto.randomUUID(),
|
|
63
72
|
type: "identity",
|
|
@@ -66,6 +75,7 @@ export function registerLibp2pMesh(api: OpenClawPluginApi) {
|
|
|
66
75
|
agentId: api.name,
|
|
67
76
|
channel: relayChannel,
|
|
68
77
|
accountId: relayAccountId,
|
|
78
|
+
instanceId: localInstanceId,
|
|
69
79
|
}),
|
|
70
80
|
timestamp: Date.now(),
|
|
71
81
|
});
|
|
@@ -101,6 +111,7 @@ export function registerLibp2pMesh(api: OpenClawPluginApi) {
|
|
|
101
111
|
agentId: api.name,
|
|
102
112
|
channel: relayChannel,
|
|
103
113
|
accountId: relayAccountId,
|
|
114
|
+
instanceId: localInstanceId,
|
|
104
115
|
}),
|
|
105
116
|
timestamp: Date.now(),
|
|
106
117
|
});
|
|
@@ -117,6 +128,7 @@ export function registerLibp2pMesh(api: OpenClawPluginApi) {
|
|
|
117
128
|
agentId: api.name,
|
|
118
129
|
channel: relayChannel,
|
|
119
130
|
accountId: relayAccountId,
|
|
131
|
+
instanceId: localInstanceId,
|
|
120
132
|
}),
|
|
121
133
|
timestamp: Date.now(),
|
|
122
134
|
});
|