Skip to content

Commit

Permalink
Merge pull request #122 from DIG-Network/release/v0.0.1-alpha.134
Browse files Browse the repository at this point in the history
Release/v0.0.1 alpha.134
  • Loading branch information
MichaelTaylor3D authored Oct 5, 2024
2 parents 5afdedf + 9cf650b commit cee13c3
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 13 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.134](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.133...v0.0.1-alpha.134) (2024-10-05)


### Bug Fixes

* ping peer message ([b6d5a6a](https://github.com/DIG-Network/dig-chia-sdk/commit/b6d5a6add70f61d6d4453e9e2e1cfce843069515))

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


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.133",
"version": "0.0.1-alpha.134",
"description": "",
"type": "commonjs",
"main": "./dist/index.js",
Expand Down
55 changes: 45 additions & 10 deletions src/DigNetwork/PropagationServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ export class PropagationServer {
* @param rootHash - The root hash for the store update.
*/
async pingUpdate(rootHash: string): Promise<void> {
const spinner = createSpinner(`Pinging peer ${this.ipAddress}...`).start();

try {
const httpsAgent = this.createHttpsAgent();
const url = `https://${formatHost(this.ipAddress)}:${
Expand All @@ -131,6 +129,10 @@ export class PropagationServer {
headers: {
"Content-Type": "application/json",
},
validateStatus: (status) => {
// Accept all status codes to handle them manually
return true;
},
};

// Data to send in the request (storeId and rootHash)
Expand All @@ -142,20 +144,53 @@ export class PropagationServer {

try {
const response = await axios.post(url, data, config);
console.log(green(`✔ Successfully pinged peer: ${this.ipAddress}`));
spinner.success({
text: green(
`✔ Successfully pinged peer ${this.ipAddress} with rootHash ${rootHash}`
),
});
return response.data;

if (response.status === 200) {
console.log(green(`✔ Peer was up to date: ${this.ipAddress}`));
return;
} else if (
response.status === 400 &&
response.data?.error?.includes("does not exist")
) {
console.log(
yellow(
`⚠ Peer ${this.ipAddress} does not have store ${this.storeId}. Notifying for update.`
)
);
// You can implement additional logic here if needed, such as retrying or logging
return;
} else {
console.error(
red(
`✖ Unexpected response from peer ${this.ipAddress}: ${response.status} ${response.statusText}`
)
);
throw new Error(
`Unexpected response: ${response.status} ${response.statusText}`
);
}
} catch (error: any) {
if (error.response) {
// Server responded with a status other than 2xx
if (
error.response.status === 400 &&
error.response.data?.error?.includes("does not exist")
) {
console.log(
yellow(
`⚠ Peer ${this.ipAddress} does not have store ${this.storeId}. Notifying for update.`
)
);
// You can implement additional logic here if needed
return;
}
}

console.error(red(`✖ Failed to ping peer: ${this.ipAddress}`));
console.error(red(error.message));
throw error;
}
} catch (error: any) {
spinner.error({ text: red("✖ Error pinging network peer.") });
console.error(red(error.message));
}
}
Expand Down

0 comments on commit cee13c3

Please sign in to comment.