@highway1/cli 0.1.38 → 0.1.40
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/index.js +62 -10
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/commands/join.ts +37 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@highway1/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.40",
|
|
4
4
|
"description": "CLI tool for Clawiverse network",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"clean": "rm -rf dist"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@highway1/core": "
|
|
16
|
+
"@highway1/core": "workspace:*",
|
|
17
17
|
"chalk": "^5.3.0",
|
|
18
18
|
"cli-table3": "^0.6.5",
|
|
19
19
|
"commander": "^12.1.0",
|
package/src/commands/join.ts
CHANGED
|
@@ -87,17 +87,17 @@ export function registerJoinCommand(program: Command): void {
|
|
|
87
87
|
}, 15000);
|
|
88
88
|
|
|
89
89
|
// Listen for relay:reservation event (fires when reservation succeeds)
|
|
90
|
-
const onReservation = (
|
|
90
|
+
const onReservation = () => {
|
|
91
91
|
reservationSucceeded = true;
|
|
92
92
|
info(`✓ Relay reservation successful!`);
|
|
93
93
|
clearTimeout(timeout);
|
|
94
94
|
setTimeout(resolve, 500);
|
|
95
95
|
};
|
|
96
96
|
|
|
97
|
-
node.libp2p.addEventListener('relay:reservation', onReservation, { once: true });
|
|
97
|
+
(node.libp2p as any).addEventListener('relay:reservation', onReservation, { once: true });
|
|
98
98
|
|
|
99
99
|
setTimeout(() => {
|
|
100
|
-
node.libp2p.removeEventListener('relay:reservation', onReservation);
|
|
100
|
+
(node.libp2p as any).removeEventListener('relay:reservation', onReservation);
|
|
101
101
|
}, 15000);
|
|
102
102
|
});
|
|
103
103
|
|
|
@@ -114,12 +114,22 @@ export function registerJoinCommand(program: Command): void {
|
|
|
114
114
|
const directAddrs = node.getMultiaddrs().filter(a => !a.includes('/p2p-circuit'));
|
|
115
115
|
const relayAddrs = node.getMultiaddrs().filter(a => a.includes('/p2p-circuit'));
|
|
116
116
|
const fallbackRelayAddrs = relayAddrs.length === 0
|
|
117
|
-
? bootstrapPeers.map(r => `${r}/p2p-circuit/p2p/${node.getPeerId()}`)
|
|
117
|
+
? bootstrapPeers.map((r: string) => `${r}/p2p-circuit/p2p/${node.getPeerId()}`)
|
|
118
118
|
: [];
|
|
119
119
|
const allAddrs = [...directAddrs, ...relayAddrs, ...fallbackRelayAddrs];
|
|
120
120
|
|
|
121
|
-
const capabilities =
|
|
122
|
-
|
|
121
|
+
const capabilities = (card.capabilities ?? []).map((capability: string) => ({
|
|
122
|
+
id: capability,
|
|
123
|
+
name: capability,
|
|
124
|
+
description: `Capability: ${capability}`,
|
|
125
|
+
}));
|
|
126
|
+
if (options.relay) {
|
|
127
|
+
capabilities.push({
|
|
128
|
+
id: 'relay',
|
|
129
|
+
name: 'relay',
|
|
130
|
+
description: 'Provides circuit relay service for NAT traversal',
|
|
131
|
+
});
|
|
132
|
+
}
|
|
123
133
|
|
|
124
134
|
const agentCard = createAgentCard(
|
|
125
135
|
identity.did,
|
|
@@ -141,14 +151,29 @@ export function registerJoinCommand(program: Command): void {
|
|
|
141
151
|
|
|
142
152
|
// Keep connection alive by pinging bootstrap peers periodically
|
|
143
153
|
const pingInterval = setInterval(async () => {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
154
|
+
const peers = node.libp2p.getPeers();
|
|
155
|
+
if (peers.length === 0) {
|
|
156
|
+
// No peers connected, try to reconnect to bootstrap
|
|
157
|
+
for (const bootstrapAddr of bootstrapPeers) {
|
|
158
|
+
try {
|
|
159
|
+
await node.libp2p.dial(bootstrapAddr);
|
|
160
|
+
info('Reconnected to bootstrap peer');
|
|
161
|
+
break;
|
|
162
|
+
} catch {
|
|
163
|
+
// try next bootstrap peer
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
} else {
|
|
167
|
+
// Ping existing peers to keep connection alive
|
|
168
|
+
for (const peer of peers) {
|
|
169
|
+
try {
|
|
170
|
+
await (node.libp2p.services.ping as any).ping(peer);
|
|
171
|
+
} catch {
|
|
172
|
+
// ignore ping failures
|
|
173
|
+
}
|
|
149
174
|
}
|
|
150
175
|
}
|
|
151
|
-
},
|
|
176
|
+
}, 15000); // ping every 15s (reduced from 30s for better stability)
|
|
152
177
|
|
|
153
178
|
const verifyFn = async (signature: Uint8Array, data: Uint8Array): Promise<boolean> => {
|
|
154
179
|
try {
|