@dignetwork/dig-sdk 0.0.1-alpha.162 → 0.0.1-alpha.164
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FullNodePeer.d.ts","sourceRoot":"","sources":["../../src/blockchain/FullNodePeer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAO,MAAM,8BAA8B,CAAC;AAiCzD;;GAEG;AACH,qBAAa,YAAY;IA6BH,OAAO,CAAC,IAAI;IA3BhC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAA6B;IAGpD,OAAO,CAAC,MAAM,CAAC,aAAa,CAAuD;IAGnF,OAAO,CAAC,MAAM,CAAC,cAAc,
|
|
1
|
+
{"version":3,"file":"FullNodePeer.d.ts","sourceRoot":"","sources":["../../src/blockchain/FullNodePeer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAO,MAAM,8BAA8B,CAAC;AAiCzD;;GAEG;AACH,qBAAa,YAAY;IA6BH,OAAO,CAAC,IAAI;IA3BhC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAA6B;IAGpD,OAAO,CAAC,MAAM,CAAC,aAAa,CAAuD;IAGnF,OAAO,CAAC,MAAM,CAAC,cAAc,CAAoC;IAGjE,OAAO,CAAC,MAAM,CAAC,WAAW,CAAkC;IAG5D,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAgB;IAG/C,OAAO,CAAC,MAAM,CAAC,SAAS,CAAoC;IAG5D,OAAO,CAAC,MAAM,CAAC,WAAW,CAAoD;IAG9E,OAAO,CAAC,MAAM,CAAC,YAAY,CAAsC;IAGjE,OAAO,CAAC,MAAM,CAAC,eAAe,CAAa;IAG3C,OAAO;IAEP;;;OAGG;WACW,WAAW,IAAI,YAAY;IAOzC;;OAEG;IACU,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAaxC;;;;OAIG;WACiB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAO5C;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;IAuB9B;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAM/B;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,kBAAkB;IASjC;;;;OAIG;mBACkB,eAAe;IA4FpC;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,YAAY;IAS3B;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,qBAAqB;IAgBpC;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,oBAAoB;IAenC;;;OAGG;mBACkB,UAAU;IAK/B;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,UAAU;IAIzB;;;OAGG;YACW,WAAW;IAuEzB,OAAO,CAAC,eAAe;IAkDvB;;;OAGG;WACW,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAqB3D;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,aAAa;IAS5B;;;;OAIG;WACiB,mBAAmB,CACrC,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,OAAO,CAAC;CAkDpB"}
|
|
@@ -446,7 +446,7 @@ FullNodePeer.instance = null;
|
|
|
446
446
|
// Cooldown cache to exclude faulty peers temporarily
|
|
447
447
|
FullNodePeer.cooldownCache = new node_cache_1.default({ stdTTL: COOLDOWN_DURATION / 1000 });
|
|
448
448
|
// Failed DNS hosts cooldown cache
|
|
449
|
-
FullNodePeer.failedDNSCache = new node_cache_1.default({ stdTTL:
|
|
449
|
+
FullNodePeer.failedDNSCache = new node_cache_1.default({ stdTTL: 86400 });
|
|
450
450
|
// Peer reliability weights
|
|
451
451
|
FullNodePeer.peerWeights = new Map();
|
|
452
452
|
// List of prioritized peers
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../src/utils/network.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../src/utils/network.ts"],"names":[],"mappings":"AAoBA,eAAO,MAAM,aAAa,QAAa,OAAO,CAAC,MAAM,GAAG,SAAS,CA+ChE,CAAC;AAIF,eAAO,MAAM,UAAU,SAAU,MAAM,KAAG,MAUzC,CAAC"}
|
package/dist/utils/network.js
CHANGED
|
@@ -1,52 +1,53 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
4
|
};
|
|
25
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
6
|
exports.formatHost = exports.getPublicHost = void 0;
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
7
|
+
const superagent_1 = __importDefault(require("superagent"));
|
|
8
|
+
const MAX_RETRIES = 5;
|
|
9
|
+
const RETRY_DELAY = 2000; // in milliseconds
|
|
10
|
+
// Regular expression for validating both IPv4 and IPv6 addresses
|
|
11
|
+
const ipv4Regex = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
|
12
|
+
const ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7}([0-9a-fA-F]{1,4}|:)|(([0-9a-fA-F]{1,7}|:):){1,7}([0-9a-fA-F]{1,4}|:))$/;
|
|
13
|
+
// Regular expression for validating hostnames
|
|
14
|
+
const hostnameRegex = /^(([a-zA-Z0-9](-*[a-zA-Z0-9])*)\.)*[a-zA-Z]{2,}$/;
|
|
15
|
+
// Helper function to validate the IP address or hostname
|
|
16
|
+
const isValidHost = (host) => {
|
|
17
|
+
return ipv4Regex.test(host) || ipv6Regex.test(host) || hostnameRegex.test(host);
|
|
18
|
+
};
|
|
32
19
|
const getPublicHost = async () => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
20
|
+
const publicHost = process.env.PUBLIC_IP;
|
|
21
|
+
if (publicHost) {
|
|
22
|
+
console.log("Public IP/Hostname from env:", publicHost);
|
|
23
|
+
if (isValidHost(publicHost)) {
|
|
24
|
+
return publicHost;
|
|
25
|
+
}
|
|
26
|
+
console.error("Invalid public IP/Hostname in environment variable");
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
let attempt = 0;
|
|
30
|
+
while (attempt < MAX_RETRIES) {
|
|
31
|
+
try {
|
|
32
|
+
const response = await superagent_1.default.get("https://api.datalayer.storage/user/v1/get_user_ip");
|
|
33
|
+
if (response.body && response.body.success) {
|
|
34
|
+
const ipAddress = response.body.ip_address;
|
|
35
|
+
if (isValidHost(ipAddress)) {
|
|
36
|
+
return ipAddress;
|
|
37
|
+
}
|
|
38
|
+
throw new Error("Invalid IP address or hostname format received");
|
|
44
39
|
}
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
throw new Error("Failed to retrieve public host");
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
attempt++;
|
|
44
|
+
console.error(`Error fetching public host (Attempt ${attempt}):`, error.message);
|
|
45
|
+
if (attempt >= MAX_RETRIES) {
|
|
46
|
+
throw new Error("Could not retrieve public host after several attempts");
|
|
47
47
|
}
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
await new Promise((resolve) => setTimeout(resolve, RETRY_DELAY));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
50
51
|
};
|
|
51
52
|
exports.getPublicHost = getPublicHost;
|
|
52
53
|
// Helper function to wrap IPv6 addresses in brackets
|