@mtcute/core 0.24.2 → 0.24.3

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.
@@ -216,7 +216,11 @@ class UpdatesManager {
216
216
  utils$1.assertNever();
217
217
  }
218
218
  if (this.pendingUpdateContainers.length % WARN_EVERY === 0) {
219
- this.log.warn("%d pending update containers, updatesLoopActive = %b. possible memory leak", this.pendingUpdateContainers.length, this.updatesLoopActive);
219
+ if (this.updatesLoopActive) {
220
+ this.log.warn("%d pending update containers, but the updates loop is not active. did you forget to start it?", this.pendingUpdateContainers.length);
221
+ } else {
222
+ this.log.warn("%d pending update containers, can't keep up!", this.pendingUpdateContainers.length);
223
+ }
220
224
  }
221
225
  this.updatesLoopCv.notify();
222
226
  }
@@ -946,6 +950,11 @@ class UpdatesManager {
946
950
  this.log.warn("cannot fetch full peer %d - getPeerById returned null", id);
947
951
  return;
948
952
  }
953
+ if (peerUtils$1.isInputPeerChannel(peer)) {
954
+ return batchedQueries._getChannelsBatched(client, peerUtils$1.toInputChannel(peer));
955
+ } else if (peerUtils$1.isInputPeerUser(peer)) {
956
+ return batchedQueries._getUsersBatched(client, peerUtils$1.toInputUser(peer));
957
+ }
949
958
  log.warn("cannot fetch full peer %d - unknown peer type %s", id, peer._);
950
959
  }).catch((err) => {
951
960
  log.warn("error fetching full peer %d: %e", id, err);
@@ -7,11 +7,11 @@ import { EarlyTimer } from "../../utils/early-timer.js";
7
7
  import { toggleChannelIdMark, parseMarkedPeerId, getBarePeerId, getMarkedPeerId } from "../../utils/peer-utils.js";
8
8
  import { SortedArray } from "../../utils/sorted-array.js";
9
9
  import "@mtcute/tl-runtime";
10
- import { _getChannelsBatched } from "../methods/chats/batched-queries.js";
10
+ import { _getChannelsBatched, _getUsersBatched } from "../methods/chats/batched-queries.js";
11
11
  import { PeersIndex } from "../types/peers/peers-index.js";
12
12
  import { RawUpdateInfo } from "./types.js";
13
13
  import { toPendingUpdate, messageToUpdate, isMessageEmpty, createDummyUpdatesContainer, extractChannelIdFromUpdate } from "./utils.js";
14
- import { toInputChannel } from "../utils/peer-utils.js";
14
+ import { toInputChannel, isInputPeerChannel, isInputPeerUser, toInputUser } from "../utils/peer-utils.js";
15
15
  const WARN_EVERY = 100;
16
16
  const KEEP_ALIVE_INTERVAL = 15 * 60 * 1e3;
17
17
  const UPDATES_TOO_LONG = { _: "updatesTooLong" };
@@ -209,7 +209,11 @@ class UpdatesManager {
209
209
  assertNever();
210
210
  }
211
211
  if (this.pendingUpdateContainers.length % WARN_EVERY === 0) {
212
- this.log.warn("%d pending update containers, updatesLoopActive = %b. possible memory leak", this.pendingUpdateContainers.length, this.updatesLoopActive);
212
+ if (this.updatesLoopActive) {
213
+ this.log.warn("%d pending update containers, but the updates loop is not active. did you forget to start it?", this.pendingUpdateContainers.length);
214
+ } else {
215
+ this.log.warn("%d pending update containers, can't keep up!", this.pendingUpdateContainers.length);
216
+ }
213
217
  }
214
218
  this.updatesLoopCv.notify();
215
219
  }
@@ -939,6 +943,11 @@ class UpdatesManager {
939
943
  this.log.warn("cannot fetch full peer %d - getPeerById returned null", id);
940
944
  return;
941
945
  }
946
+ if (isInputPeerChannel(peer)) {
947
+ return _getChannelsBatched(client, toInputChannel(peer));
948
+ } else if (isInputPeerUser(peer)) {
949
+ return _getUsersBatched(client, toInputUser(peer));
950
+ }
942
951
  log.warn("cannot fetch full peer %d - unknown peer type %s", id, peer._);
943
952
  }).catch((err) => {
944
953
  log.warn("error fetching full peer %d: %e", id, err);
@@ -24,11 +24,13 @@ function internalErrorsHandler(params) {
24
24
  const exceptErrorsSet = exceptErrors ? new Set(exceptErrors) : void 0;
25
25
  return async (ctx, next) => {
26
26
  const numRetries = ctx.params?.maxRetryCount ?? maxRetries;
27
+ let lastError;
27
28
  for (let i = 0; i <= numRetries; i++) {
28
29
  const res = await next(ctx);
29
30
  if (!typeAssertions.isTlRpcError(res)) return res;
30
31
  if (!CLIENT_ERRORS.has(res.errorCode)) {
31
32
  if (exceptErrorsSet?.has(res.errorMessage)) return res;
33
+ lastError = res;
32
34
  if (ctx.params?.throw503 && res.errorCode === -503) {
33
35
  throw new errors.MtTimeoutError();
34
36
  }
@@ -49,6 +51,7 @@ function internalErrorsHandler(params) {
49
51
  }
50
52
  return res;
51
53
  }
54
+ return lastError;
52
55
  };
53
56
  }
54
57
  exports.internalErrorsHandler = internalErrorsHandler;
@@ -17,11 +17,13 @@ function internalErrorsHandler(params) {
17
17
  const exceptErrorsSet = exceptErrors ? new Set(exceptErrors) : void 0;
18
18
  return async (ctx, next) => {
19
19
  const numRetries = ctx.params?.maxRetryCount ?? maxRetries;
20
+ let lastError;
20
21
  for (let i = 0; i <= numRetries; i++) {
21
22
  const res = await next(ctx);
22
23
  if (!isTlRpcError(res)) return res;
23
24
  if (!CLIENT_ERRORS.has(res.errorCode)) {
24
25
  if (exceptErrorsSet?.has(res.errorMessage)) return res;
26
+ lastError = res;
25
27
  if (ctx.params?.throw503 && res.errorCode === -503) {
26
28
  throw new MtTimeoutError();
27
29
  }
@@ -42,6 +44,7 @@ function internalErrorsHandler(params) {
42
44
  }
43
45
  return res;
44
46
  }
47
+ return lastError;
45
48
  };
46
49
  }
47
50
  export {
@@ -220,7 +220,7 @@ class NetworkManager {
220
220
  _: "initConnection",
221
221
  deviceModel,
222
222
  systemVersion: "1.0",
223
- appVersion: "0.24.2",
223
+ appVersion: "0.24.3",
224
224
  systemLangCode: "en",
225
225
  langPack: "",
226
226
  // "langPacks are for official apps only"
@@ -213,7 +213,7 @@ class NetworkManager {
213
213
  _: "initConnection",
214
214
  deviceModel,
215
215
  systemVersion: "1.0",
216
- appVersion: "0.24.2",
216
+ appVersion: "0.24.3",
217
217
  systemLangCode: "en",
218
218
  langPack: "",
219
219
  // "langPacks are for official apps only"
@@ -54,7 +54,8 @@ class PersistentConnection {
54
54
  const uidPrefix = `[UID ${this._uid}] `;
55
55
  if (this._fuman.isConnected) {
56
56
  const dc = this.params.dc;
57
- this.log.prefix = `${uidPrefix}[DC ${dc.id}:${dc.ipAddress}:${dc.port}] `;
57
+ const prettifiedIp = net.ip.prettify(dc.ipAddress, { encloseIpv6: true });
58
+ this.log.prefix = `${uidPrefix}[DC ${dc.id} @ ${prettifiedIp}:${dc.port}] `;
58
59
  } else if (this._fuman.isConnecting) {
59
60
  this.log.prefix = `${uidPrefix}[connecting] `;
60
61
  } else {
@@ -1,5 +1,5 @@
1
1
  import { FramedReader, FramedWriter } from "@fuman/io";
2
- import { PersistentConnection as PersistentConnection$1, ConnectionClosedError } from "@fuman/net";
2
+ import { PersistentConnection as PersistentConnection$1, ip, ConnectionClosedError } from "@fuman/net";
3
3
  import { Emitter, timers } from "@fuman/utils";
4
4
  let nextConnectionUid = 0;
5
5
  class PersistentConnection {
@@ -47,7 +47,8 @@ class PersistentConnection {
47
47
  const uidPrefix = `[UID ${this._uid}] `;
48
48
  if (this._fuman.isConnected) {
49
49
  const dc = this.params.dc;
50
- this.log.prefix = `${uidPrefix}[DC ${dc.id}:${dc.ipAddress}:${dc.port}] `;
50
+ const prettifiedIp = ip.prettify(dc.ipAddress, { encloseIpv6: true });
51
+ this.log.prefix = `${uidPrefix}[DC ${dc.id} @ ${prettifiedIp}:${dc.port}] `;
51
52
  } else if (this._fuman.isConnecting) {
52
53
  this.log.prefix = `${uidPrefix}[connecting] `;
53
54
  } else {
@@ -27,8 +27,18 @@ class ServerSaltManager {
27
27
  _timer;
28
28
  _scheduleNext() {
29
29
  if (this._timer) utils.timers.clearTimeout(this._timer);
30
- if (this._futureSalts.length === 0) return;
31
- const next = this._futureSalts.shift();
30
+ const now = Date.now() / 1e3;
31
+ let next;
32
+ while (this._futureSalts.length !== 0) {
33
+ const salt = this._futureSalts.shift();
34
+ if (salt.validSince <= now && now <= salt.validUntil) {
35
+ next = salt;
36
+ break;
37
+ }
38
+ }
39
+ if (!next) {
40
+ return;
41
+ }
32
42
  this._timer = utils.timers.setTimeout(
33
43
  () => {
34
44
  this.currentSalt = next.salt;
@@ -20,8 +20,18 @@ class ServerSaltManager {
20
20
  _timer;
21
21
  _scheduleNext() {
22
22
  if (this._timer) timers.clearTimeout(this._timer);
23
- if (this._futureSalts.length === 0) return;
24
- const next = this._futureSalts.shift();
23
+ const now = Date.now() / 1e3;
24
+ let next;
25
+ while (this._futureSalts.length !== 0) {
26
+ const salt = this._futureSalts.shift();
27
+ if (salt.validSince <= now && now <= salt.validUntil) {
28
+ next = salt;
29
+ break;
30
+ }
31
+ }
32
+ if (!next) {
33
+ return;
34
+ }
25
35
  this._timer = timers.setTimeout(
26
36
  () => {
27
37
  this.currentSalt = next.salt;
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@mtcute/core",
3
3
  "type": "module",
4
- "version": "0.24.2",
4
+ "version": "0.24.3",
5
5
  "description": "Type-safe library for MTProto (Telegram API)",
6
6
  "license": "MIT",
7
7
  "scripts": {},
8
8
  "dependencies": {
9
- "@fuman/io": "0.0.14",
10
- "@fuman/net": "0.0.14",
11
- "@fuman/utils": "0.0.14",
12
- "@mtcute/file-id": "^0.23.0",
9
+ "@fuman/io": "0.0.15",
10
+ "@fuman/net": "0.0.15",
11
+ "@fuman/utils": "0.0.15",
12
+ "@mtcute/file-id": "^0.24.3",
13
13
  "@mtcute/tl": "^204.0.0",
14
- "@mtcute/tl-runtime": "^0.23.0",
14
+ "@mtcute/tl-runtime": "^0.24.3",
15
15
  "@types/events": "3.0.0",
16
16
  "long": "5.2.3"
17
17
  },