amule-ec-client 0.6.0 → 0.7.0

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.
Files changed (87) hide show
  1. package/README.md +10 -2
  2. package/dist/{AddLinkRequest-DwUbSMXD.mjs → AddLinkRequest-DEKGy-R2.js} +2 -5
  3. package/dist/{ClientQueueRequest-D9FaX5K9.mjs → ClientQueueRequest-DrLXSxtp.js} +2 -5
  4. package/dist/{ClientQueueResponse-FVQBR_8b.mjs → ClientQueueResponse-CXxY_9wU.js} +6 -6
  5. package/dist/{CreateCategoryRequest-Br6yfDhZ.mjs → CreateCategoryRequest-COulF12x.js} +2 -5
  6. package/dist/{DeleteCategoryRequest-C2-p6sx0.mjs → DeleteCategoryRequest-D-mljaNV.js} +2 -5
  7. package/dist/{DownloadCommandRequest-CaULjfNi.mjs → DownloadCommandRequest-Bf1Ez8Da.js} +3 -6
  8. package/dist/{DownloadFileRequest-CcNqsBo7.mjs → DownloadFileRequest-WfOIV07R.js} +2 -5
  9. package/dist/{DownloadQueueRequest-bd7lFiMj.mjs → DownloadQueueRequest-Br-pgrRt.js} +2 -5
  10. package/dist/DownloadQueueResponse-C-5d4teB.js +241 -0
  11. package/dist/{GetPreferencesRequest-C94Su9IH.mjs → GetPreferencesRequest-BE3RbRRn.js} +2 -5
  12. package/dist/{PreferencesDetailsResponse-BjMxbvVY.mjs → PreferencesDetailsResponse-D8lBd8Ot.js} +1 -4
  13. package/dist/{PreferencesResponse-Dth-n2sA.mjs → PreferencesResponse-BmGTQM30.js} +1 -4
  14. package/dist/{ReloadSharedFilesRequest-CPwAEJYG.mjs → ReloadSharedFilesRequest-BbDUeGcq.js} +2 -4
  15. package/dist/{Request-C0UUuQIX.mjs → Request-BvScDpeu.js} +3 -11
  16. package/dist/{SearchProgressResponse-Bputc9Ww.mjs → SearchProgressResponse-BQPliUup.js} +1 -4
  17. package/dist/{SearchRequest-CNqz-K1Z.mjs → SearchRequest-DOakj8fA.js} +3 -6
  18. package/dist/{SearchResultsRequest-DKG508KF.mjs → SearchResultsRequest-oZBs5KKm.js} +2 -4
  19. package/dist/{SearchResultsResponse-ChNrKJ6_.mjs → SearchResultsResponse-C9I9x035.js} +1 -4
  20. package/dist/{SearchStatusRequest-Bv6iaC9Y.mjs → SearchStatusRequest-B1ZzSQlE.js} +2 -4
  21. package/dist/{SearchStopRequest-rET-2Nsz.mjs → SearchStopRequest-FfXf_DCn.js} +2 -4
  22. package/dist/{ServerConnectRequest-CcO2-Eqd.mjs → ServerConnectRequest-Cdiw-KWu.js} +2 -5
  23. package/dist/{ServerDisconnectRequest-DEORM3SF.mjs → ServerDisconnectRequest-BVXSumxX.js} +2 -4
  24. package/dist/{ServerListRequest-FwFQBp12.mjs → ServerListRequest-3yMrgZID.js} +2 -4
  25. package/dist/{ServerListResponse-ZAKSSCPZ.mjs → ServerListResponse-Do3iRai0.js} +5 -6
  26. package/dist/{ServerUpdateFromUrlRequest-D4xBqJDJ.mjs → ServerUpdateFromUrlRequest-DpxBII5W.js} +2 -5
  27. package/dist/{SetFileCategoryRequest-BwEPJVeR.mjs → SetFileCategoryRequest-CFgkJB-H.js} +2 -5
  28. package/dist/{SetPreferencesRequest-D2fVIH3P.mjs → SetPreferencesRequest-BdZ40Ao_.js} +2 -5
  29. package/dist/{SharedFilePriorityRequest-j6ImgagV.mjs → SharedFilePriorityRequest-BMNmaL06.js} +2 -5
  30. package/dist/{SharedFilesRequest-D2M3K0eB.mjs → SharedFilesRequest-BZKz0oyn.js} +2 -5
  31. package/dist/SharedFilesResponse-DE0cd1DT.js +45 -0
  32. package/dist/{StatsRequest-B8v9LLHG.mjs → StatsRequest-DVwx5wk1.js} +2 -5
  33. package/dist/{StatsResponse-BVUxNPbz.mjs → StatsResponse-CP2F2zt0.js} +25 -4
  34. package/dist/{Codes-CjiW7Pdl.mjs → Tag-B5gWV2XF.js} +268 -3
  35. package/dist/{UpdateCategoryRequest-CgzH7SxP.mjs → UpdateCategoryRequest-Bu22YjOm.js} +2 -5
  36. package/dist/{UpdateRequest-Bunl73Ga.mjs → UpdateRequest-CaQ867p8.js} +2 -5
  37. package/dist/UpdateState-Dn-SuAsj.js +173 -0
  38. package/dist/{download-details-OM0FJUhZ.mjs → download-details-OM0FJUhZ.js} +0 -2
  39. package/dist/{index.d.mts → index.d.ts} +358 -337
  40. package/dist/{index.mjs → index.js} +94 -54
  41. package/dist/rolldown-runtime-D7D4PA-g.js +13 -0
  42. package/dist/{utils-DBnUQnZ-.mjs → utils-CNoUroOI.js} +11 -3
  43. package/package.json +1 -1
  44. package/dist/AddLinkRequest-DwUbSMXD.mjs.map +0 -1
  45. package/dist/ClientQueueRequest-D9FaX5K9.mjs.map +0 -1
  46. package/dist/ClientQueueResponse-FVQBR_8b.mjs.map +0 -1
  47. package/dist/Codes-CjiW7Pdl.mjs.map +0 -1
  48. package/dist/CreateCategoryRequest-Br6yfDhZ.mjs.map +0 -1
  49. package/dist/DeleteCategoryRequest-C2-p6sx0.mjs.map +0 -1
  50. package/dist/DownloadCommandRequest-CaULjfNi.mjs.map +0 -1
  51. package/dist/DownloadFileRequest-CcNqsBo7.mjs.map +0 -1
  52. package/dist/DownloadQueueRequest-bd7lFiMj.mjs.map +0 -1
  53. package/dist/DownloadQueueResponse-DyP1rLTV.mjs +0 -261
  54. package/dist/DownloadQueueResponse-DyP1rLTV.mjs.map +0 -1
  55. package/dist/GetPreferencesRequest-C94Su9IH.mjs.map +0 -1
  56. package/dist/PreferencesDetailsResponse-BjMxbvVY.mjs.map +0 -1
  57. package/dist/PreferencesResponse-Dth-n2sA.mjs.map +0 -1
  58. package/dist/ReloadSharedFilesRequest-CPwAEJYG.mjs.map +0 -1
  59. package/dist/Request-C0UUuQIX.mjs.map +0 -1
  60. package/dist/SearchProgressResponse-Bputc9Ww.mjs.map +0 -1
  61. package/dist/SearchRequest-CNqz-K1Z.mjs.map +0 -1
  62. package/dist/SearchResultsRequest-DKG508KF.mjs.map +0 -1
  63. package/dist/SearchResultsResponse-ChNrKJ6_.mjs.map +0 -1
  64. package/dist/SearchStatusRequest-Bv6iaC9Y.mjs.map +0 -1
  65. package/dist/SearchStopRequest-rET-2Nsz.mjs.map +0 -1
  66. package/dist/ServerConnectRequest-CcO2-Eqd.mjs.map +0 -1
  67. package/dist/ServerDisconnectRequest-DEORM3SF.mjs.map +0 -1
  68. package/dist/ServerListRequest-FwFQBp12.mjs.map +0 -1
  69. package/dist/ServerListResponse-ZAKSSCPZ.mjs.map +0 -1
  70. package/dist/ServerUpdateFromUrlRequest-D4xBqJDJ.mjs.map +0 -1
  71. package/dist/SetFileCategoryRequest-BwEPJVeR.mjs.map +0 -1
  72. package/dist/SetPreferencesRequest-D2fVIH3P.mjs.map +0 -1
  73. package/dist/SharedFilePriorityRequest-j6ImgagV.mjs.map +0 -1
  74. package/dist/SharedFilesRequest-D2M3K0eB.mjs.map +0 -1
  75. package/dist/SharedFilesResponse-BiXT_oCx.mjs +0 -41
  76. package/dist/SharedFilesResponse-BiXT_oCx.mjs.map +0 -1
  77. package/dist/StatsRequest-B8v9LLHG.mjs.map +0 -1
  78. package/dist/StatsResponse-BVUxNPbz.mjs.map +0 -1
  79. package/dist/Tag-CZF6BRMY.mjs +0 -262
  80. package/dist/Tag-CZF6BRMY.mjs.map +0 -1
  81. package/dist/UpdateCategoryRequest-CgzH7SxP.mjs.map +0 -1
  82. package/dist/UpdateRequest-Bunl73Ga.mjs.map +0 -1
  83. package/dist/UpdateResponse-1LhyH9Zf.mjs +0 -47
  84. package/dist/UpdateResponse-1LhyH9Zf.mjs.map +0 -1
  85. package/dist/download-details-OM0FJUhZ.mjs.map +0 -1
  86. package/dist/index.mjs.map +0 -1
  87. package/dist/utils-DBnUQnZ-.mjs.map +0 -1
@@ -0,0 +1,173 @@
1
+ import { f as findNumericTag, p as findTag } from "./Tag-B5gWV2XF.js";
2
+ import { a as toOptionalNumber, i as toOptionalIp, n as tagOwnNumericValue, r as toOptionalBool } from "./utils-CNoUroOI.js";
3
+ import { a as rleDecode, i as extractPartFileStatusBuffers, o as sourceNameEntriesFromFileTag, r as computeChunkInfo, s as xorReconstruct, t as DownloadQueueResponseParser } from "./DownloadQueueResponse-C-5d4teB.js";
4
+ import { t as SharedFilesResponseParser } from "./SharedFilesResponse-DE0cd1DT.js";
5
+ import { t as ClientQueueResponseParser } from "./ClientQueueResponse-CXxY_9wU.js";
6
+ import { t as ServerListResponseParser } from "./ServerListResponse-Do3iRai0.js";
7
+ //#region src/response/UpdateResponse.ts
8
+ var UpdateResponseParser = class {
9
+ static fromPacket(packet) {
10
+ const sharedFiles = SharedFilesResponseParser.fromPacket(packet).files;
11
+ const downloadQueue = DownloadQueueResponseParser.fromPacket(packet).files;
12
+ const clientContainer = findTag(packet.tags, 1536);
13
+ const clients = clientContainer && clientContainer.nestedTags ? ClientQueueResponseParser.fromTags(clientContainer.nestedTags).clients : [];
14
+ const serverContainer = findTag(packet.tags, 1280);
15
+ const servers = serverContainer && serverContainer.nestedTags ? ServerListResponseParser.fromTags(serverContainer.nestedTags).servers : [];
16
+ const friendContainer = findTag(packet.tags, 2048);
17
+ return {
18
+ sharedFiles,
19
+ downloadQueue,
20
+ clients,
21
+ servers,
22
+ friends: friendContainer && friendContainer.nestedTags ? this.parseFriends(friendContainer.nestedTags) : []
23
+ };
24
+ }
25
+ static parseFriends(tags) {
26
+ const friends = [];
27
+ const friendTags = tags.filter((t) => t.name === 2048);
28
+ for (const friendTag of friendTags) {
29
+ const nested = friendTag.nestedTags || [];
30
+ friends.push({
31
+ name: findTag(nested, 2049)?.getValue(),
32
+ userHashHexString: findTag(nested, 2050)?.getValue()?.toString("hex"),
33
+ ip: toOptionalIp(findNumericTag(nested, 2051)?.getInt()),
34
+ port: findNumericTag(nested, 2052)?.getInt(),
35
+ friendSlot: toOptionalBool(findNumericTag(nested, 2056)?.getInt()),
36
+ shared: toOptionalBool(findNumericTag(nested, 2057)?.getInt()),
37
+ client: ClientQueueResponseParser.fromTags(nested).clients[0]
38
+ });
39
+ }
40
+ return friends;
41
+ }
42
+ };
43
+ //#endregion
44
+ //#region src/client/UpdateState.ts
45
+ const STATUS_BUFFER_KEYS = [
46
+ "partStatus",
47
+ "gapStatus",
48
+ "reqStatus"
49
+ ];
50
+ /**
51
+ * Merge update fields into the existing object. Fields absent from an incremental
52
+ * response are undefined after parsing and must not clobber previously known values.
53
+ */
54
+ function mergeDefined(existing, updates) {
55
+ const result = { ...existing };
56
+ for (const [key, value] of Object.entries(updates)) if (value !== void 0) result[key] = value;
57
+ return result;
58
+ }
59
+ var UpdateState = class {
60
+ sessionGeneration;
61
+ downloads = /* @__PURE__ */ new Map();
62
+ sharedFiles = /* @__PURE__ */ new Map();
63
+ clients = /* @__PURE__ */ new Map();
64
+ statusBuffers = /* @__PURE__ */ new Map();
65
+ sourceNames = /* @__PURE__ */ new Map();
66
+ /**
67
+ * @param sessionGeneration Connection generation this state belongs to (see
68
+ * AmuleConnection.getSessionGeneration). The state is only valid while the
69
+ * connection that produced it is alive, since the daemon diffs per connection.
70
+ */
71
+ constructor(sessionGeneration) {
72
+ this.sessionGeneration = sessionGeneration;
73
+ }
74
+ apply(packet) {
75
+ const parsed = UpdateResponseParser.fromPacket(packet);
76
+ for (const file of parsed.downloadQueue) {
77
+ delete file.chunkInfo;
78
+ delete file.sourceNames;
79
+ }
80
+ const downloadQueue = this.mergeCollection(this.downloads, parsed.downloadQueue);
81
+ const sharedFiles = this.mergeCollection(this.sharedFiles, parsed.sharedFiles);
82
+ const clients = this.mergeCollection(this.clients, parsed.clients);
83
+ for (const ecid of [...this.statusBuffers.keys()]) if (!this.downloads.has(ecid)) this.statusBuffers.delete(ecid);
84
+ for (const ecid of [...this.sourceNames.keys()]) if (!this.downloads.has(ecid)) this.sourceNames.delete(ecid);
85
+ this.reconstructFileDetails(packet);
86
+ this.attachSources();
87
+ return {
88
+ downloadQueue,
89
+ sharedFiles,
90
+ clients,
91
+ servers: parsed.servers,
92
+ friends: parsed.friends
93
+ };
94
+ }
95
+ mergeCollection(state, items) {
96
+ const seen = /* @__PURE__ */ new Set();
97
+ const result = [];
98
+ for (const item of items) {
99
+ if (item.ecid === void 0) {
100
+ result.push(item);
101
+ continue;
102
+ }
103
+ seen.add(item.ecid);
104
+ const existing = state.get(item.ecid);
105
+ const merged = existing ? mergeDefined(existing, item) : item;
106
+ state.set(item.ecid, merged);
107
+ result.push(merged);
108
+ }
109
+ for (const ecid of [...state.keys()]) if (!seen.has(ecid)) state.delete(ecid);
110
+ return result;
111
+ }
112
+ /**
113
+ * Reconstruct the incremental per-file details of each partfile in the packet:
114
+ * RLE-decode and XOR-reconstruct the status buffers (recomputing chunk info from the
115
+ * accumulated state), and apply the source-names map diffs (new entry / count change /
116
+ * removal when count is 0).
117
+ */
118
+ reconstructFileDetails(packet) {
119
+ const partfileTags = packet.tags.filter((tag) => tag.name === 768);
120
+ for (const fileTag of partfileTags) {
121
+ const ecid = tagOwnNumericValue(fileTag);
122
+ if (ecid === void 0) continue;
123
+ const file = this.downloads.get(ecid);
124
+ if (!file) continue;
125
+ const raw = extractPartFileStatusBuffers(fileTag);
126
+ const state = this.statusBuffers.get(ecid) || {};
127
+ for (const key of STATUS_BUFFER_KEYS) {
128
+ const rawBuffer = raw[key];
129
+ if (!rawBuffer || rawBuffer.length === 0) continue;
130
+ const decoded = rleDecode(rawBuffer);
131
+ const previous = state[key];
132
+ state[key] = previous ? xorReconstruct(previous, decoded) : decoded;
133
+ }
134
+ this.statusBuffers.set(ecid, state);
135
+ if (file.sizeFull && file.sizeFull > 0) file.chunkInfo = computeChunkInfo(file.sizeFull, state);
136
+ const entries = sourceNameEntriesFromFileTag(fileTag);
137
+ if (entries) {
138
+ const nameMap = this.sourceNames.get(ecid) || /* @__PURE__ */ new Map();
139
+ for (const entry of entries) {
140
+ if (entry.count === 0) {
141
+ nameMap.delete(entry.id);
142
+ continue;
143
+ }
144
+ const existing = nameMap.get(entry.id);
145
+ if (existing) {
146
+ existing.count = entry.count;
147
+ if (entry.name !== void 0) existing.name = entry.name;
148
+ } else if (entry.name !== void 0) nameMap.set(entry.id, {
149
+ name: entry.name,
150
+ count: entry.count
151
+ });
152
+ }
153
+ this.sourceNames.set(ecid, nameMap);
154
+ }
155
+ const nameMap = this.sourceNames.get(ecid);
156
+ if (nameMap) file.sourceNames = [...nameMap.values()];
157
+ }
158
+ }
159
+ /**
160
+ * Group clients by the download they are requesting (client.requestFileId -> file.ecid).
161
+ */
162
+ attachSources() {
163
+ for (const file of this.downloads.values()) file.sources = [];
164
+ for (const client of this.clients.values()) {
165
+ const requestFileId = toOptionalNumber(client.requestFileId);
166
+ if (requestFileId === void 0) continue;
167
+ const file = this.downloads.get(requestFileId);
168
+ if (file) file.sources.push(client);
169
+ }
170
+ }
171
+ };
172
+ //#endregion
173
+ export { UpdateState };
@@ -8,5 +8,3 @@ const ChunkStatus = {
8
8
  };
9
9
  //#endregion
10
10
  export { PARTSIZE as n, ChunkStatus as t };
11
-
12
- //# sourceMappingURL=download-details-OM0FJUhZ.mjs.map