@trap_stevo/filetide 0.0.85 → 0.0.87
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/SCL-1.0-Universal.md +228 -0
- package/dist/cjs/FileMessagerClient.js +134 -70
- package/dist/cjs/FileTide.js +163 -82
- package/dist/cjs/{FileMessager.js → FileTideAnchor.js} +464 -264
- package/dist/cjs/HUDManagers/EndpointManager.js +157 -0
- package/dist/cjs/HUDManagers/{FileNetClientManager.js → FileTideAnchorClientManager.js} +3 -2
- package/dist/cjs/HUDManagers/{FileNetUtilityManager.js → FileTideAnchorUtilityManager.js} +2 -2
- package/dist/cjs/HUDManagers/FileTideDebugUtilityManager.js +6 -0
- package/dist/cjs/HUDManagers/FileTideNetworkTrafficManager.js +419 -0
- package/dist/cjs/HUDManagers/FileTransferManager.js +90 -157
- package/dist/cjs/HUDManagers/FileTransferReceiverManager.js +169 -9
- package/dist/cjs/HUDManagers/FileTransferStatsManager.js +138 -0
- package/dist/cjs/HUDManagers/FileTransferTrackingManager.js +22 -0
- package/package.json +4 -5
- package/LICENSE.md +0 -79
- package/dist/cjs/HUDComponents/ConsoleProgressBarManager.js +0 -288
|
@@ -8,14 +8,14 @@ const {
|
|
|
8
8
|
} = require("@trap_stevo/legendarybuilderpronodejs-utilities/HUDStructs");
|
|
9
9
|
const IoTide = require("@trap_stevo/iotide");
|
|
10
10
|
const {
|
|
11
|
-
|
|
12
|
-
} = require("./HUDManagers/
|
|
11
|
+
FileTideAnchorUtilityManager
|
|
12
|
+
} = require("./HUDManagers/FileTideAnchorUtilityManager");
|
|
13
13
|
const {
|
|
14
|
-
|
|
15
|
-
} = require("./HUDManagers/
|
|
14
|
+
FileTideAnchorClientManager
|
|
15
|
+
} = require("./HUDManagers/FileTideAnchorClientManager");
|
|
16
16
|
const {
|
|
17
|
-
|
|
18
|
-
} = require("./HUDManagers/
|
|
17
|
+
FileMessagerConfigManager
|
|
18
|
+
} = require("./HUDManagers/FileMessagerConfigManager");
|
|
19
19
|
const {
|
|
20
20
|
FileTransferManager
|
|
21
21
|
} = require("./HUDManagers/FileTransferManager");
|
|
@@ -28,8 +28,8 @@ const HUDTargetQueue = require("./HUDManagers/HUDTargetQueueManager");
|
|
|
28
28
|
const {
|
|
29
29
|
tidalytics
|
|
30
30
|
} = require("./HUDManagers/TidalyticsManager");
|
|
31
|
-
var
|
|
32
|
-
class
|
|
31
|
+
var _FileTideAnchor_brand = /*#__PURE__*/new WeakSet();
|
|
32
|
+
class FileTideAnchor {
|
|
33
33
|
constructor(options = {
|
|
34
34
|
pingTimeout: 180000,
|
|
35
35
|
pingInterval: 60000
|
|
@@ -37,7 +37,7 @@ class FileMessager {
|
|
|
37
37
|
parallelChunks: 3,
|
|
38
38
|
maxRetries: 3
|
|
39
39
|
}, onTideAction = null, debugMode = false, tideSentinelOptions = {}) {
|
|
40
|
-
_classPrivateMethodInitSpec(this,
|
|
40
|
+
_classPrivateMethodInitSpec(this, _FileTideAnchor_brand);
|
|
41
41
|
const serverOptions = FileMessagerConfigManager.getServerOptions(options);
|
|
42
42
|
this.transporter = new FileTransferManager(transportOptions);
|
|
43
43
|
this.transferQueue = new HUDTargetQueue();
|
|
@@ -48,7 +48,7 @@ class FileMessager {
|
|
|
48
48
|
this.tideSentinel.registerEntryAddedHook((key, entryData) => {
|
|
49
49
|
console.log(key, entryData);
|
|
50
50
|
});
|
|
51
|
-
this.
|
|
51
|
+
this.anchor = new IoTide(serverOptions.port, serverOptions, true, this.onConnect.bind(this), this.onDisconnect.bind(this));
|
|
52
52
|
this.onlineClients = new OmniMap();
|
|
53
53
|
this.onTideAction = onTideAction ?? (() => {});
|
|
54
54
|
this.debugMode = debugMode;
|
|
@@ -64,7 +64,7 @@ class FileMessager {
|
|
|
64
64
|
}
|
|
65
65
|
onDisconnect(connectionRes, socket) {
|
|
66
66
|
console.log(`Client disconnected ~ ${socket.id}`);
|
|
67
|
-
const currentOnlineClient =
|
|
67
|
+
const currentOnlineClient = FileTideAnchorClientManager.getOnlineClientByConnectionID(socket.id);
|
|
68
68
|
if (currentOnlineClient) {
|
|
69
69
|
this.handleClientOffline({}, {
|
|
70
70
|
connectionID: currentOnlineClient.id,
|
|
@@ -75,28 +75,29 @@ class FileMessager {
|
|
|
75
75
|
return;
|
|
76
76
|
}
|
|
77
77
|
close() {
|
|
78
|
-
this.
|
|
78
|
+
this.anchor.close();
|
|
79
79
|
return;
|
|
80
80
|
}
|
|
81
81
|
start() {
|
|
82
|
-
this.
|
|
83
|
-
this.
|
|
84
|
-
this.
|
|
85
|
-
this.
|
|
86
|
-
this.
|
|
87
|
-
this.
|
|
88
|
-
this.
|
|
89
|
-
this.
|
|
90
|
-
this.
|
|
91
|
-
this.
|
|
92
|
-
this.
|
|
93
|
-
this.
|
|
94
|
-
this.
|
|
95
|
-
this.
|
|
96
|
-
this.
|
|
97
|
-
this.
|
|
98
|
-
this.
|
|
99
|
-
this.
|
|
82
|
+
this.anchor.on("get-client-transfer-barrier-response", this.handleClientTransferBarrierResponse.bind(this));
|
|
83
|
+
this.anchor.on("get-client", this.handleGetClient.bind(this));
|
|
84
|
+
this.anchor.on("acknowledge-transfer-tide", this.handleAcknowledgeTransferTide.bind(this));
|
|
85
|
+
this.anchor.on("notify-transfer-barrier", this.handleNotifyTransferBarrier.bind(this));
|
|
86
|
+
this.anchor.on("sent-file-list-to-client", this.handleSentFileListToClient.bind(this));
|
|
87
|
+
this.anchor.on("send-file-list-to-client", this.handleSendFileListToClient.bind(this));
|
|
88
|
+
this.anchor.on("list-client-files", this.handleListClientFiles.bind(this));
|
|
89
|
+
this.anchor.on("transfer-start", this.handleFileTransferStart.bind(this));
|
|
90
|
+
this.anchor.on("transfer-progress", this.handleFileTransferProgress.bind(this));
|
|
91
|
+
this.anchor.on("transfer-complete", this.handleFileTransferComplete.bind(this));
|
|
92
|
+
this.anchor.on("transfer-failed", this.handleFileTransferFailed.bind(this));
|
|
93
|
+
this.anchor.on("request-transfer-from-client", this.handleRequestTransferFromClient.bind(this));
|
|
94
|
+
this.anchor.on("client-to-client-transfer", this.handleClientToClientTransfer.bind(this));
|
|
95
|
+
this.anchor.on("check-client-banned", this.handleCheckClientBanned.bind(this));
|
|
96
|
+
this.anchor.on("check-client-online", this.handleCheckClientOnline.bind(this));
|
|
97
|
+
this.anchor.on("client-offline", this.handleClientOffline.bind(this));
|
|
98
|
+
this.anchor.on("clients-online", this.handleClientsOnline.bind(this));
|
|
99
|
+
this.anchor.on("client-online", this.handleClientOnline.bind(this));
|
|
100
|
+
this.anchor.on("client-tiding", this.handleClientTiding.bind(this));
|
|
100
101
|
return;
|
|
101
102
|
}
|
|
102
103
|
|
|
@@ -158,7 +159,7 @@ class FileMessager {
|
|
|
158
159
|
end = null
|
|
159
160
|
} = options;
|
|
160
161
|
const sources = ["storage", "memory"];
|
|
161
|
-
const fetch = _assertClassBrand(
|
|
162
|
+
const fetch = _assertClassBrand(_FileTideAnchor_brand, this, _getTidalyticsRangeFetcher).call(this, interval, rangeMode, start, end);
|
|
162
163
|
const [storedOnline, storedOffline] = await Promise.all([fetch({
|
|
163
164
|
...filter,
|
|
164
165
|
tags: {
|
|
@@ -230,7 +231,7 @@ class FileMessager {
|
|
|
230
231
|
...chartConfig
|
|
231
232
|
};
|
|
232
233
|
const sources = ["storage", "memory"];
|
|
233
|
-
const fetch = _assertClassBrand(
|
|
234
|
+
const fetch = _assertClassBrand(_FileTideAnchor_brand, this, _getTidalyticsRangeFetcher).call(this, interval, rangeMode, start, end);
|
|
234
235
|
const [alreadyOnlineEvents, onlineJoins] = await Promise.all([fetch({
|
|
235
236
|
...filter,
|
|
236
237
|
tags: {
|
|
@@ -291,7 +292,7 @@ class FileMessager {
|
|
|
291
292
|
...chartConfig
|
|
292
293
|
};
|
|
293
294
|
const sources = ["storage", "memory"];
|
|
294
|
-
const fetch = _assertClassBrand(
|
|
295
|
+
const fetch = _assertClassBrand(_FileTideAnchor_brand, this, _getTidalyticsRangeFetcher).call(this, interval, rangeMode, start, end);
|
|
295
296
|
const [banned, kicked, unbanned] = await Promise.all([fetch({
|
|
296
297
|
...filter,
|
|
297
298
|
tags: {
|
|
@@ -346,7 +347,7 @@ class FileMessager {
|
|
|
346
347
|
...chartConfig
|
|
347
348
|
};
|
|
348
349
|
const sources = ["storage", "memory"];
|
|
349
|
-
const fetch = _assertClassBrand(
|
|
350
|
+
const fetch = _assertClassBrand(_FileTideAnchor_brand, this, _getTidalyticsRangeFetcher).call(this, interval, rangeMode, start, end);
|
|
350
351
|
const [incomingTransfers, incoming, completed] = await Promise.all([fetch({
|
|
351
352
|
...filter,
|
|
352
353
|
tags: {
|
|
@@ -404,7 +405,7 @@ class FileMessager {
|
|
|
404
405
|
...chartConfig
|
|
405
406
|
};
|
|
406
407
|
const sources = ["storage", "memory"];
|
|
407
|
-
const fetch = _assertClassBrand(
|
|
408
|
+
const fetch = _assertClassBrand(_FileTideAnchor_brand, this, _getTidalyticsRangeFetcher).call(this, interval, rangeMode, start, end);
|
|
408
409
|
const [transferStates] = await Promise.all([fetch({
|
|
409
410
|
...filter,
|
|
410
411
|
tags: {
|
|
@@ -443,7 +444,7 @@ class FileMessager {
|
|
|
443
444
|
...chartConfig
|
|
444
445
|
};
|
|
445
446
|
const sources = ["storage", "memory"];
|
|
446
|
-
const fetch = _assertClassBrand(
|
|
447
|
+
const fetch = _assertClassBrand(_FileTideAnchor_brand, this, _getTidalyticsRangeFetcher).call(this, interval, rangeMode, start, end);
|
|
447
448
|
const [requested, received] = await Promise.all([fetch({
|
|
448
449
|
...filter,
|
|
449
450
|
tags: {
|
|
@@ -490,7 +491,7 @@ class FileMessager {
|
|
|
490
491
|
...chartConfig
|
|
491
492
|
};
|
|
492
493
|
const sources = ["storage", "memory"];
|
|
493
|
-
const fetch = _assertClassBrand(
|
|
494
|
+
const fetch = _assertClassBrand(_FileTideAnchor_brand, this, _getTidalyticsRangeFetcher).call(this, interval, rangeMode, start, end);
|
|
494
495
|
const [accepted, denied] = await Promise.all([fetch({
|
|
495
496
|
...filter,
|
|
496
497
|
tags: {
|
|
@@ -840,7 +841,7 @@ class FileMessager {
|
|
|
840
841
|
start = null,
|
|
841
842
|
end = null
|
|
842
843
|
} = options;
|
|
843
|
-
const fetch = _assertClassBrand(
|
|
844
|
+
const fetch = _assertClassBrand(_FileTideAnchor_brand, this, _getTidalyticsRangeFetcher).call(this, interval, rangeMode, start, end);
|
|
844
845
|
const rawMetrics = await fetch({
|
|
845
846
|
...filter,
|
|
846
847
|
tags: {
|
|
@@ -876,7 +877,7 @@ class FileMessager {
|
|
|
876
877
|
start = null,
|
|
877
878
|
end = null
|
|
878
879
|
} = options;
|
|
879
|
-
const fetch = _assertClassBrand(
|
|
880
|
+
const fetch = _assertClassBrand(_FileTideAnchor_brand, this, _getTidalyticsRangeFetcher).call(this, interval, rangeMode, start, end);
|
|
880
881
|
const rawMetrics = await fetch({
|
|
881
882
|
...filter,
|
|
882
883
|
tags: {
|
|
@@ -915,7 +916,7 @@ class FileMessager {
|
|
|
915
916
|
start = null,
|
|
916
917
|
end = null
|
|
917
918
|
} = options;
|
|
918
|
-
const fetch = _assertClassBrand(
|
|
919
|
+
const fetch = _assertClassBrand(_FileTideAnchor_brand, this, _getTidalyticsRangeFetcher).call(this, interval, rangeMode, start, end);
|
|
919
920
|
const rawMetrics = await fetch({
|
|
920
921
|
...filter,
|
|
921
922
|
tags: {
|
|
@@ -950,7 +951,7 @@ class FileMessager {
|
|
|
950
951
|
start = null,
|
|
951
952
|
end = null
|
|
952
953
|
} = options;
|
|
953
|
-
const fetch = _assertClassBrand(
|
|
954
|
+
const fetch = _assertClassBrand(_FileTideAnchor_brand, this, _getTidalyticsRangeFetcher).call(this, interval, rangeMode, start, end);
|
|
954
955
|
const rawMetrics = await fetch({
|
|
955
956
|
...filter,
|
|
956
957
|
tags: {
|
|
@@ -984,7 +985,7 @@ class FileMessager {
|
|
|
984
985
|
start = null,
|
|
985
986
|
end = null
|
|
986
987
|
} = options;
|
|
987
|
-
const fetch = _assertClassBrand(
|
|
988
|
+
const fetch = _assertClassBrand(_FileTideAnchor_brand, this, _getTidalyticsRangeFetcher).call(this, interval, rangeMode, start, end);
|
|
988
989
|
const rawMetrics = await fetch({
|
|
989
990
|
...filter,
|
|
990
991
|
tags: {
|
|
@@ -1021,7 +1022,7 @@ class FileMessager {
|
|
|
1021
1022
|
start = null,
|
|
1022
1023
|
end = null
|
|
1023
1024
|
} = options;
|
|
1024
|
-
const fetch = _assertClassBrand(
|
|
1025
|
+
const fetch = _assertClassBrand(_FileTideAnchor_brand, this, _getTidalyticsRangeFetcher).call(this, interval, rangeMode, start, end);
|
|
1025
1026
|
const rawMetrics = await fetch({
|
|
1026
1027
|
...filter,
|
|
1027
1028
|
tags: {
|
|
@@ -1058,7 +1059,7 @@ class FileMessager {
|
|
|
1058
1059
|
start = null,
|
|
1059
1060
|
end = null
|
|
1060
1061
|
} = options;
|
|
1061
|
-
const fetch = _assertClassBrand(
|
|
1062
|
+
const fetch = _assertClassBrand(_FileTideAnchor_brand, this, _getTidalyticsRangeFetcher).call(this, interval, rangeMode, start, end);
|
|
1062
1063
|
const rawMetrics = await fetch({
|
|
1063
1064
|
...filter,
|
|
1064
1065
|
tags: {
|
|
@@ -1090,7 +1091,7 @@ class FileMessager {
|
|
|
1090
1091
|
start = null,
|
|
1091
1092
|
end = null
|
|
1092
1093
|
} = options;
|
|
1093
|
-
const fetch = _assertClassBrand(
|
|
1094
|
+
const fetch = _assertClassBrand(_FileTideAnchor_brand, this, _getTidalyticsRangeFetcher).call(this, interval, rangeMode, start, end);
|
|
1094
1095
|
const rawMetrics = await fetch({
|
|
1095
1096
|
...filter,
|
|
1096
1097
|
tags: {
|
|
@@ -1121,7 +1122,7 @@ class FileMessager {
|
|
|
1121
1122
|
start = null,
|
|
1122
1123
|
end = null
|
|
1123
1124
|
} = options;
|
|
1124
|
-
const fetch = _assertClassBrand(
|
|
1125
|
+
const fetch = _assertClassBrand(_FileTideAnchor_brand, this, _getTidalyticsRangeFetcher).call(this, interval, rangeMode, start, end);
|
|
1125
1126
|
const rawMetrics = await fetch({
|
|
1126
1127
|
...filter,
|
|
1127
1128
|
tags: {
|
|
@@ -1151,7 +1152,7 @@ class FileMessager {
|
|
|
1151
1152
|
start = null,
|
|
1152
1153
|
end = null
|
|
1153
1154
|
} = options;
|
|
1154
|
-
const fetch = _assertClassBrand(
|
|
1155
|
+
const fetch = _assertClassBrand(_FileTideAnchor_brand, this, _getTidalyticsRangeFetcher).call(this, interval, rangeMode, start, end);
|
|
1155
1156
|
const rawMetrics = await fetch({
|
|
1156
1157
|
...filter,
|
|
1157
1158
|
tags: {
|
|
@@ -1181,7 +1182,7 @@ class FileMessager {
|
|
|
1181
1182
|
start = null,
|
|
1182
1183
|
end = null
|
|
1183
1184
|
} = options;
|
|
1184
|
-
const fetch = _assertClassBrand(
|
|
1185
|
+
const fetch = _assertClassBrand(_FileTideAnchor_brand, this, _getTidalyticsRangeFetcher).call(this, interval, rangeMode, start, end);
|
|
1185
1186
|
const rawMetrics = await fetch({
|
|
1186
1187
|
...filter,
|
|
1187
1188
|
tags: {
|
|
@@ -1210,7 +1211,7 @@ class FileMessager {
|
|
|
1210
1211
|
start = null,
|
|
1211
1212
|
end = null
|
|
1212
1213
|
} = options;
|
|
1213
|
-
const fetch = _assertClassBrand(
|
|
1214
|
+
const fetch = _assertClassBrand(_FileTideAnchor_brand, this, _getTidalyticsRangeFetcher).call(this, interval, rangeMode, start, end);
|
|
1214
1215
|
const rawMetrics = await fetch({
|
|
1215
1216
|
...filter,
|
|
1216
1217
|
tags: {
|
|
@@ -1245,7 +1246,7 @@ class FileMessager {
|
|
|
1245
1246
|
start = null,
|
|
1246
1247
|
end = null
|
|
1247
1248
|
} = options;
|
|
1248
|
-
const fetch = _assertClassBrand(
|
|
1249
|
+
const fetch = _assertClassBrand(_FileTideAnchor_brand, this, _getTidalyticsRangeFetcher).call(this, interval, rangeMode, start, end);
|
|
1249
1250
|
const rawMetrics = await fetch({
|
|
1250
1251
|
...filter,
|
|
1251
1252
|
tags: {
|
|
@@ -1280,7 +1281,7 @@ class FileMessager {
|
|
|
1280
1281
|
start = null,
|
|
1281
1282
|
end = null
|
|
1282
1283
|
} = options;
|
|
1283
|
-
const fetch = _assertClassBrand(
|
|
1284
|
+
const fetch = _assertClassBrand(_FileTideAnchor_brand, this, _getTidalyticsRangeFetcher).call(this, interval, rangeMode, start, end);
|
|
1284
1285
|
const rawMetrics = await fetch({
|
|
1285
1286
|
...filter,
|
|
1286
1287
|
tags: {
|
|
@@ -1442,7 +1443,7 @@ class FileMessager {
|
|
|
1442
1443
|
return client;
|
|
1443
1444
|
}
|
|
1444
1445
|
getClient(clientID) {
|
|
1445
|
-
const client =
|
|
1446
|
+
const client = FileTideAnchorClientManager.getOnlineClient(clientID);
|
|
1446
1447
|
if (!client) {
|
|
1447
1448
|
console.log(`Client ~ ${clientID} not found.`);
|
|
1448
1449
|
return;
|
|
@@ -1450,15 +1451,15 @@ class FileMessager {
|
|
|
1450
1451
|
return client;
|
|
1451
1452
|
}
|
|
1452
1453
|
getOnlineClients() {
|
|
1453
|
-
return
|
|
1454
|
+
return FileTideAnchorClientManager.getOnlineClients();
|
|
1454
1455
|
}
|
|
1455
1456
|
requestFromClient(requesterID, senderID, filePath = process.cwd(), destinationPath) {
|
|
1456
|
-
const senderConnectionID =
|
|
1457
|
+
const senderConnectionID = FileTideAnchorClientManager.getOnlineClient(senderID).id;
|
|
1457
1458
|
const client = this.getClientFromID(senderConnectionID);
|
|
1458
1459
|
if (!client) {
|
|
1459
1460
|
return;
|
|
1460
1461
|
}
|
|
1461
|
-
this.
|
|
1462
|
+
this.anchor.emitToTide(client.tideID, "transfer-requested", {
|
|
1462
1463
|
senderID,
|
|
1463
1464
|
requesterID,
|
|
1464
1465
|
path: filePath,
|
|
@@ -1483,7 +1484,7 @@ class FileMessager {
|
|
|
1483
1484
|
return;
|
|
1484
1485
|
}
|
|
1485
1486
|
if (chunkIndex === 0) {
|
|
1486
|
-
this.
|
|
1487
|
+
this.anchor.emitToTide(client.tideID, "incoming-file", {
|
|
1487
1488
|
senderID: senderData.userID,
|
|
1488
1489
|
clientID: clientData.userID,
|
|
1489
1490
|
fileName,
|
|
@@ -1529,7 +1530,7 @@ class FileMessager {
|
|
|
1529
1530
|
}
|
|
1530
1531
|
});
|
|
1531
1532
|
}
|
|
1532
|
-
this.
|
|
1533
|
+
this.anchor.emitToTide(client.tideID, "transfer-progress", {
|
|
1533
1534
|
senderName: senderData.userID,
|
|
1534
1535
|
senderID: senderData.id,
|
|
1535
1536
|
fileName,
|
|
@@ -1540,9 +1541,9 @@ class FileMessager {
|
|
|
1540
1541
|
fileSize,
|
|
1541
1542
|
metadata
|
|
1542
1543
|
});
|
|
1543
|
-
_assertClassBrand(
|
|
1544
|
+
_assertClassBrand(_FileTideAnchor_brand, this, _log).call(this, `[FileTide ~ Anchor Transporter] ~ Sent chunk ${chunkIndex} of ${fileName} to client ~ ${clientData.userID}!`);
|
|
1544
1545
|
if (senderClient) {
|
|
1545
|
-
this.
|
|
1546
|
+
this.anchor.emitToTide(senderClient.tideID, "transfer-status", {
|
|
1546
1547
|
status: `Chunk ${chunkIndex} of ${fileName} sent to client ${clientData.userID}!`,
|
|
1547
1548
|
recipientID: clientData.userID,
|
|
1548
1549
|
senderName: senderData.userID,
|
|
@@ -1578,14 +1579,14 @@ class FileMessager {
|
|
|
1578
1579
|
runningOn
|
|
1579
1580
|
} = listData;
|
|
1580
1581
|
try {
|
|
1581
|
-
const recipientConnectionID =
|
|
1582
|
-
const senderConnectionID =
|
|
1582
|
+
const recipientConnectionID = FileTideAnchorClientManager.getOnlineClient(recipientID).id;
|
|
1583
|
+
const senderConnectionID = FileTideAnchorClientManager.getOnlineClient(senderID).id;
|
|
1583
1584
|
const senderClient = this.getClientFromID(senderConnectionID);
|
|
1584
1585
|
const client = this.getClientFromID(recipientConnectionID);
|
|
1585
1586
|
if (!client || !senderClient) {
|
|
1586
1587
|
return;
|
|
1587
1588
|
}
|
|
1588
|
-
this.
|
|
1589
|
+
this.anchor.emitToTide(client.tideID, "client-file-list-received", {
|
|
1589
1590
|
senderID,
|
|
1590
1591
|
totalItemsSent,
|
|
1591
1592
|
runningOn
|
|
@@ -1618,7 +1619,7 @@ class FileMessager {
|
|
|
1618
1619
|
}
|
|
1619
1620
|
});
|
|
1620
1621
|
} catch (error) {
|
|
1621
|
-
console.error(`[FileTide ~
|
|
1622
|
+
console.error(`[FileTide ~ Anchor Scanner] ~ `, error);
|
|
1622
1623
|
return;
|
|
1623
1624
|
}
|
|
1624
1625
|
}
|
|
@@ -1631,21 +1632,21 @@ class FileMessager {
|
|
|
1631
1632
|
runningOn
|
|
1632
1633
|
} = listData;
|
|
1633
1634
|
try {
|
|
1634
|
-
const recipientConnectionID =
|
|
1635
|
-
const senderConnectionID =
|
|
1635
|
+
const recipientConnectionID = FileTideAnchorClientManager.getOnlineClient(recipientID).id;
|
|
1636
|
+
const senderConnectionID = FileTideAnchorClientManager.getOnlineClient(senderID).id;
|
|
1636
1637
|
const senderClient = this.getClientFromID(senderConnectionID);
|
|
1637
1638
|
const client = this.getClientFromID(recipientConnectionID);
|
|
1638
1639
|
if (!client || !senderClient) {
|
|
1639
1640
|
return;
|
|
1640
1641
|
}
|
|
1641
|
-
this.
|
|
1642
|
+
this.anchor.emitToTide(client.tideID, "client-file-list", {
|
|
1642
1643
|
senderID,
|
|
1643
1644
|
totalItems,
|
|
1644
1645
|
listedFiles,
|
|
1645
1646
|
runningOn
|
|
1646
1647
|
});
|
|
1647
1648
|
} catch (error) {
|
|
1648
|
-
console.error(`[FileTide ~
|
|
1649
|
+
console.error(`[FileTide ~ Anchor Scanner] ~ `, error);
|
|
1649
1650
|
return;
|
|
1650
1651
|
}
|
|
1651
1652
|
}
|
|
@@ -1656,14 +1657,14 @@ class FileMessager {
|
|
|
1656
1657
|
depth = 1
|
|
1657
1658
|
} = clientData;
|
|
1658
1659
|
try {
|
|
1659
|
-
const recipientConnectionID =
|
|
1660
|
-
const senderConnectionID =
|
|
1660
|
+
const recipientConnectionID = FileTideAnchorClientManager.getOnlineClient(recipientID).id;
|
|
1661
|
+
const senderConnectionID = FileTideAnchorClientManager.getOnlineClient(requesterID).id;
|
|
1661
1662
|
const senderClient = this.getClientFromID(senderConnectionID);
|
|
1662
1663
|
const client = this.getClientFromID(recipientConnectionID);
|
|
1663
1664
|
if (!client || !senderClient) {
|
|
1664
1665
|
return;
|
|
1665
1666
|
}
|
|
1666
|
-
this.
|
|
1667
|
+
this.anchor.emitToTide(client.tideID, "list-files", {
|
|
1667
1668
|
senderID: requesterID,
|
|
1668
1669
|
recipientID,
|
|
1669
1670
|
depth
|
|
@@ -1693,140 +1694,113 @@ class FileMessager {
|
|
|
1693
1694
|
}
|
|
1694
1695
|
});
|
|
1695
1696
|
} catch (error) {
|
|
1696
|
-
console.error(`[FileTide ~
|
|
1697
|
+
console.error(`[FileTide ~ Anchor Scanner] ~ `, error);
|
|
1697
1698
|
return;
|
|
1698
1699
|
}
|
|
1699
1700
|
}
|
|
1700
1701
|
handleClientToClientTransfer(senderTide, transferData) {
|
|
1701
1702
|
try {
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
fileSize,
|
|
1752
|
-
fileName
|
|
1753
|
-
},
|
|
1754
|
-
metadata: {
|
|
1755
|
-
recipientID: recipientId,
|
|
1756
|
-
senderID,
|
|
1757
|
-
path: filePath,
|
|
1758
|
-
fileSize,
|
|
1759
|
-
fileName,
|
|
1760
|
-
completedChunks,
|
|
1761
|
-
totalChunks,
|
|
1762
|
-
chunkSize,
|
|
1763
|
-
transferMetadata: metadata
|
|
1764
|
-
}
|
|
1765
|
-
});
|
|
1766
|
-
this.onTideAction({
|
|
1767
|
-
tideActionID: "tide-completed-transfer",
|
|
1768
|
-
tideActionDate: Date.now(),
|
|
1769
|
-
tideActionDetails: {
|
|
1770
|
-
recipientID: recipientId,
|
|
1771
|
-
senderID,
|
|
1772
|
-
path: filePath,
|
|
1773
|
-
fileSize,
|
|
1774
|
-
fileName,
|
|
1775
|
-
completedChunks,
|
|
1776
|
-
totalChunks,
|
|
1777
|
-
chunkSize,
|
|
1778
|
-
transferMetadata: metadata
|
|
1779
|
-
}
|
|
1780
|
-
});
|
|
1781
|
-
console.log(`[FileTide ~ File Messager] ~ File transfer completed: ${fileName} from ${senderID} to ${recipientId}`);
|
|
1782
|
-
const tidingTransfers = this.currentTidingTransfers.get(senderID);
|
|
1783
|
-
if (tidingTransfers) {
|
|
1784
|
-
tidingTransfers.delete(senderID);
|
|
1785
|
-
}
|
|
1786
|
-
}
|
|
1787
|
-
}
|
|
1788
|
-
return;
|
|
1703
|
+
let tide = transferData?.tide;
|
|
1704
|
+
if (!tide && Array.isArray(transferData?.chunkBatch) && transferData.chunkBatch.length > 0) {
|
|
1705
|
+
const legacyChunks = transferData.chunkBatch;
|
|
1706
|
+
const firstChunk = legacyChunks[0];
|
|
1707
|
+
const lastChunk = legacyChunks[legacyChunks.length - 1];
|
|
1708
|
+
tide = {
|
|
1709
|
+
transferId: firstChunk.transferId,
|
|
1710
|
+
senderID: firstChunk.senderID,
|
|
1711
|
+
recipientId: firstChunk.recipientId,
|
|
1712
|
+
fileName: firstChunk.fileName,
|
|
1713
|
+
filePath: firstChunk.filePath,
|
|
1714
|
+
fileSize: firstChunk.fileSize,
|
|
1715
|
+
totalChunks: firstChunk.totalChunks,
|
|
1716
|
+
firstChunkIndex: firstChunk.chunkIndex,
|
|
1717
|
+
lastChunkIndex: lastChunk.chunkIndex,
|
|
1718
|
+
completedChunks: lastChunk.completedChunks,
|
|
1719
|
+
tideChunkCount: legacyChunks.length,
|
|
1720
|
+
tideBytes: legacyChunks.reduce((total, chunk) => total + chunk.chunkSize, 0),
|
|
1721
|
+
chunks: legacyChunks.map(chunk => ({
|
|
1722
|
+
chunkIndex: chunk.chunkIndex,
|
|
1723
|
+
chunkSize: chunk.chunkSize,
|
|
1724
|
+
fileChunk: chunk.fileChunk
|
|
1725
|
+
})),
|
|
1726
|
+
metadata: firstChunk.metadata || {}
|
|
1727
|
+
};
|
|
1728
|
+
} else if (!tide && transferData?.fileChunk !== undefined) {
|
|
1729
|
+
tide = {
|
|
1730
|
+
transferId: transferData.transferId,
|
|
1731
|
+
senderID: transferData.senderID,
|
|
1732
|
+
recipientId: transferData.recipientId,
|
|
1733
|
+
fileName: transferData.fileName,
|
|
1734
|
+
filePath: transferData.filePath,
|
|
1735
|
+
fileSize: transferData.fileSize,
|
|
1736
|
+
totalChunks: transferData.totalChunks,
|
|
1737
|
+
firstChunkIndex: transferData.chunkIndex,
|
|
1738
|
+
lastChunkIndex: transferData.chunkIndex,
|
|
1739
|
+
completedChunks: transferData.completedChunks,
|
|
1740
|
+
tideChunkCount: 1,
|
|
1741
|
+
tideBytes: transferData.chunkSize,
|
|
1742
|
+
chunks: [{
|
|
1743
|
+
chunkIndex: transferData.chunkIndex,
|
|
1744
|
+
chunkSize: transferData.chunkSize,
|
|
1745
|
+
fileChunk: transferData.fileChunk
|
|
1746
|
+
}],
|
|
1747
|
+
metadata: transferData.metadata || {}
|
|
1748
|
+
};
|
|
1749
|
+
}
|
|
1750
|
+
if (!tide || !Array.isArray(tide.chunks) || tide.chunks.length <= 0) {
|
|
1751
|
+
throw new Error("Received an invalid or empty transfer Tide.");
|
|
1789
1752
|
}
|
|
1790
1753
|
const {
|
|
1754
|
+
transferId,
|
|
1791
1755
|
senderID,
|
|
1792
1756
|
recipientId,
|
|
1793
1757
|
fileName,
|
|
1794
|
-
fileChunk,
|
|
1795
|
-
fileSize,
|
|
1796
1758
|
filePath,
|
|
1797
|
-
|
|
1798
|
-
chunkSize,
|
|
1799
|
-
completedChunks,
|
|
1759
|
+
fileSize,
|
|
1800
1760
|
totalChunks,
|
|
1761
|
+
firstChunkIndex,
|
|
1762
|
+
lastChunkIndex,
|
|
1763
|
+
completedChunks,
|
|
1764
|
+
tideChunkCount,
|
|
1765
|
+
tideBytes,
|
|
1766
|
+
chunks,
|
|
1801
1767
|
metadata = {}
|
|
1802
|
-
} =
|
|
1803
|
-
|
|
1804
|
-
const
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
}
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
}
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
this.
|
|
1768
|
+
} = tide;
|
|
1769
|
+
let expectedChunkIndex = firstChunkIndex;
|
|
1770
|
+
for (const chunk of chunks) {
|
|
1771
|
+
if (chunk.chunkIndex !== expectedChunkIndex) {
|
|
1772
|
+
throw new Error(`Tide ordering violation for ${fileName}. Expected chunk ${expectedChunkIndex}, received ${chunk.chunkIndex}.`);
|
|
1773
|
+
}
|
|
1774
|
+
expectedChunkIndex++;
|
|
1775
|
+
}
|
|
1776
|
+
if (chunks[0].chunkIndex !== firstChunkIndex || chunks[chunks.length - 1].chunkIndex !== lastChunkIndex) {
|
|
1777
|
+
throw new Error(`Tide boundary mismatch for ${fileName}.`);
|
|
1778
|
+
}
|
|
1779
|
+
const recipientClient = FileTideAnchorClientManager.getOnlineClient(recipientId);
|
|
1780
|
+
const senderClient = FileTideAnchorClientManager.getOnlineClient(senderID);
|
|
1781
|
+
if (!recipientClient || !senderClient) {
|
|
1782
|
+
throw new Error(`Both sender ${senderID} and recipient ${recipientId} must be online for Tide routing.`);
|
|
1783
|
+
}
|
|
1784
|
+
_assertClassBrand(_FileTideAnchor_brand, this, _log).call(this, `[FileTide ~ Anchor Transporter] ~ Routing Tide ~ ${fileName} | chunks ${firstChunkIndex + 1}-${lastChunkIndex + 1} >> ${completedChunks} of ${totalChunks} to client (${recipientId})`);
|
|
1785
|
+
if (firstChunkIndex === 0) {
|
|
1786
|
+
this.anchor.emitToTide(recipientClient.tideID, "incoming-file", {
|
|
1787
|
+
transferId,
|
|
1821
1788
|
senderID,
|
|
1789
|
+
clientID: recipientId,
|
|
1822
1790
|
recipientId,
|
|
1823
1791
|
fileName,
|
|
1824
|
-
|
|
1792
|
+
totalChunks,
|
|
1793
|
+
chunkIndex: 0,
|
|
1794
|
+
chunkSize: chunks[0].chunkSize,
|
|
1795
|
+
path: filePath,
|
|
1796
|
+
filePath,
|
|
1797
|
+
fileSize,
|
|
1798
|
+
metadata
|
|
1825
1799
|
});
|
|
1826
|
-
tidalytics.track("tide:
|
|
1800
|
+
tidalytics.track("tide:incoming-file", {
|
|
1827
1801
|
value: 1,
|
|
1828
1802
|
tags: {
|
|
1829
|
-
"tide:
|
|
1803
|
+
"tide:incoming-file": "tide:incoming-file",
|
|
1830
1804
|
"tide": "tide",
|
|
1831
1805
|
recipientID: recipientId,
|
|
1832
1806
|
senderID,
|
|
@@ -1835,61 +1809,78 @@ class FileMessager {
|
|
|
1835
1809
|
fileName
|
|
1836
1810
|
},
|
|
1837
1811
|
metadata: {
|
|
1812
|
+
transferId,
|
|
1838
1813
|
recipientID: recipientId,
|
|
1839
1814
|
senderID,
|
|
1840
1815
|
path: filePath,
|
|
1841
1816
|
fileSize,
|
|
1842
1817
|
fileName,
|
|
1843
|
-
completedChunks,
|
|
1844
1818
|
totalChunks,
|
|
1845
|
-
chunkSize,
|
|
1819
|
+
chunkSize: chunks[0].chunkSize,
|
|
1846
1820
|
transferMetadata: metadata
|
|
1847
1821
|
}
|
|
1848
1822
|
});
|
|
1849
1823
|
this.onTideAction({
|
|
1850
|
-
tideActionID: "tide-
|
|
1824
|
+
tideActionID: "tide-incoming-file",
|
|
1851
1825
|
tideActionDate: Date.now(),
|
|
1852
1826
|
tideActionDetails: {
|
|
1827
|
+
transferId,
|
|
1853
1828
|
recipientID: recipientId,
|
|
1854
1829
|
senderID,
|
|
1855
1830
|
path: filePath,
|
|
1856
1831
|
fileSize,
|
|
1857
1832
|
fileName,
|
|
1858
|
-
completedChunks,
|
|
1859
1833
|
totalChunks,
|
|
1860
|
-
chunkSize,
|
|
1834
|
+
chunkSize: chunks[0].chunkSize,
|
|
1861
1835
|
transferMetadata: metadata
|
|
1862
1836
|
}
|
|
1863
1837
|
});
|
|
1864
|
-
console.log(`[FileTide ~ File Messager] ~ File transfer completed: ${fileName} from ${senderID} to ${recipientId}`);
|
|
1865
|
-
const tidingTransfers = this.currentTidingTransfers.get(senderID);
|
|
1866
|
-
if (tidingTransfers) {
|
|
1867
|
-
tidingTransfers.delete(senderID);
|
|
1868
|
-
}
|
|
1869
1838
|
}
|
|
1839
|
+
this.anchor.emitToTide(recipientClient.tideID, "transfer-progress", {
|
|
1840
|
+
tide
|
|
1841
|
+
});
|
|
1870
1842
|
} catch (error) {
|
|
1871
|
-
console.error(`[FileTide ~
|
|
1843
|
+
console.error(`[FileTide ~ Anchor Transporter] ~ `, error);
|
|
1872
1844
|
return;
|
|
1873
1845
|
}
|
|
1874
1846
|
}
|
|
1875
1847
|
handleClientTransferBarrierResponse(senderTide, data) {
|
|
1876
|
-
console.log(`[FileTide ~
|
|
1848
|
+
console.log(`[FileTide ~ Anchor] Checking ${data?.recipientID}'s transfer barrier for transfer ~ ${data?.transferID}...`);
|
|
1877
1849
|
try {
|
|
1878
|
-
|
|
1879
|
-
|
|
1850
|
+
if (!data || !data.clientID || !data.recipientID || !data.transferID) {
|
|
1851
|
+
console.log(`[FileTide ~ Anchor Barrier] ~ Invalid transfer barrier request.`);
|
|
1852
|
+
return;
|
|
1853
|
+
}
|
|
1854
|
+
const recipientDetails = FileTideAnchorClientManager.getOnlineClient(data.recipientID);
|
|
1855
|
+
const senderDetails = FileTideAnchorClientManager.getOnlineClient(data.clientID);
|
|
1856
|
+
if (!recipientDetails || !senderDetails) {
|
|
1857
|
+
console.log(!senderDetails ? `[FileTide ~ Anchor Barrier] ~ Sender ~ ${data.clientID} not online.` : `[FileTide ~ Anchor Barrier] ~ Recipient ~ ${data.recipientID} not online.`);
|
|
1858
|
+
const senderClient = senderDetails ? this.getClientFromID(senderDetails.id) : null;
|
|
1859
|
+
if (senderClient) {
|
|
1860
|
+
this.anchor.emitToTide(senderClient.tideID, "transfer-barrier-response", false);
|
|
1861
|
+
}
|
|
1862
|
+
this.currentTransferBarrierTransfers.delete(data.transferID);
|
|
1863
|
+
return;
|
|
1864
|
+
}
|
|
1865
|
+
const recipientConnectionID = recipientDetails.id;
|
|
1866
|
+
const senderConnectionID = senderDetails.id;
|
|
1880
1867
|
const senderClient = this.getClientFromID(senderConnectionID);
|
|
1881
1868
|
const client = this.getClientFromID(recipientConnectionID);
|
|
1882
1869
|
if (!client || !senderClient) {
|
|
1883
|
-
console.log(`[FileTide ~
|
|
1870
|
+
console.log(`[FileTide ~ Anchor Barrier] ~ Both recipient and sender connection authorization required.`);
|
|
1871
|
+
if (senderClient) {
|
|
1872
|
+
this.anchor.emitToTide(senderClient.tideID, "transfer-barrier-response", false);
|
|
1873
|
+
}
|
|
1874
|
+
this.currentTransferBarrierTransfers.delete(data.transferID);
|
|
1884
1875
|
return;
|
|
1885
1876
|
}
|
|
1886
|
-
this.
|
|
1877
|
+
this.anchor.emitToTide(client.tideID, "queue-incoming-transfer", {
|
|
1887
1878
|
...data,
|
|
1888
1879
|
transferType: "send"
|
|
1889
1880
|
});
|
|
1890
1881
|
this.transferQueue.waitForData(data.transferID, () => this.currentTransferBarrierTransfers.get(data.transferID), [true, false], 100, data.transferExpirationTime && typeof data.transferExpirationTime === "number" ? data.transferExpirationTime : 30000).then(accepted => {
|
|
1891
|
-
console.log(`[FileTide ~
|
|
1892
|
-
this.
|
|
1882
|
+
console.log(`[FileTide ~ Anchor Barrier] ~ Transfer ${accepted ? "accepted!" : "denied."}`);
|
|
1883
|
+
this.anchor.emitToTide(senderClient.tideID, "transfer-barrier-response", accepted);
|
|
1893
1884
|
this.currentTransferBarrierTransfers.delete(data.transferID);
|
|
1894
1885
|
if (accepted) {
|
|
1895
1886
|
tidalytics.track("tide-barrier:accepted", {
|
|
@@ -1932,7 +1923,7 @@ class FileMessager {
|
|
|
1932
1923
|
tideOriginPath: data.originPath
|
|
1933
1924
|
}
|
|
1934
1925
|
});
|
|
1935
|
-
this.
|
|
1926
|
+
this.anchor.emitToTide(client.tideID, "accepted-transfer", {
|
|
1936
1927
|
accepted,
|
|
1937
1928
|
...data
|
|
1938
1929
|
});
|
|
@@ -1978,48 +1969,168 @@ class FileMessager {
|
|
|
1978
1969
|
tideOriginPath: data.originPath
|
|
1979
1970
|
}
|
|
1980
1971
|
});
|
|
1981
|
-
this.
|
|
1972
|
+
this.anchor.emitToTide(client.tideID, "denied-transfer", {
|
|
1982
1973
|
accepted,
|
|
1983
1974
|
...data
|
|
1984
1975
|
});
|
|
1985
1976
|
}).catch(error => {
|
|
1986
|
-
|
|
1977
|
+
this.currentTransferBarrierTransfers.delete(data.transferID);
|
|
1978
|
+
console.error(`[FileTide ~ Anchor Barrier] ~ ${error.message}`);
|
|
1979
|
+
const currentSenderDetails = FileTideAnchorClientManager.getOnlineClient(data.clientID);
|
|
1980
|
+
const currentSenderClient = currentSenderDetails ? this.getClientFromID(currentSenderDetails.id) : null;
|
|
1981
|
+
if (currentSenderClient) {
|
|
1982
|
+
this.anchor.emitToTide(currentSenderClient.tideID, "transfer-barrier-response", false);
|
|
1983
|
+
}
|
|
1987
1984
|
});
|
|
1988
1985
|
return;
|
|
1989
1986
|
} catch (error) {
|
|
1990
|
-
|
|
1987
|
+
this.currentTransferBarrierTransfers.delete(data?.transferID);
|
|
1988
|
+
console.error(`[FileTide ~ Anchor Barrier] ~ `, error);
|
|
1991
1989
|
return;
|
|
1992
1990
|
}
|
|
1993
1991
|
}
|
|
1994
1992
|
handleGetClient(senderTide, data) {
|
|
1995
|
-
console.log(`[FileTide ~
|
|
1993
|
+
console.log(`[FileTide ~ Anchor] ~ Getting client ~ ${data.clientID}...`);
|
|
1996
1994
|
try {
|
|
1997
|
-
const senderConnectionID =
|
|
1998
|
-
const clientConnectionID =
|
|
1995
|
+
const senderConnectionID = FileTideAnchorClientManager.getOnlineClient(data.senderID).id;
|
|
1996
|
+
const clientConnectionID = FileTideAnchorClientManager.getOnlineClient(data.clientID).id;
|
|
1999
1997
|
const senderClient = this.getClientFromID(clientConnectionID);
|
|
2000
1998
|
const client = this.getClientFromID(clientConnectionID);
|
|
2001
1999
|
if (!client || !senderClient) {
|
|
2002
2000
|
return;
|
|
2003
2001
|
}
|
|
2004
|
-
console.log(`[FileTide ~
|
|
2005
|
-
this.
|
|
2002
|
+
console.log(`[FileTide ~ Anchor] Got client ~ ${data.clientID}!`);
|
|
2003
|
+
this.anchor.emitToTide(senderClient.tideID, "retrieved-current-client", client);
|
|
2006
2004
|
} catch (error) {
|
|
2007
|
-
console.error(`[FileTide ~
|
|
2005
|
+
console.error(`[FileTide ~ Anchor Activity] ~ `, error);
|
|
2008
2006
|
return;
|
|
2009
2007
|
}
|
|
2010
2008
|
}
|
|
2011
2009
|
handleAcknowledgeTransferTide(senderTide, data) {
|
|
2012
2010
|
try {
|
|
2013
|
-
const
|
|
2014
|
-
const
|
|
2015
|
-
const
|
|
2016
|
-
const
|
|
2017
|
-
const
|
|
2018
|
-
const
|
|
2011
|
+
const transferStats = data.transferStats || {};
|
|
2012
|
+
const transferETA = transferStats.timeLeft <= 0 ? "Now" : FileTideAnchorUtilityManager.convertSeconds(transferStats.timeLeft !== null && transferStats.timeLeft !== undefined ? transferStats.timeLeft.toFixed(2) : Infinity);
|
|
2013
|
+
const transferProgress = transferStats.progress !== null && transferStats.progress !== undefined ? transferStats.progress.toFixed(2) : "N/A";
|
|
2014
|
+
const currentTransferredSize = FileTideAnchorUtilityManager.getFormattedSize(transferStats.current, true);
|
|
2015
|
+
const transferSize = FileTideAnchorUtilityManager.getFormattedSize(transferStats.totalSize, true);
|
|
2016
|
+
const transferSpeed = FileTideAnchorUtilityManager.getFormattedSize(transferStats.speed, true);
|
|
2017
|
+
const transferStartTime = transferStats.startTime;
|
|
2019
2018
|
const transferMetadata = data.metadata;
|
|
2020
2019
|
const contentType = transferMetadata?.contentType ?? "file";
|
|
2021
2020
|
const fileName = data.fileName;
|
|
2022
|
-
|
|
2021
|
+
const throughputBps = Number(transferStats.speed);
|
|
2022
|
+
const senderDetails = data.senderName ? FileTideAnchorClientManager.getOnlineClient(data.senderName) : null;
|
|
2023
|
+
const recipientDetails = data.recipientName ? FileTideAnchorClientManager.getOnlineClient(data.recipientName) : null;
|
|
2024
|
+
const senderClient = senderDetails ? this.getClientFromID(senderDetails.id) : null;
|
|
2025
|
+
const recipientClient = recipientDetails ? this.getClientFromID(recipientDetails.id) : null;
|
|
2026
|
+
if (senderClient) {
|
|
2027
|
+
this.anchor.emitToTide(senderClient.tideID, "transfer-status", {
|
|
2028
|
+
transferId: data.transferId,
|
|
2029
|
+
senderName: data.senderName,
|
|
2030
|
+
senderID: data.senderName,
|
|
2031
|
+
recipientID: data.recipientName,
|
|
2032
|
+
recipientId: data.recipientName,
|
|
2033
|
+
success: true,
|
|
2034
|
+
fileName,
|
|
2035
|
+
fileSize: data.fileSize ?? transferStats.totalSize,
|
|
2036
|
+
path: data.path,
|
|
2037
|
+
filePath: data.path,
|
|
2038
|
+
totalChunks: data.totalChunks,
|
|
2039
|
+
completedChunks: data.completedChunks,
|
|
2040
|
+
firstChunkIndex: data.firstChunkIndex,
|
|
2041
|
+
lastChunkIndex: data.lastChunkIndex,
|
|
2042
|
+
chunkIndex: data.lastChunkIndex,
|
|
2043
|
+
chunkSize: data.chunkSize,
|
|
2044
|
+
tideChunkCount: data.tideChunkCount,
|
|
2045
|
+
tideBytes: data.tideBytes,
|
|
2046
|
+
highestContiguousChunk: data.highestContiguousChunk,
|
|
2047
|
+
missingChunks: Array.isArray(data.missingChunks) ? data.missingChunks : [],
|
|
2048
|
+
metadata: transferMetadata
|
|
2049
|
+
});
|
|
2050
|
+
}
|
|
2051
|
+
if (Number.isFinite(throughputBps) && throughputBps > 0 && senderClient) {
|
|
2052
|
+
this.anchor.emitToTide(senderClient.tideID, "tide-network-sample", {
|
|
2053
|
+
transferId: data.transferId,
|
|
2054
|
+
transferStateID: data.transferStateID,
|
|
2055
|
+
senderID: data.senderName,
|
|
2056
|
+
recipientID: data.recipientName,
|
|
2057
|
+
fileName,
|
|
2058
|
+
path: data.path,
|
|
2059
|
+
throughputBps,
|
|
2060
|
+
progress: transferStats.progress,
|
|
2061
|
+
transferredBytes: transferStats.current,
|
|
2062
|
+
totalBytes: transferStats.totalSize,
|
|
2063
|
+
firstChunkIndex: data.firstChunkIndex,
|
|
2064
|
+
lastChunkIndex: data.lastChunkIndex,
|
|
2065
|
+
highestContiguousChunk: data.highestContiguousChunk,
|
|
2066
|
+
tideChunkCount: data.tideChunkCount,
|
|
2067
|
+
tideBytes: data.tideBytes,
|
|
2068
|
+
sampledOn: Date.now()
|
|
2069
|
+
});
|
|
2070
|
+
}
|
|
2071
|
+
const missingChunks = Array.isArray(data.missingChunks) ? data.missingChunks : [];
|
|
2072
|
+
const receiverConfirmedComplete = Number.isInteger(data.totalChunks) && data.totalChunks > 0 && data.highestContiguousChunk === data.totalChunks - 1 && missingChunks.length === 0;
|
|
2073
|
+
if (receiverConfirmedComplete && senderClient && recipientClient) {
|
|
2074
|
+
const completionData = {
|
|
2075
|
+
transferId: data.transferId,
|
|
2076
|
+
senderID: data.senderName,
|
|
2077
|
+
recipientId: data.recipientName,
|
|
2078
|
+
fileName,
|
|
2079
|
+
filePath: data.path,
|
|
2080
|
+
completedChunks: data.completedChunks,
|
|
2081
|
+
totalChunks: data.totalChunks,
|
|
2082
|
+
highestContiguousChunk: data.highestContiguousChunk,
|
|
2083
|
+
metadata: transferMetadata
|
|
2084
|
+
};
|
|
2085
|
+
this.anchor.emitToTide(recipientClient.tideID, "transfer-complete", completionData);
|
|
2086
|
+
this.anchor.emitToTide(senderClient.tideID, "transfer-complete", completionData);
|
|
2087
|
+
tidalytics.track("tide:completed-transfer", {
|
|
2088
|
+
value: 1,
|
|
2089
|
+
tags: {
|
|
2090
|
+
"tide:completed-transfer": "tide:completed-transfer",
|
|
2091
|
+
"tide": "tide",
|
|
2092
|
+
recipientID: data.recipientName,
|
|
2093
|
+
senderID: data.senderName,
|
|
2094
|
+
path: data.path,
|
|
2095
|
+
fileName
|
|
2096
|
+
},
|
|
2097
|
+
metadata: {
|
|
2098
|
+
transferId: data.transferId,
|
|
2099
|
+
recipientID: data.recipientName,
|
|
2100
|
+
senderID: data.senderName,
|
|
2101
|
+
path: data.path,
|
|
2102
|
+
fileName,
|
|
2103
|
+
completedChunks: data.completedChunks,
|
|
2104
|
+
totalChunks: data.totalChunks,
|
|
2105
|
+
highestContiguousChunk: data.highestContiguousChunk,
|
|
2106
|
+
transferMetadata
|
|
2107
|
+
}
|
|
2108
|
+
});
|
|
2109
|
+
this.onTideAction({
|
|
2110
|
+
tideActionID: "tide-completed-transfer",
|
|
2111
|
+
tideActionDate: Date.now(),
|
|
2112
|
+
tideActionDetails: {
|
|
2113
|
+
transferId: data.transferId,
|
|
2114
|
+
recipientID: data.recipientName,
|
|
2115
|
+
senderID: data.senderName,
|
|
2116
|
+
path: data.path,
|
|
2117
|
+
fileName,
|
|
2118
|
+
completedChunks: data.completedChunks,
|
|
2119
|
+
totalChunks: data.totalChunks,
|
|
2120
|
+
highestContiguousChunk: data.highestContiguousChunk,
|
|
2121
|
+
transferMetadata
|
|
2122
|
+
}
|
|
2123
|
+
});
|
|
2124
|
+
console.log(`[FileTide ~ Anchor Transporter] ~ Receiver confirmed file transfer completion: ${fileName} from ${data.senderName} to ${data.recipientName}`);
|
|
2125
|
+
const tidingTransfers = this.currentTidingTransfers.get(data.senderName);
|
|
2126
|
+
if (tidingTransfers) {
|
|
2127
|
+
tidingTransfers.delete(data.recipientName);
|
|
2128
|
+
if (tidingTransfers.size <= 0) {
|
|
2129
|
+
this.currentTidingTransfers.delete(data.senderName);
|
|
2130
|
+
}
|
|
2131
|
+
}
|
|
2132
|
+
}
|
|
2133
|
+
console.log(`[FileTide ~ Anchor Activity] ~ ${data.recipientName} acknowledged Tide transfer from ${data.senderName}.\n\n\t~ [${fileName}-${transferStartTime}] ~\n\n\t\tFile Name ~ ${fileName}\n\t\tDestination ~ ${data.path}\n\n\t\t\tChunks ~ ${data.firstChunkIndex}-${data.lastChunkIndex}\n\t\t\tHighest Contiguous Chunk ~ ${data.highestContiguousChunk}\n\t\t\tProgress ~ ${transferProgress}%\n\t\t\tETA ~ ${transferETA}\n\t\t\tSpeed ~ ${transferSpeed}/s\n\t\t\tSize ~ ${transferSize}\n\t\t\tTransferred ~ ${currentTransferredSize}\n`);
|
|
2023
2134
|
tidalytics.track("tide:transfer-state", {
|
|
2024
2135
|
value: 1,
|
|
2025
2136
|
tags: {
|
|
@@ -2035,6 +2146,7 @@ class FileMessager {
|
|
|
2035
2146
|
fileName
|
|
2036
2147
|
},
|
|
2037
2148
|
metadata: {
|
|
2149
|
+
transferId: data.transferId,
|
|
2038
2150
|
transferStateID: data.transferStateID,
|
|
2039
2151
|
recipientID: data.recipientName,
|
|
2040
2152
|
senderID: data.senderName,
|
|
@@ -2042,9 +2154,16 @@ class FileMessager {
|
|
|
2042
2154
|
startTime: transferStartTime,
|
|
2043
2155
|
currentTransferredSize,
|
|
2044
2156
|
speed: transferSpeed,
|
|
2157
|
+
throughputBps,
|
|
2045
2158
|
transferProgress,
|
|
2046
2159
|
transferSize,
|
|
2047
2160
|
transferETA,
|
|
2161
|
+
firstChunkIndex: data.firstChunkIndex,
|
|
2162
|
+
lastChunkIndex: data.lastChunkIndex,
|
|
2163
|
+
highestContiguousChunk: data.highestContiguousChunk,
|
|
2164
|
+
tideChunkCount: data.tideChunkCount,
|
|
2165
|
+
tideBytes: data.tideBytes,
|
|
2166
|
+
missingChunks,
|
|
2048
2167
|
fileName,
|
|
2049
2168
|
transferMetadata
|
|
2050
2169
|
}
|
|
@@ -2053,6 +2172,7 @@ class FileMessager {
|
|
|
2053
2172
|
tideActionID: "tide-transfer-state",
|
|
2054
2173
|
tideActionDate: Date.now(),
|
|
2055
2174
|
tideActionDetails: {
|
|
2175
|
+
transferId: data.transferId,
|
|
2056
2176
|
transferStateID: data.transferStateID,
|
|
2057
2177
|
recipientID: data.recipientName,
|
|
2058
2178
|
senderID: data.senderName,
|
|
@@ -2060,16 +2180,23 @@ class FileMessager {
|
|
|
2060
2180
|
startTime: transferStartTime,
|
|
2061
2181
|
currentTransferredSize,
|
|
2062
2182
|
speed: transferSpeed,
|
|
2183
|
+
throughputBps,
|
|
2063
2184
|
transferProgress,
|
|
2064
2185
|
transferSize,
|
|
2065
2186
|
transferETA,
|
|
2187
|
+
firstChunkIndex: data.firstChunkIndex,
|
|
2188
|
+
lastChunkIndex: data.lastChunkIndex,
|
|
2189
|
+
highestContiguousChunk: data.highestContiguousChunk,
|
|
2190
|
+
tideChunkCount: data.tideChunkCount,
|
|
2191
|
+
tideBytes: data.tideBytes,
|
|
2192
|
+
missingChunks,
|
|
2066
2193
|
contentType,
|
|
2067
2194
|
fileName,
|
|
2068
2195
|
transferMetadata
|
|
2069
2196
|
}
|
|
2070
2197
|
});
|
|
2071
2198
|
} catch (error) {
|
|
2072
|
-
console.error(`[FileTide ~
|
|
2199
|
+
console.error(`[FileTide ~ Anchor Activity] ~ ${data.recipientName} acknowledged Tide transfer from ${data.senderName}.\n\n${error}`);
|
|
2073
2200
|
}
|
|
2074
2201
|
}
|
|
2075
2202
|
handleNotifyTransferBarrier(senderTide, data, emitToChannel) {
|
|
@@ -2078,17 +2205,17 @@ class FileMessager {
|
|
|
2078
2205
|
this.currentTransferBarrierTransfers.set(transferID, accepted);
|
|
2079
2206
|
}
|
|
2080
2207
|
handleFileTransferStart(senderTide, data, emitToChannel) {
|
|
2081
|
-
console.log(`[FileTide ~
|
|
2208
|
+
console.log(`[FileTide ~ Anchor Transporter] ~ Alerting client of incoming transfer from ${data.senderID}...`);
|
|
2082
2209
|
try {
|
|
2083
|
-
const recipientConnectionID =
|
|
2084
|
-
const senderConnectionID =
|
|
2210
|
+
const recipientConnectionID = FileTideAnchorClientManager.getOnlineClient(data.recipientID).id;
|
|
2211
|
+
const senderConnectionID = FileTideAnchorClientManager.getOnlineClient(data.senderID).id;
|
|
2085
2212
|
const senderClient = this.getClientFromID(senderConnectionID);
|
|
2086
2213
|
const client = this.getClientFromID(recipientConnectionID);
|
|
2087
2214
|
if (!client || !senderClient) {
|
|
2088
2215
|
return;
|
|
2089
2216
|
}
|
|
2090
|
-
this.
|
|
2091
|
-
this.
|
|
2217
|
+
this.anchor.emitToTide(client.tideID, "incoming-transfer", data);
|
|
2218
|
+
this.anchor.emitToTide(senderClient.tideID, "incoming-transfer", {
|
|
2092
2219
|
...data,
|
|
2093
2220
|
currentSender: data.senderID
|
|
2094
2221
|
});
|
|
@@ -2144,7 +2271,7 @@ class FileMessager {
|
|
|
2144
2271
|
path: data.path
|
|
2145
2272
|
});
|
|
2146
2273
|
} catch (error) {
|
|
2147
|
-
console.error(`[FileTide ~
|
|
2274
|
+
console.error(`[FileTide ~ Anchor Transfers] ~ `, error);
|
|
2148
2275
|
return;
|
|
2149
2276
|
}
|
|
2150
2277
|
}
|
|
@@ -2154,13 +2281,86 @@ class FileMessager {
|
|
|
2154
2281
|
handleFileTransferComplete(senderTide, data) {
|
|
2155
2282
|
console.log(`File transfer completed: ${data.fileName}`);
|
|
2156
2283
|
}
|
|
2284
|
+
handleFileTransferFailed(senderTide, data) {
|
|
2285
|
+
try {
|
|
2286
|
+
const {
|
|
2287
|
+
transferId,
|
|
2288
|
+
senderID,
|
|
2289
|
+
recipientId,
|
|
2290
|
+
fileName,
|
|
2291
|
+
filePath,
|
|
2292
|
+
reason,
|
|
2293
|
+
metadata = {}
|
|
2294
|
+
} = data;
|
|
2295
|
+
const recipientClient = FileTideAnchorClientManager.getOnlineClient(recipientId);
|
|
2296
|
+
const senderClient = FileTideAnchorClientManager.getOnlineClient(senderID);
|
|
2297
|
+
const failureData = {
|
|
2298
|
+
transferId,
|
|
2299
|
+
senderID,
|
|
2300
|
+
recipientId,
|
|
2301
|
+
fileName,
|
|
2302
|
+
filePath,
|
|
2303
|
+
reason,
|
|
2304
|
+
metadata
|
|
2305
|
+
};
|
|
2306
|
+
if (recipientClient) {
|
|
2307
|
+
this.anchor.emitToTide(recipientClient.tideID, "transfer-failed", failureData);
|
|
2308
|
+
}
|
|
2309
|
+
if (senderClient) {
|
|
2310
|
+
this.anchor.emitToTide(senderClient.tideID, "transfer-failed", failureData);
|
|
2311
|
+
}
|
|
2312
|
+
const tidingTransfers = this.currentTidingTransfers.get(senderID);
|
|
2313
|
+
if (tidingTransfers) {
|
|
2314
|
+
tidingTransfers.delete(recipientId);
|
|
2315
|
+
if (tidingTransfers.size <= 0) {
|
|
2316
|
+
this.currentTidingTransfers.delete(senderID);
|
|
2317
|
+
}
|
|
2318
|
+
}
|
|
2319
|
+
tidalytics.track("tide:failed-transfer", {
|
|
2320
|
+
value: 1,
|
|
2321
|
+
tags: {
|
|
2322
|
+
"tide:failed-transfer": "tide:failed-transfer",
|
|
2323
|
+
"tide": "tide",
|
|
2324
|
+
recipientID: recipientId,
|
|
2325
|
+
senderID,
|
|
2326
|
+
path: filePath,
|
|
2327
|
+
fileName
|
|
2328
|
+
},
|
|
2329
|
+
metadata: {
|
|
2330
|
+
transferId,
|
|
2331
|
+
recipientID: recipientId,
|
|
2332
|
+
senderID,
|
|
2333
|
+
path: filePath,
|
|
2334
|
+
fileName,
|
|
2335
|
+
reason,
|
|
2336
|
+
transferMetadata: metadata
|
|
2337
|
+
}
|
|
2338
|
+
});
|
|
2339
|
+
this.onTideAction({
|
|
2340
|
+
tideActionID: "tide-failed-transfer",
|
|
2341
|
+
tideActionDate: Date.now(),
|
|
2342
|
+
tideActionDetails: {
|
|
2343
|
+
transferId,
|
|
2344
|
+
recipientID: recipientId,
|
|
2345
|
+
senderID,
|
|
2346
|
+
path: filePath,
|
|
2347
|
+
fileName,
|
|
2348
|
+
reason,
|
|
2349
|
+
transferMetadata: metadata
|
|
2350
|
+
}
|
|
2351
|
+
});
|
|
2352
|
+
console.error(`[FileTide ~ Anchor Transporter] ~ File transfer failed: ${fileName} from ${senderID} to ${recipientId} ~ ${reason}`);
|
|
2353
|
+
} catch (error) {
|
|
2354
|
+
console.error(`[FileTide ~ Anchor Transfers] ~ Did not process failed transfer ~`, error);
|
|
2355
|
+
}
|
|
2356
|
+
}
|
|
2157
2357
|
async handleCheckClientBanned(senderTide, data) {
|
|
2158
|
-
console.log(`[FileTide ~
|
|
2358
|
+
console.log(`[FileTide ~ Anchor Activity] ~ Checking if client ~ ${data.clientID} banned...`);
|
|
2159
2359
|
try {
|
|
2160
2360
|
const clientBanned = await this.clientBanned(data.tideID);
|
|
2161
2361
|
if (!clientBanned) {
|
|
2162
|
-
console.log(`[FileTide ~
|
|
2163
|
-
this.
|
|
2362
|
+
console.log(`[FileTide ~ Anchor Activity] ~ Client ~ ${data.clientID} access authorized!`);
|
|
2363
|
+
this.anchor.emit("retrieved-client-banned", {
|
|
2164
2364
|
banned: false,
|
|
2165
2365
|
clientID: data.clientID,
|
|
2166
2366
|
tideID: data.tideID,
|
|
@@ -2168,18 +2368,18 @@ class FileMessager {
|
|
|
2168
2368
|
});
|
|
2169
2369
|
return;
|
|
2170
2370
|
}
|
|
2171
|
-
console.log(`[FileTide ~
|
|
2371
|
+
console.log(`[FileTide ~ Anchor Activity] ~ Client ~ ${data.clientID} banned.`);
|
|
2172
2372
|
const bannedClientDetails = await this.getBanEntry(data.tideID);
|
|
2173
|
-
|
|
2373
|
+
FileTideAnchorClientManager.clearOnlineClient(data.clientID);
|
|
2174
2374
|
this.saveClientTransferStates(data);
|
|
2175
|
-
this.
|
|
2375
|
+
this.anchor.emit("retrieved-client-banned", {
|
|
2176
2376
|
banned: true,
|
|
2177
2377
|
clientID: data.clientID,
|
|
2178
2378
|
tideID: data.tideID,
|
|
2179
2379
|
bannedDetails: bannedClientDetails
|
|
2180
2380
|
});
|
|
2181
2381
|
} catch (error) {
|
|
2182
|
-
this.
|
|
2382
|
+
this.anchor.emit("retrieved-client-banned", {
|
|
2183
2383
|
banned: false,
|
|
2184
2384
|
clientID: data.clientID,
|
|
2185
2385
|
tideID: data.tideID,
|
|
@@ -2189,23 +2389,23 @@ class FileMessager {
|
|
|
2189
2389
|
}
|
|
2190
2390
|
}
|
|
2191
2391
|
handleCheckClientOnline(senderTide, data) {
|
|
2192
|
-
console.log(`[FileTide ~
|
|
2392
|
+
console.log(`[FileTide ~ Anchor Activity] ~ Checking if client ~ ${data.clientID} online...`);
|
|
2193
2393
|
try {
|
|
2194
|
-
const client =
|
|
2394
|
+
const client = FileTideAnchorClientManager.getOnlineClient(data.clientID);
|
|
2195
2395
|
if (!client) {
|
|
2196
|
-
this.
|
|
2396
|
+
this.anchor.emit("retrieved-client-online", {
|
|
2197
2397
|
online: false,
|
|
2198
2398
|
client: null
|
|
2199
2399
|
});
|
|
2200
2400
|
return;
|
|
2201
2401
|
}
|
|
2202
|
-
console.log(`[FileTide ~
|
|
2203
|
-
this.
|
|
2402
|
+
console.log(`[FileTide ~ Anchor Activity] ~ Client ~ ${data.clientID} online!`);
|
|
2403
|
+
this.anchor.emit("retrieved-client-online", {
|
|
2204
2404
|
online: true,
|
|
2205
2405
|
client
|
|
2206
2406
|
});
|
|
2207
2407
|
} catch (error) {
|
|
2208
|
-
this.
|
|
2408
|
+
this.anchor.emit("retrieved-client-online", {
|
|
2209
2409
|
online: false,
|
|
2210
2410
|
client: null
|
|
2211
2411
|
});
|
|
@@ -2213,28 +2413,28 @@ class FileMessager {
|
|
|
2213
2413
|
}
|
|
2214
2414
|
}
|
|
2215
2415
|
handleClientsOnline(senderTide, clientID) {
|
|
2216
|
-
const connectionDetails =
|
|
2416
|
+
const connectionDetails = FileTideAnchorClientManager.getOnlineClient(clientID);
|
|
2217
2417
|
if (!connectionDetails) {
|
|
2218
|
-
console.log(`[FileTide ~
|
|
2418
|
+
console.log(`[FileTide ~ Anchor Activity] ~ Client ~ ${clientID} not authorized.`);
|
|
2219
2419
|
return;
|
|
2220
2420
|
}
|
|
2221
2421
|
const client = this.onlineClients.get(connectionDetails.id);
|
|
2222
2422
|
if (!client) {
|
|
2223
|
-
console.log(`[FileTide ~
|
|
2423
|
+
console.log(`[FileTide ~ Anchor Activity] ~ Client ~ ${clientID} not found.`);
|
|
2224
2424
|
return;
|
|
2225
2425
|
}
|
|
2226
|
-
this.
|
|
2426
|
+
this.anchor.emitToTide(connectionDetails.tideID, "current-online-clients", Object.fromEntries(FileTideAnchorClientManager.getOnlineClients()));
|
|
2227
2427
|
return;
|
|
2228
2428
|
}
|
|
2229
2429
|
handleClientOnline(senderTide, clientID, tideID, pClientID, connectionID, activeTransferBarrier, originClientID, currentTideChannel) {
|
|
2230
2430
|
if (!this.onlineClients.contains(connectionID)) {
|
|
2231
2431
|
return;
|
|
2232
2432
|
}
|
|
2233
|
-
if (
|
|
2433
|
+
if (FileTideAnchorClientManager.getOnlineClient(clientID) && this.onlineClients.get(connectionID)) {
|
|
2234
2434
|
const nClientID = `${clientID}_${connectionID.slice(0, 4)}`;
|
|
2235
2435
|
const currentClientID = clientID;
|
|
2236
2436
|
clientID = nClientID;
|
|
2237
|
-
this.
|
|
2437
|
+
this.anchor.emitToTide(tideID, "current-client-id-already-online", clientID);
|
|
2238
2438
|
tidalytics.track("tider:already-online", {
|
|
2239
2439
|
value: 1,
|
|
2240
2440
|
tags: {
|
|
@@ -2269,7 +2469,7 @@ class FileMessager {
|
|
|
2269
2469
|
connectedOn: Date.now()
|
|
2270
2470
|
}
|
|
2271
2471
|
});
|
|
2272
|
-
|
|
2472
|
+
FileTideAnchorClientManager.updateOnlineClient(nClientID, {
|
|
2273
2473
|
pClientID: currentClientID,
|
|
2274
2474
|
clientID: nClientID,
|
|
2275
2475
|
tideID: senderTide.tideID,
|
|
@@ -2312,7 +2512,7 @@ class FileMessager {
|
|
|
2312
2512
|
tideID
|
|
2313
2513
|
}
|
|
2314
2514
|
});
|
|
2315
|
-
|
|
2515
|
+
FileTideAnchorClientManager.addOnlineClient(clientID, pClientID, tideID, connectionID, {
|
|
2316
2516
|
connectedOn: Date.now(),
|
|
2317
2517
|
currentTideChannel: currentTideChannel || "file-room",
|
|
2318
2518
|
originClientID
|
|
@@ -2321,17 +2521,17 @@ class FileMessager {
|
|
|
2321
2521
|
clientID,
|
|
2322
2522
|
activeTransferBarrier
|
|
2323
2523
|
});
|
|
2324
|
-
const currentOnlineClients = Object.fromEntries(
|
|
2325
|
-
this.
|
|
2326
|
-
this.
|
|
2524
|
+
const currentOnlineClients = Object.fromEntries(FileTideAnchorClientManager.getOnlineClients());
|
|
2525
|
+
this.anchor.emit("current-online-clients", currentOnlineClients);
|
|
2526
|
+
this.anchor.emit("current-clients", currentOnlineClients);
|
|
2327
2527
|
return;
|
|
2328
2528
|
}
|
|
2329
2529
|
handleClientOffline(senderTide, clientData) {
|
|
2330
|
-
console.log(`[FileTide ~
|
|
2530
|
+
console.log(`[FileTide ~ Anchor Activity] ~ Client ~ ${clientData.clientID} | connection origin ~ ${clientData.connectionID} going offline...`);
|
|
2331
2531
|
try {
|
|
2332
|
-
const clientDetails =
|
|
2532
|
+
const clientDetails = FileTideAnchorClientManager.getOnlineClient(clientData.clientID);
|
|
2333
2533
|
if (!clientDetails || clientDetails.id !== clientData.connectionID) {
|
|
2334
|
-
console.log(!clientDetails ? `[FileTide ~
|
|
2534
|
+
console.log(!clientDetails ? `[FileTide ~ Anchor Activity] ~ Client ~ ${clientData.clientID} already offline.` : `[FileTide ~ Anchor Activity] ~ Unauthorized offline signal from connection ID ~ ${clientData.connectionID}.`);
|
|
2335
2535
|
return;
|
|
2336
2536
|
}
|
|
2337
2537
|
tidalytics.track("tider:offline", {
|
|
@@ -2366,29 +2566,29 @@ class FileMessager {
|
|
|
2366
2566
|
connectedOn: clientDetails.connectedOn
|
|
2367
2567
|
}
|
|
2368
2568
|
});
|
|
2369
|
-
|
|
2370
|
-
const currentOnlineClients = Object.fromEntries(
|
|
2371
|
-
this.
|
|
2372
|
-
this.
|
|
2569
|
+
FileTideAnchorClientManager.clearOnlineClient(clientData.clientID);
|
|
2570
|
+
const currentOnlineClients = Object.fromEntries(FileTideAnchorClientManager.getOnlineClients());
|
|
2571
|
+
this.anchor.emit("current-online-clients", currentOnlineClients);
|
|
2572
|
+
this.anchor.emit("current-clients", currentOnlineClients);
|
|
2373
2573
|
} catch (error) {
|
|
2374
|
-
console.log(`[FileTide ~
|
|
2574
|
+
console.log(`[FileTide ~ Anchor Activity] ~ Did not process client ~ ${clientData} offline signal ~ ${error}`);
|
|
2375
2575
|
}
|
|
2376
2576
|
return;
|
|
2377
2577
|
}
|
|
2378
2578
|
handleClientTiding(senderTide, data) {
|
|
2379
2579
|
try {
|
|
2380
|
-
const senderConnectionID =
|
|
2580
|
+
const senderConnectionID = FileTideAnchorClientManager.getOnlineClient(data.senderID).id;
|
|
2381
2581
|
const senderClient = this.getClientFromID(senderConnectionID);
|
|
2382
2582
|
if (!senderClient) {
|
|
2383
2583
|
return;
|
|
2384
2584
|
}
|
|
2385
|
-
console.log(`[FileTide ~
|
|
2386
|
-
this.
|
|
2585
|
+
console.log(`[FileTide ~ Anchor Activity] ~ Received client ~ ${data.senderID} tiding.`);
|
|
2586
|
+
this.anchor.emitToTide(senderClient.tideID, "current-client-tiding", {
|
|
2387
2587
|
message: data.message
|
|
2388
2588
|
});
|
|
2389
2589
|
return;
|
|
2390
2590
|
} catch (error) {
|
|
2391
|
-
console.error(`[FileTide ~
|
|
2591
|
+
console.error(`[FileTide ~ Anchor Activity] ~ `, error);
|
|
2392
2592
|
return;
|
|
2393
2593
|
}
|
|
2394
2594
|
}
|
|
@@ -2415,4 +2615,4 @@ function _getTidalyticsRangeFetcher(interval, rangeMode, start, end) {
|
|
|
2415
2615
|
};
|
|
2416
2616
|
}
|
|
2417
2617
|
;
|
|
2418
|
-
module.exports =
|
|
2618
|
+
module.exports = FileTideAnchor;
|