amule-ec-client 0.5.2 → 0.6.1
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/README.md +4 -0
- package/dist/AddLinkRequest-D2IME4eb.js +15 -0
- package/dist/ClientQueueRequest-DFfCiNcz.js +15 -0
- package/dist/ClientQueueResponse-JTrBqrr1.js +63 -0
- package/dist/Codes-CjiW7Pdl.js +409 -0
- package/dist/CreateCategoryRequest-CRUMcPo5.js +22 -0
- package/dist/DeleteCategoryRequest-C8v9oGZ-.js +15 -0
- package/dist/DownloadCommandRequest-B3KV_bvm.js +29 -0
- package/dist/DownloadFileRequest-BjrroO3h.js +18 -0
- package/dist/DownloadQueueRequest-Dil5hl3D.js +15 -0
- package/dist/DownloadQueueResponse-DUam_zNf.js +259 -0
- package/dist/GetPreferencesRequest-DsxlghqT.js +16 -0
- package/dist/PreferencesDetailsResponse-DapscVQi.js +94 -0
- package/dist/PreferencesResponse-8n1STWUZ.js +37 -0
- package/dist/ReloadSharedFilesRequest-kt0Pxs8A.js +13 -0
- package/dist/Request-C0UUuQIX.js +158 -0
- package/dist/SearchProgressResponse-C1CdzKnz.js +15 -0
- package/dist/SearchRequest-DQnKfA5Z.js +55 -0
- package/dist/SearchResultsRequest-2ejFGQmQ.js +13 -0
- package/dist/SearchResultsResponse-DwmvbQop.js +29 -0
- package/dist/SearchStatusRequest-B_xr4-72.js +13 -0
- package/dist/SearchStopRequest-8hwXobty.js +13 -0
- package/dist/ServerConnectRequest-BhNpGiEJ.js +18 -0
- package/dist/ServerDisconnectRequest-BjCitLtU.js +13 -0
- package/dist/ServerListRequest-BWXLGJib.js +13 -0
- package/dist/ServerListResponse-BUJ7sz5p.js +50 -0
- package/dist/ServerUpdateFromUrlRequest-K8C_d0UQ.js +12 -0
- package/dist/SetFileCategoryRequest-VwroLBTV.js +15 -0
- package/dist/SetPreferencesRequest-KZ23VaBY.js +64 -0
- package/dist/SharedFilePriorityRequest-7BriqAcr.js +13 -0
- package/dist/SharedFilesRequest-B72XyRcA.js +15 -0
- package/dist/SharedFilesResponse-CkqvYd3N.js +39 -0
- package/dist/StatsRequest-CGGumOOx.js +15 -0
- package/dist/StatsResponse-DxQk686g.js +76 -0
- package/dist/Tag-CZF6BRMY.js +260 -0
- package/dist/UpdateCategoryRequest-CzKJa_rC.js +22 -0
- package/dist/UpdateRequest-g2ReOQ5m.js +15 -0
- package/dist/UpdateResponse-CGwVjn0Y.js +45 -0
- package/dist/download-details-OM0FJUhZ.js +10 -0
- package/dist/index.d.ts +1042 -933
- package/dist/index.js +1041 -3123
- package/dist/utils-DBnUQnZ-.js +24 -0
- package/package.json +5 -5
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import "./Codes-CjiW7Pdl.js";
|
|
2
|
+
import { f as findNumericTag, p as findTag } from "./Tag-CZF6BRMY.js";
|
|
3
|
+
//#region src/response/SearchResultsResponse.ts
|
|
4
|
+
var SearchResultsResponseParser = class {
|
|
5
|
+
static fromPacket(packet) {
|
|
6
|
+
const files = [];
|
|
7
|
+
const searchFileTags = packet.tags.filter((tag) => tag.name === 1792);
|
|
8
|
+
for (const fileTag of searchFileTags) {
|
|
9
|
+
const nestedTags = fileTag.nestedTags || [];
|
|
10
|
+
const fileNameTag = findTag(nestedTags, 769);
|
|
11
|
+
const hashTag = findTag(nestedTags, 798);
|
|
12
|
+
const sizeTag = findNumericTag(nestedTags, 771);
|
|
13
|
+
const sourceCountTag = findNumericTag(nestedTags, 778);
|
|
14
|
+
const completeSourcesTag = findNumericTag(nestedTags, 781);
|
|
15
|
+
const downloadStatusTag = findNumericTag(nestedTags, 776);
|
|
16
|
+
if (fileNameTag && hashTag) files.push({
|
|
17
|
+
fileName: fileNameTag.getValue(),
|
|
18
|
+
hash: hashTag.getValue(),
|
|
19
|
+
sizeFull: sizeTag ? Number(sizeTag.getLong()) : 0,
|
|
20
|
+
downloadStatus: downloadStatusTag ? downloadStatusTag.getInt() : 0,
|
|
21
|
+
completeSourceCount: completeSourcesTag ? completeSourcesTag.getInt() : 0,
|
|
22
|
+
sourceCount: sourceCountTag ? sourceCountTag.getInt() : 0
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return { files };
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
//#endregion
|
|
29
|
+
export { SearchResultsResponseParser };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { t as Request } from "./Request-C0UUuQIX.js";
|
|
2
|
+
import "./Codes-CjiW7Pdl.js";
|
|
3
|
+
//#region src/request/SearchStatusRequest.ts
|
|
4
|
+
/**
|
|
5
|
+
* Search Status Request - Get search progress
|
|
6
|
+
*/
|
|
7
|
+
var SearchStatusRequest = class extends Request {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(41);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { SearchStatusRequest };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { t as Request } from "./Request-C0UUuQIX.js";
|
|
2
|
+
import "./Codes-CjiW7Pdl.js";
|
|
3
|
+
//#region src/request/SearchStopRequest.ts
|
|
4
|
+
/**
|
|
5
|
+
* Search Stop Request - Stop current search
|
|
6
|
+
*/
|
|
7
|
+
var SearchStopRequest = class extends Request {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(39);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { SearchStopRequest };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { t as Request } from "./Request-C0UUuQIX.js";
|
|
2
|
+
import "./Codes-CjiW7Pdl.js";
|
|
3
|
+
import { i as Ipv4Tag } from "./Tag-CZF6BRMY.js";
|
|
4
|
+
//#region src/request/ServerConnectRequest.ts
|
|
5
|
+
/**
|
|
6
|
+
* Server Connect Request - Connect to a specific server
|
|
7
|
+
*/
|
|
8
|
+
var ServerConnectRequest = class extends Request {
|
|
9
|
+
constructor(ip, port) {
|
|
10
|
+
super(47);
|
|
11
|
+
if (ip && port) this.addTag(new Ipv4Tag(1280, {
|
|
12
|
+
address: ip,
|
|
13
|
+
port
|
|
14
|
+
}));
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { ServerConnectRequest };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { t as Request } from "./Request-C0UUuQIX.js";
|
|
2
|
+
import "./Codes-CjiW7Pdl.js";
|
|
3
|
+
//#region src/request/ServerDisconnectRequest.ts
|
|
4
|
+
/**
|
|
5
|
+
* Server Disconnect Request - Disconnect from the current server
|
|
6
|
+
*/
|
|
7
|
+
var ServerDisconnectRequest = class extends Request {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(46);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { ServerDisconnectRequest };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { t as Request } from "./Request-C0UUuQIX.js";
|
|
2
|
+
import "./Codes-CjiW7Pdl.js";
|
|
3
|
+
//#region src/request/ServerListRequest.ts
|
|
4
|
+
/**
|
|
5
|
+
* Server List Request - Request the list of servers
|
|
6
|
+
*/
|
|
7
|
+
var ServerListRequest = class extends Request {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(44);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { ServerListRequest };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import "./Codes-CjiW7Pdl.js";
|
|
2
|
+
import { f as findNumericTag, p as findTag } from "./Tag-CZF6BRMY.js";
|
|
3
|
+
import { n as toOptionalBool, t as formatIp } from "./utils-DBnUQnZ-.js";
|
|
4
|
+
//#region src/response/ServerListResponse.ts
|
|
5
|
+
var ServerListResponseParser = class {
|
|
6
|
+
static fromPacket(packet) {
|
|
7
|
+
return this.fromTags(packet.tags);
|
|
8
|
+
}
|
|
9
|
+
static fromTags(allTags) {
|
|
10
|
+
const servers = [];
|
|
11
|
+
const serverTags = allTags.filter((tag) => tag.name === 1280);
|
|
12
|
+
for (const serverTag of serverTags) {
|
|
13
|
+
const nested = serverTag.nestedTags || [];
|
|
14
|
+
const ipv4Tag = findTag(nested, 1292) || findTag(nested, 1283) || (serverTag.constructor.name.includes("Ipv4") ? serverTag : null);
|
|
15
|
+
let ip = void 0;
|
|
16
|
+
let port = void 0;
|
|
17
|
+
if (ipv4Tag && ipv4Tag.getValue() && typeof ipv4Tag.getValue() === "object" && "address" in ipv4Tag.getValue()) {
|
|
18
|
+
const val = ipv4Tag.getValue();
|
|
19
|
+
ip = val.address;
|
|
20
|
+
port = val.port;
|
|
21
|
+
} else {
|
|
22
|
+
const ipNum = findNumericTag(nested, 1292)?.getInt() || findNumericTag(allTags, 1292)?.getInt();
|
|
23
|
+
port = findNumericTag(nested, 1293)?.getInt() || findNumericTag(allTags, 1293)?.getInt();
|
|
24
|
+
ip = ipNum !== void 0 ? formatIp(ipNum) : void 0;
|
|
25
|
+
}
|
|
26
|
+
if (port === void 0 || port === 0) {
|
|
27
|
+
const extraPort = findNumericTag(nested, 1293)?.getInt();
|
|
28
|
+
if (extraPort !== void 0) port = extraPort;
|
|
29
|
+
}
|
|
30
|
+
servers.push({
|
|
31
|
+
name: findTag(nested, 1281)?.getValue(),
|
|
32
|
+
description: findTag(nested, 1282)?.getValue(),
|
|
33
|
+
address: findTag(nested, 1283)?.getValue(),
|
|
34
|
+
ip,
|
|
35
|
+
port,
|
|
36
|
+
ping: findNumericTag(nested, 1284)?.getInt(),
|
|
37
|
+
users: findNumericTag(nested, 1285)?.getInt(),
|
|
38
|
+
maxUsers: findNumericTag(nested, 1286)?.getInt(),
|
|
39
|
+
files: findNumericTag(nested, 1287)?.getInt(),
|
|
40
|
+
priority: findNumericTag(nested, 1288)?.getInt(),
|
|
41
|
+
version: findTag(nested, 1291)?.getValue(),
|
|
42
|
+
isStatic: toOptionalBool(findNumericTag(nested, 1290)?.getInt()),
|
|
43
|
+
failedCount: findNumericTag(nested, 1289)?.getInt()
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return { servers };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
//#endregion
|
|
50
|
+
export { ServerListResponseParser };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { t as Request } from "./Request-C0UUuQIX.js";
|
|
2
|
+
import "./Codes-CjiW7Pdl.js";
|
|
3
|
+
import { a as StringTag } from "./Tag-CZF6BRMY.js";
|
|
4
|
+
//#region src/request/ServerUpdateFromUrlRequest.ts
|
|
5
|
+
var ServerUpdateFromUrlRequest = class extends Request {
|
|
6
|
+
constructor(url) {
|
|
7
|
+
super(50);
|
|
8
|
+
this.addTag(new StringTag(5900, url));
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
//#endregion
|
|
12
|
+
export { ServerUpdateFromUrlRequest };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { t as Request } from "./Request-C0UUuQIX.js";
|
|
2
|
+
import "./Codes-CjiW7Pdl.js";
|
|
3
|
+
import { r as Hash16Tag, s as UByteTag } from "./Tag-CZF6BRMY.js";
|
|
4
|
+
//#region src/request/SetFileCategoryRequest.ts
|
|
5
|
+
/**
|
|
6
|
+
* Set File Category Request - Change category of a file
|
|
7
|
+
*/
|
|
8
|
+
var SetFileCategoryRequest = class extends Request {
|
|
9
|
+
constructor(hash, categoryId) {
|
|
10
|
+
super(30);
|
|
11
|
+
this.addTag(new Hash16Tag(768, hash, [new UByteTag(783, categoryId)]));
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
export { SetFileCategoryRequest };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { t as Request } from "./Request-C0UUuQIX.js";
|
|
2
|
+
import "./Codes-CjiW7Pdl.js";
|
|
3
|
+
import { a as StringTag, d as UShortTag, l as UIntTag, s as UByteTag } from "./Tag-CZF6BRMY.js";
|
|
4
|
+
//#region src/request/SetPreferencesRequest.ts
|
|
5
|
+
var SetPreferencesRequest = class SetPreferencesRequest extends Request {
|
|
6
|
+
constructor(prefs) {
|
|
7
|
+
super(64);
|
|
8
|
+
this.tags.push(...SetPreferencesRequest.buildTopLevelTags(prefs));
|
|
9
|
+
}
|
|
10
|
+
static buildTopLevelTags(prefs) {
|
|
11
|
+
const topTags = [];
|
|
12
|
+
if (prefs.general) {
|
|
13
|
+
const g = prefs.general;
|
|
14
|
+
topTags.push(new UByteTag(4608, 0, [new StringTag(4609, g.userNick), new UByteTag(4612, g.checkNewVersion ? 1 : 0)]));
|
|
15
|
+
}
|
|
16
|
+
if (prefs.connection) {
|
|
17
|
+
const c = prefs.connection;
|
|
18
|
+
topTags.push(new UByteTag(4864, 0, [
|
|
19
|
+
new UIntTag(4866, c.uploadCapacity),
|
|
20
|
+
new UIntTag(4865, c.downloadCapacity),
|
|
21
|
+
new UIntTag(4868, c.maxUploadSpeed),
|
|
22
|
+
new UIntTag(4867, c.maxDownloadSpeed),
|
|
23
|
+
new UIntTag(4869, c.slotAllocation),
|
|
24
|
+
new UShortTag(4870, c.tcpPort),
|
|
25
|
+
new UShortTag(4871, c.udpPort),
|
|
26
|
+
new UIntTag(4873, c.maxFileSources),
|
|
27
|
+
new UIntTag(4874, c.maxConnections),
|
|
28
|
+
new UByteTag(4875, c.autoconnect ? 1 : 0),
|
|
29
|
+
new UByteTag(4876, c.reconnect ? 1 : 0),
|
|
30
|
+
new UByteTag(4877, c.networkED2K ? 1 : 0),
|
|
31
|
+
new UByteTag(4878, c.networkKademlia ? 1 : 0)
|
|
32
|
+
]));
|
|
33
|
+
}
|
|
34
|
+
if (prefs.servers) {
|
|
35
|
+
const s = prefs.servers;
|
|
36
|
+
topTags.push(new UByteTag(5888, 0, [
|
|
37
|
+
new UByteTag(5889, s.removeDead ? 1 : 0),
|
|
38
|
+
new UShortTag(5890, s.deadRetries),
|
|
39
|
+
new UByteTag(5895, s.useScoreSystem ? 1 : 0),
|
|
40
|
+
new UByteTag(5896, s.smartIdCheck ? 1 : 0),
|
|
41
|
+
new StringTag(5900, s.updateUrl)
|
|
42
|
+
]));
|
|
43
|
+
}
|
|
44
|
+
if (prefs.security) {
|
|
45
|
+
const sec = prefs.security;
|
|
46
|
+
topTags.push(new UByteTag(7168, 0, [
|
|
47
|
+
new UByteTag(7169, sec.canSeeShares),
|
|
48
|
+
new UByteTag(7170, sec.ipFilterClients ? 1 : 0),
|
|
49
|
+
new UByteTag(7171, sec.ipFilterServers ? 1 : 0),
|
|
50
|
+
new UByteTag(7172, sec.ipFilterAutoUpdate ? 1 : 0),
|
|
51
|
+
new StringTag(7173, sec.ipFilterUpdateUrl),
|
|
52
|
+
new UByteTag(7174, sec.ipFilterLevel),
|
|
53
|
+
new UByteTag(7175, sec.filterLan ? 1 : 0),
|
|
54
|
+
new UByteTag(7176, sec.useSecIdent ? 1 : 0),
|
|
55
|
+
new UByteTag(7177, sec.obfuscationSupported ? 1 : 0),
|
|
56
|
+
new UByteTag(7178, sec.obfuscationRequested ? 1 : 0),
|
|
57
|
+
new UByteTag(7179, sec.obfuscationRequired ? 1 : 0)
|
|
58
|
+
]));
|
|
59
|
+
}
|
|
60
|
+
return topTags;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
//#endregion
|
|
64
|
+
export { SetPreferencesRequest };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { t as Request } from "./Request-C0UUuQIX.js";
|
|
2
|
+
import "./Codes-CjiW7Pdl.js";
|
|
3
|
+
import { l as UIntTag, r as Hash16Tag } from "./Tag-CZF6BRMY.js";
|
|
4
|
+
//#region src/request/SharedFilePriorityRequest.ts
|
|
5
|
+
var SharedFilePriorityRequest = class extends Request {
|
|
6
|
+
constructor(hash, priority) {
|
|
7
|
+
super(17);
|
|
8
|
+
this.addTag(new Hash16Tag(798, hash));
|
|
9
|
+
this.addTag(new UIntTag(1035, priority));
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { SharedFilePriorityRequest };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { t as Request } from "./Request-C0UUuQIX.js";
|
|
2
|
+
import "./Codes-CjiW7Pdl.js";
|
|
3
|
+
import { s as UByteTag } from "./Tag-CZF6BRMY.js";
|
|
4
|
+
//#region src/request/SharedFilesRequest.ts
|
|
5
|
+
/**
|
|
6
|
+
* Shared Files Request - Get shared files list
|
|
7
|
+
*/
|
|
8
|
+
var SharedFilesRequest = class extends Request {
|
|
9
|
+
constructor(detailLevel = 2) {
|
|
10
|
+
super(16);
|
|
11
|
+
this.addTag(new UByteTag(4, detailLevel));
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
export { SharedFilesRequest };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import "./Codes-CjiW7Pdl.js";
|
|
2
|
+
import { f as findNumericTag, p as findTag } from "./Tag-CZF6BRMY.js";
|
|
3
|
+
import { i as toOptionalNumber } from "./utils-DBnUQnZ-.js";
|
|
4
|
+
//#region src/response/SharedFilesResponse.ts
|
|
5
|
+
var SharedFilesResponseParser = class {
|
|
6
|
+
static fromPacket(packet) {
|
|
7
|
+
const files = [];
|
|
8
|
+
const knownfileTags = packet.tags.filter((tag) => tag.name === 1024);
|
|
9
|
+
for (const fileTag of knownfileTags) {
|
|
10
|
+
const tags = fileTag.nestedTags || [];
|
|
11
|
+
const hashTag = findTag(tags, 798);
|
|
12
|
+
const fileNameTag = findTag(tags, 769);
|
|
13
|
+
const file = {
|
|
14
|
+
fileHashHexString: hashTag ? hashTag.getValue().toString("hex") : void 0,
|
|
15
|
+
fileName: fileNameTag ? fileNameTag.getValue() : void 0,
|
|
16
|
+
filePath: findTag(tags, 1032)?.getValue(),
|
|
17
|
+
sizeFull: toOptionalNumber(findNumericTag(tags, 771)?.getLong()),
|
|
18
|
+
fileEd2kLink: findTag(tags, 782)?.getValue(),
|
|
19
|
+
upPrio: findNumericTag(tags, 1035)?.getInt(),
|
|
20
|
+
getRequests: findNumericTag(tags, 1027)?.getShort(),
|
|
21
|
+
getAllRequests: findNumericTag(tags, 1028)?.getInt(),
|
|
22
|
+
getAccepts: findNumericTag(tags, 1029)?.getShort(),
|
|
23
|
+
getAllAccepts: findNumericTag(tags, 1030)?.getInt(),
|
|
24
|
+
getXferred: toOptionalNumber(findNumericTag(tags, 1025)?.getLong()),
|
|
25
|
+
getAllXferred: toOptionalNumber(findNumericTag(tags, 1026)?.getLong()),
|
|
26
|
+
getCompleteSourcesLow: findNumericTag(tags, 1033)?.getShort(),
|
|
27
|
+
getCompleteSourcesHigh: findNumericTag(tags, 1034)?.getShort(),
|
|
28
|
+
getCompleteSources: findNumericTag(tags, 1037)?.getShort(),
|
|
29
|
+
getOnQueue: findNumericTag(tags, 1036)?.getShort(),
|
|
30
|
+
getComment: findTag(tags, 1038)?.getValue(),
|
|
31
|
+
getRating: findNumericTag(tags, 1039)?.getInt()
|
|
32
|
+
};
|
|
33
|
+
files.push(file);
|
|
34
|
+
}
|
|
35
|
+
return { files };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
//#endregion
|
|
39
|
+
export { SharedFilesResponseParser };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { t as Request } from "./Request-C0UUuQIX.js";
|
|
2
|
+
import "./Codes-CjiW7Pdl.js";
|
|
3
|
+
import { s as UByteTag } from "./Tag-CZF6BRMY.js";
|
|
4
|
+
//#region src/request/StatsRequest.ts
|
|
5
|
+
/**
|
|
6
|
+
* Stats Request - Request server statistics
|
|
7
|
+
*/
|
|
8
|
+
var StatsRequest = class extends Request {
|
|
9
|
+
constructor(detailLevel = 2) {
|
|
10
|
+
super(10);
|
|
11
|
+
this.addTag(new UByteTag(4, detailLevel));
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
export { StatsRequest };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import "./Codes-CjiW7Pdl.js";
|
|
2
|
+
import { f as findNumericTag, p as findTag } from "./Tag-CZF6BRMY.js";
|
|
3
|
+
//#region src/response/StatsResponse.ts
|
|
4
|
+
var StatsResponseParser = class {
|
|
5
|
+
static fromPacket(packet) {
|
|
6
|
+
const uploadOverhead = findNumericTag(packet.tags, 516)?.getValue() || 0;
|
|
7
|
+
const downloadOverhead = findNumericTag(packet.tags, 517)?.getValue() || 0;
|
|
8
|
+
const bannedCount = findNumericTag(packet.tags, 519)?.getValue() || 0;
|
|
9
|
+
const totalSentBytes = findNumericTag(packet.tags, 536)?.getValue() || 0;
|
|
10
|
+
const totalReceivedBytes = findNumericTag(packet.tags, 537)?.getValue() || 0;
|
|
11
|
+
const sharedFileCount = findNumericTag(packet.tags, 538)?.getValue() || 0;
|
|
12
|
+
const uploadSpeed = findNumericTag(packet.tags, 512)?.getValue() || 0;
|
|
13
|
+
const downloadSpeed = findNumericTag(packet.tags, 513)?.getValue() || 0;
|
|
14
|
+
const uploadSpeedLimit = findNumericTag(packet.tags, 514)?.getValue() || 0;
|
|
15
|
+
const downloadSpeedLimit = findNumericTag(packet.tags, 515)?.getValue() || 0;
|
|
16
|
+
const uploadQueueLength = findNumericTag(packet.tags, 520)?.getValue() || 0;
|
|
17
|
+
const totalSourceCount = findNumericTag(packet.tags, 518)?.getValue() || 0;
|
|
18
|
+
const ed2kUsers = findNumericTag(packet.tags, 521)?.getValue() || 0;
|
|
19
|
+
const kadUsers = findNumericTag(packet.tags, 522)?.getValue() || 0;
|
|
20
|
+
const ed2kFiles = findNumericTag(packet.tags, 523)?.getValue() || 0;
|
|
21
|
+
const kadFiles = findNumericTag(packet.tags, 524)?.getValue() || 0;
|
|
22
|
+
const kadNodes = findNumericTag(packet.tags, 539)?.getValue() || 0;
|
|
23
|
+
const connStateTag = findTag(packet.tags, 5);
|
|
24
|
+
let ed2kId = 0;
|
|
25
|
+
let clientId = 0;
|
|
26
|
+
let kadId;
|
|
27
|
+
let connectedServer;
|
|
28
|
+
if (connStateTag && connStateTag.nestedTags) {
|
|
29
|
+
ed2kId = Number(findNumericTag(connStateTag.nestedTags, 6)?.getValue() || 0);
|
|
30
|
+
clientId = Number(findNumericTag(connStateTag.nestedTags, 10)?.getValue() || 0);
|
|
31
|
+
const kadIdTag = findTag(connStateTag.nestedTags, 16);
|
|
32
|
+
if (kadIdTag && kadIdTag.getValue() !== void 0) {
|
|
33
|
+
const val = kadIdTag.getValue();
|
|
34
|
+
if (typeof val === "bigint") kadId = val.toString(16).padStart(32, "0");
|
|
35
|
+
else if (val instanceof Buffer) kadId = val.toString("hex");
|
|
36
|
+
}
|
|
37
|
+
const serverTag = findTag(connStateTag.nestedTags, 1280);
|
|
38
|
+
if (serverTag) {
|
|
39
|
+
const serverVal = serverTag.getValue();
|
|
40
|
+
if (serverVal && typeof serverVal === "object" && "address" in serverVal) connectedServer = {
|
|
41
|
+
ip: serverVal.address,
|
|
42
|
+
port: serverVal.port,
|
|
43
|
+
name: findTag(serverTag.nestedTags || [], 1281)?.getValue(),
|
|
44
|
+
description: findTag(serverTag.nestedTags || [], 1282)?.getValue()
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const id = clientId || Number(findNumericTag(packet.tags, 10)?.getValue() || 0);
|
|
49
|
+
return {
|
|
50
|
+
id: Number(id),
|
|
51
|
+
ed2kId,
|
|
52
|
+
kadId,
|
|
53
|
+
connectedServer,
|
|
54
|
+
uploadOverhead: Number(uploadOverhead),
|
|
55
|
+
downloadOverhead: Number(downloadOverhead),
|
|
56
|
+
bannedCount: Number(bannedCount),
|
|
57
|
+
loggerMessage: [],
|
|
58
|
+
totalSentBytes: Number(totalSentBytes),
|
|
59
|
+
totalReceivedBytes: Number(totalReceivedBytes),
|
|
60
|
+
sharedFileCount: Number(sharedFileCount),
|
|
61
|
+
uploadSpeed: Number(uploadSpeed),
|
|
62
|
+
downloadSpeed: Number(downloadSpeed),
|
|
63
|
+
uploadSpeedLimit: Number(uploadSpeedLimit),
|
|
64
|
+
downloadSpeedLimit: Number(downloadSpeedLimit),
|
|
65
|
+
uploadQueueLength: Number(uploadQueueLength),
|
|
66
|
+
totalSourceCount: Number(totalSourceCount),
|
|
67
|
+
ed2kUsers: Number(ed2kUsers),
|
|
68
|
+
kadUsers: Number(kadUsers),
|
|
69
|
+
ed2kFiles: Number(ed2kFiles),
|
|
70
|
+
kadFiles: Number(kadFiles),
|
|
71
|
+
kadNodes: Number(kadNodes)
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
//#endregion
|
|
76
|
+
export { StatsResponseParser };
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
//#region src/ec/tag/Tag.ts
|
|
2
|
+
var Tag = class {
|
|
3
|
+
name;
|
|
4
|
+
type;
|
|
5
|
+
nameValue;
|
|
6
|
+
value;
|
|
7
|
+
nestedTags;
|
|
8
|
+
constructor(name, type, nestedTags = [], nameValue = name) {
|
|
9
|
+
this.name = name;
|
|
10
|
+
this.type = type;
|
|
11
|
+
this.nameValue = nameValue;
|
|
12
|
+
if (nestedTags.length > 0) this.nestedTags = nestedTags;
|
|
13
|
+
}
|
|
14
|
+
getValue() {
|
|
15
|
+
return this.value;
|
|
16
|
+
}
|
|
17
|
+
setValue(value) {
|
|
18
|
+
this.value = value;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
var CustomTag = class extends Tag {
|
|
22
|
+
constructor(name, value, subtags = [], nameValue = name) {
|
|
23
|
+
super(name, 1, subtags, nameValue);
|
|
24
|
+
if (value !== void 0) this.setValue(value);
|
|
25
|
+
}
|
|
26
|
+
parseValue(value) {
|
|
27
|
+
this.setValue(value);
|
|
28
|
+
}
|
|
29
|
+
encodeValue() {
|
|
30
|
+
return this.getValue();
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var UByteTag = class UByteTag extends Tag {
|
|
34
|
+
constructor(name, value, subtags = [], nameValue = name) {
|
|
35
|
+
super(name, 2, subtags, nameValue);
|
|
36
|
+
if (value !== void 0) this.setValue(value);
|
|
37
|
+
}
|
|
38
|
+
static withValue(name, value, subtags = []) {
|
|
39
|
+
return new UByteTag(name, value, subtags);
|
|
40
|
+
}
|
|
41
|
+
parseValue(value) {
|
|
42
|
+
if (value.length === 0) this.setValue(0);
|
|
43
|
+
else if (value.length === 1) this.setValue(value[0]);
|
|
44
|
+
else throw new Error("UInt8Tag value must be 1 byte long");
|
|
45
|
+
}
|
|
46
|
+
encodeValue() {
|
|
47
|
+
const buf = Buffer.allocUnsafe(1);
|
|
48
|
+
buf.writeUInt8(this.getValue());
|
|
49
|
+
return buf;
|
|
50
|
+
}
|
|
51
|
+
getShort() {
|
|
52
|
+
return this.getValue();
|
|
53
|
+
}
|
|
54
|
+
getInt() {
|
|
55
|
+
return this.getValue();
|
|
56
|
+
}
|
|
57
|
+
getLong() {
|
|
58
|
+
return BigInt(this.getValue());
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var UShortTag = class UShortTag extends Tag {
|
|
62
|
+
constructor(name, value, subtags = [], nameValue = name) {
|
|
63
|
+
super(name, 3, subtags, nameValue);
|
|
64
|
+
if (value !== void 0) this.setValue(value);
|
|
65
|
+
}
|
|
66
|
+
static withValue(name, value, subtags = []) {
|
|
67
|
+
return new UShortTag(name, value, subtags);
|
|
68
|
+
}
|
|
69
|
+
parseValue(value) {
|
|
70
|
+
if (value.length === 0) this.setValue(0);
|
|
71
|
+
else if (value.length === 2) this.setValue(value.readUInt16BE(0));
|
|
72
|
+
else throw new Error("UInt16Tag value must be 2 bytes long");
|
|
73
|
+
}
|
|
74
|
+
encodeValue() {
|
|
75
|
+
const buf = Buffer.allocUnsafe(2);
|
|
76
|
+
buf.writeUInt16BE(this.getValue());
|
|
77
|
+
return buf;
|
|
78
|
+
}
|
|
79
|
+
getShort() {
|
|
80
|
+
return this.getValue();
|
|
81
|
+
}
|
|
82
|
+
getInt() {
|
|
83
|
+
return this.getValue();
|
|
84
|
+
}
|
|
85
|
+
getLong() {
|
|
86
|
+
return BigInt(this.getValue());
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
var UIntTag = class UIntTag extends Tag {
|
|
90
|
+
constructor(name, value, subtags = [], nameValue = name) {
|
|
91
|
+
super(name, 4, subtags, nameValue);
|
|
92
|
+
if (value !== void 0) this.setValue(value);
|
|
93
|
+
}
|
|
94
|
+
static withValue(name, value, subtags = []) {
|
|
95
|
+
return new UIntTag(name, value, subtags);
|
|
96
|
+
}
|
|
97
|
+
parseValue(value) {
|
|
98
|
+
if (value.length === 0) this.setValue(0);
|
|
99
|
+
else if (value.length === 4) this.setValue(value.readUInt32BE(0));
|
|
100
|
+
else throw new Error("UInt32Tag value must be 4 bytes long");
|
|
101
|
+
}
|
|
102
|
+
encodeValue() {
|
|
103
|
+
const buf = Buffer.allocUnsafe(4);
|
|
104
|
+
buf.writeUInt32BE(this.getValue());
|
|
105
|
+
return buf;
|
|
106
|
+
}
|
|
107
|
+
getShort() {
|
|
108
|
+
throw new Error("Unsigned Integer cannot be cast to short");
|
|
109
|
+
}
|
|
110
|
+
getInt() {
|
|
111
|
+
return this.getValue();
|
|
112
|
+
}
|
|
113
|
+
getLong() {
|
|
114
|
+
return BigInt(this.getValue());
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
var ULongTag = class ULongTag extends Tag {
|
|
118
|
+
constructor(name, value, subtags = [], nameValue = name) {
|
|
119
|
+
super(name, 5, subtags, nameValue);
|
|
120
|
+
if (value !== void 0) this.setValue(value);
|
|
121
|
+
}
|
|
122
|
+
static withValue(name, value, subtags = []) {
|
|
123
|
+
return new ULongTag(name, value, subtags);
|
|
124
|
+
}
|
|
125
|
+
parseValue(value) {
|
|
126
|
+
if (value.length === 0) this.setValue(0n);
|
|
127
|
+
else if (value.length === 8) this.setValue(value.readBigUInt64BE(0));
|
|
128
|
+
else throw new Error("UInt64Tag value must be 8 bytes long");
|
|
129
|
+
}
|
|
130
|
+
encodeValue() {
|
|
131
|
+
const buf = Buffer.allocUnsafe(8);
|
|
132
|
+
buf.writeBigUInt64BE(this.getValue());
|
|
133
|
+
return buf;
|
|
134
|
+
}
|
|
135
|
+
getShort() {
|
|
136
|
+
throw new Error("Unsigned Long cannot be cast to short");
|
|
137
|
+
}
|
|
138
|
+
getInt() {
|
|
139
|
+
throw new Error("Unsigned Long cannot be cast to int");
|
|
140
|
+
}
|
|
141
|
+
getLong() {
|
|
142
|
+
return this.getValue();
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
var UInt128Tag = class UInt128Tag extends Tag {
|
|
146
|
+
constructor(name, value, subtags = [], nameValue = name) {
|
|
147
|
+
super(name, 10, subtags, nameValue);
|
|
148
|
+
if (value !== void 0) this.setValue(value);
|
|
149
|
+
}
|
|
150
|
+
static withValue(name, value, subtags = []) {
|
|
151
|
+
return new UInt128Tag(name, value, subtags);
|
|
152
|
+
}
|
|
153
|
+
parseValue(value) {
|
|
154
|
+
if (value.length === 0) this.setValue(0n);
|
|
155
|
+
else {
|
|
156
|
+
let result = 0n;
|
|
157
|
+
for (let i = 0; i < value.length; i++) result = result << 8n | BigInt(value[i]);
|
|
158
|
+
this.setValue(result);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
encodeValue() {
|
|
162
|
+
const val = this.getValue();
|
|
163
|
+
const bytes = [];
|
|
164
|
+
let remaining = val;
|
|
165
|
+
while (remaining > 0n) {
|
|
166
|
+
bytes.unshift(Number(remaining & 255n));
|
|
167
|
+
remaining >>= 8n;
|
|
168
|
+
}
|
|
169
|
+
while (bytes.length < 16) bytes.unshift(0);
|
|
170
|
+
return Buffer.from(bytes);
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
var StringTag = class StringTag extends Tag {
|
|
174
|
+
constructor(name, value, subtags = [], nameValue = name) {
|
|
175
|
+
super(name, 6, subtags, nameValue);
|
|
176
|
+
if (value !== void 0) this.setValue(value);
|
|
177
|
+
}
|
|
178
|
+
static withValue(name, value, subtags = []) {
|
|
179
|
+
return new StringTag(name, value, subtags);
|
|
180
|
+
}
|
|
181
|
+
parseValue(value) {
|
|
182
|
+
if (value[value.length - 1] !== 0) throw new Error("StringTag value must be null terminated");
|
|
183
|
+
this.setValue(value.toString("utf8", 0, value.length - 1));
|
|
184
|
+
}
|
|
185
|
+
encodeValue() {
|
|
186
|
+
return Buffer.concat([Buffer.from(this.getValue(), "utf8"), Buffer.from([0])]);
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
var DoubleTag = class DoubleTag extends Tag {
|
|
190
|
+
constructor(name, value, subtags = [], nameValue = name) {
|
|
191
|
+
super(name, 7, subtags, nameValue);
|
|
192
|
+
if (value !== void 0) this.setValue(value);
|
|
193
|
+
}
|
|
194
|
+
static withValue(name, value, subtags = []) {
|
|
195
|
+
return new DoubleTag(name, value, subtags);
|
|
196
|
+
}
|
|
197
|
+
parseValue(value) {
|
|
198
|
+
const numValue = value.length >= 8 ? value.readDoubleBE(0) : 0;
|
|
199
|
+
this.setValue(numValue);
|
|
200
|
+
}
|
|
201
|
+
encodeValue() {
|
|
202
|
+
const buf = Buffer.allocUnsafe(8);
|
|
203
|
+
buf.writeDoubleBE(this.getValue());
|
|
204
|
+
return buf;
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
var Ipv4Tag = class Ipv4Tag extends Tag {
|
|
208
|
+
constructor(name, value, subtags = [], nameValue = name) {
|
|
209
|
+
super(name, 8, subtags, nameValue);
|
|
210
|
+
if (value !== void 0) this.setValue(value);
|
|
211
|
+
}
|
|
212
|
+
static withValue(name, value, subtags = []) {
|
|
213
|
+
return new Ipv4Tag(name, value, subtags);
|
|
214
|
+
}
|
|
215
|
+
parseValue(value) {
|
|
216
|
+
if (value.length !== 6) throw new Error("Ipv4Tag value must be 6 bytes long");
|
|
217
|
+
const address = `${value[0]}.${value[1]}.${value[2]}.${value[3]}`;
|
|
218
|
+
const port = value.readUInt16BE(4);
|
|
219
|
+
this.setValue({
|
|
220
|
+
address,
|
|
221
|
+
port
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
encodeValue() {
|
|
225
|
+
const val = this.getValue();
|
|
226
|
+
const parts = val.address.split(".").map(Number);
|
|
227
|
+
const buf = Buffer.allocUnsafe(6);
|
|
228
|
+
buf[0] = parts[0];
|
|
229
|
+
buf[1] = parts[1];
|
|
230
|
+
buf[2] = parts[2];
|
|
231
|
+
buf[3] = parts[3];
|
|
232
|
+
buf.writeUInt16BE(val.port, 4);
|
|
233
|
+
return buf;
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
var Hash16Tag = class Hash16Tag extends Tag {
|
|
237
|
+
constructor(name, value, subtags = [], nameValue = name) {
|
|
238
|
+
super(name, 9, subtags, nameValue);
|
|
239
|
+
if (value !== void 0) this.setValue(value);
|
|
240
|
+
}
|
|
241
|
+
static withValue(name, value, subtags = []) {
|
|
242
|
+
return new Hash16Tag(name, value, subtags);
|
|
243
|
+
}
|
|
244
|
+
parseValue(value) {
|
|
245
|
+
if (value.length === 16) this.setValue(value);
|
|
246
|
+
else throw new Error("Hash16Tag value must be 16 bytes long");
|
|
247
|
+
}
|
|
248
|
+
encodeValue() {
|
|
249
|
+
return this.getValue();
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
function findTag(tags, name) {
|
|
253
|
+
return tags.find((tag) => tag.name === name);
|
|
254
|
+
}
|
|
255
|
+
function findNumericTag(tags, name) {
|
|
256
|
+
const tag = tags.find((tag) => tag.name === name);
|
|
257
|
+
if (tag && "getInt" in tag && "getShort" in tag && "getLong" in tag) return tag;
|
|
258
|
+
}
|
|
259
|
+
//#endregion
|
|
260
|
+
export { StringTag as a, UInt128Tag as c, UShortTag as d, findNumericTag as f, Ipv4Tag as i, UIntTag as l, DoubleTag as n, Tag as o, findTag as p, Hash16Tag as r, UByteTag as s, CustomTag as t, ULongTag as u };
|