nodio-cli 1.0.3 → 1.0.4
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/package.json +1 -1
- package/src/node/index.js +1 -1
- package/src/node/runtime.js +9 -2
- package/src/server/routes.js +41 -25
package/package.json
CHANGED
package/src/node/index.js
CHANGED
package/src/node/runtime.js
CHANGED
|
@@ -85,11 +85,18 @@ class NodioNodeRuntime {
|
|
|
85
85
|
res.json({ ok: true, nodeId: this.nodeId });
|
|
86
86
|
});
|
|
87
87
|
|
|
88
|
-
await new Promise((resolve) => {
|
|
89
|
-
app.listen(this.port, () => {
|
|
88
|
+
await new Promise((resolve, reject) => {
|
|
89
|
+
const server = app.listen({ port: this.port, exclusive: true }, () => {
|
|
90
90
|
console.log(`Nodio node ${this.nodeId} listening on port ${this.port}`);
|
|
91
91
|
resolve();
|
|
92
92
|
});
|
|
93
|
+
|
|
94
|
+
server.once('error', (error) => {
|
|
95
|
+
if (error && error.code === 'EADDRINUSE') {
|
|
96
|
+
return reject(new Error(`port ${this.port} is already in use`));
|
|
97
|
+
}
|
|
98
|
+
return reject(error);
|
|
99
|
+
});
|
|
93
100
|
});
|
|
94
101
|
}
|
|
95
102
|
|
package/src/server/routes.js
CHANGED
|
@@ -63,18 +63,33 @@ function buildRoutes(config) {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
let effectiveNodeId = nodeId || existingByNodeKey?.nodeId || null;
|
|
66
|
+
let claimedKnownNode = null;
|
|
66
67
|
|
|
67
68
|
if (!effectiveNodeId && deviceKey && normalizedKnownNodeIds.length > 0) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
69
|
+
claimedKnownNode = await NodeModel.findOneAndUpdate(
|
|
70
|
+
{
|
|
71
|
+
deviceKey,
|
|
72
|
+
status: 'offline',
|
|
73
|
+
nodeId: { $in: normalizedKnownNodeIds }
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
$set: {
|
|
77
|
+
url,
|
|
78
|
+
capacityBytes: capacity,
|
|
79
|
+
freeBytes: free,
|
|
80
|
+
status: 'online',
|
|
81
|
+
lastHeartbeatAt: new Date(),
|
|
82
|
+
...(nodeKey ? { nodeKey } : {})
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
new: true,
|
|
87
|
+
sort: { createdAt: 1 }
|
|
88
|
+
}
|
|
89
|
+
);
|
|
75
90
|
|
|
76
|
-
if (
|
|
77
|
-
effectiveNodeId =
|
|
91
|
+
if (claimedKnownNode) {
|
|
92
|
+
effectiveNodeId = claimedKnownNode.nodeId;
|
|
78
93
|
}
|
|
79
94
|
}
|
|
80
95
|
|
|
@@ -82,22 +97,23 @@ function buildRoutes(config) {
|
|
|
82
97
|
effectiveNodeId = `donor-${uuidv4().slice(0, 8)}`;
|
|
83
98
|
}
|
|
84
99
|
|
|
85
|
-
const node =
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
100
|
+
const node = claimedKnownNode
|
|
101
|
+
|| await NodeModel.findOneAndUpdate(
|
|
102
|
+
{ nodeId: effectiveNodeId },
|
|
103
|
+
{
|
|
104
|
+
$set: {
|
|
105
|
+
nodeId: effectiveNodeId,
|
|
106
|
+
...(deviceKey ? { deviceKey } : {}),
|
|
107
|
+
...(nodeKey ? { nodeKey } : {}),
|
|
108
|
+
url,
|
|
109
|
+
capacityBytes: capacity,
|
|
110
|
+
freeBytes: free,
|
|
111
|
+
status: 'online',
|
|
112
|
+
lastHeartbeatAt: new Date()
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
{ upsert: true, new: true, setDefaultsOnInsert: true }
|
|
116
|
+
);
|
|
101
117
|
|
|
102
118
|
res.json({
|
|
103
119
|
nodeId: node.nodeId,
|