Skip to content

Commit

Permalink
- Add Dappnode Peer to Local Ipfs Node (#1804)
Browse files Browse the repository at this point in the history
* - Add Dappnode Peer to Local Ipfs Node

* - Corrections

* - More corrections

---------

Co-authored-by: dappnode <[email protected]>
  • Loading branch information
mateumiralles and dappnode authored Jan 23, 2024
1 parent 3621f2c commit acfb48c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/migrations/src/addDappnodePeerToLocalIpfsNode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { logs } from "@dappnode/logger";

//Adds Dappnode IPFS peer to the local IPFS node for more stability when fetching IPFS content
export async function addDappnodePeerToLocalIpfsNode() {
const dappnodeIpfsPeer =
"/ip4/167.86.114.131/tcp/4001/p2p/QmfB6dT5zxUq1BXiXisgcZKYkvjywdDYBK5keRaqDKH633";
const ipfsAlias = "ipfs.dappnode";

logs.info("adding dappnode peer to local ipfs node");
await fetch(
`http://${ipfsAlias}:5001/api/v0/swarm/peering/add?arg=${dappnodeIpfsPeer}`,
{
method: "POST",
}
);
}
12 changes: 12 additions & 0 deletions packages/migrations/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { removeDnsFromComposeFiles } from "./removeDnsFromComposeFiles.js";
import { migrateDockerNetworkIpRange } from "./migrateDockerNetworkIpRange/index.js";
import { recreateContainersIfLegacyDns } from "./recreateContainersIfLegacyDns.js";
import { ensureCoreComposesHardcodedIpsRange } from "./ensureCoreComposesHardcodedIpsRange.js";
import { addDappnodePeerToLocalIpfsNode } from "./addDappnodePeerToLocalIpfsNode.js";
import { params } from "@dappnode/params";

export class MigrationError extends Error {
Expand Down Expand Up @@ -128,5 +129,16 @@ export async function executeMigrations(): Promise<void> {
})
);

await addDappnodePeerToLocalIpfsNode().catch(
(e: { message: any; stack: any }) =>
migrationErrors.push({
migration: "add Dappnode peer to local IPFS node",
coreVersion: "0.2.88",
name: "MIGRATION_ERROR",
message: e.message,
stack: e.stack,
})
);

if (migrationErrors.length > 0) throw migrationErrors;
}
8 changes: 8 additions & 0 deletions packages/migrations/test/unit/addPeerToLocal.unit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { expect } from "chai";
import { addDappnodePeerToLocalIpfsNode } from "../../src/addDappnodePeerToLocalIpfsNode.js";

describe.skip("Add Dappnode Peer to Local IPFS Node Test", () => {
it("should add a DAppNode peer to the local IPFS node", async () => {
expect(await addDappnodePeerToLocalIpfsNode()).to.not.throw();
});
});

0 comments on commit acfb48c

Please sign in to comment.