Skip to content

Commit

Permalink
Merge pull request #10 from DIG-Network/release/v0.0.1-alpha.10
Browse files Browse the repository at this point in the history
Release/v0.0.1 alpha.10
  • Loading branch information
MichaelTaylor3D authored Sep 10, 2024
2 parents 0d73615 + 26bd47f commit bc6e25c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [0.0.1-alpha.10](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.9...v0.0.1-alpha.10) (2024-09-10)


### Bug Fixes

* better trusted node handling ([0b1fefe](https://github.com/DIG-Network/dig-chia-sdk/commit/0b1fefebbf4b8b3a27a0d8b7af0afe59bc457aef))

### [0.0.1-alpha.9](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.8...v0.0.1-alpha.9) (2024-09-10)


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dignetwork/dig-sdk",
"version": "0.0.1-alpha.9",
"version": "0.0.1-alpha.10",
"description": "",
"type": "commonjs",
"main": "./dist/index.js",
Expand Down
19 changes: 16 additions & 3 deletions src/blockchain/FullNodePeer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,31 @@ export class FullNodePeer {
private static isValidIpAddress(ip: string): boolean {
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]?)$/;

return ipv4Regex.test(ip);
}

private static async fetchNewPeerIPs(): Promise<string[]> {
/**
* Retrieves the TRUSTED_FULLNODE IP from the environment
* and verifies if it is a valid IP address.
*
* @returns {string | null} The valid IP address or null if invalid
*/
private static getTrustedFullNode(): string | null {
const trustedNodeIp = process.env.TRUSTED_FULLNODE || null;

if (trustedNodeIp && FullNodePeer.isValidIpAddress(trustedNodeIp)) {
return trustedNodeIp;
}
return null;
}

private static async fetchNewPeerIPs(): Promise<string[]> {
const trustedNodeIp = FullNodePeer.getTrustedFullNode();
const priorityIps: string[] = [];

// Prioritize trustedNodeIp
if (
trustedNodeIp &&
FullNodePeer.isValidIpAddress(trustedNodeIp) &&
(await FullNodePeer.isPortReachable(trustedNodeIp, FULLNODE_PORT))
) {
priorityIps.push(trustedNodeIp);
Expand Down

0 comments on commit bc6e25c

Please sign in to comment.