mirror of
https://github.com/fluencelabs/examples
synced 2025-06-26 16:21:36 +00:00
Aqua IPFS demo: change nodes, fix 'remove' button (#30)
This commit is contained in:
@ -5,6 +5,7 @@
|
|||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
|
"prestart": "npm run build",
|
||||||
"start:local": "node dist/demo.js local",
|
"start:local": "node dist/demo.js local",
|
||||||
"start:remote": "node dist/demo.js krasnodar",
|
"start:remote": "node dist/demo.js krasnodar",
|
||||||
"start": "npm run start:remote"
|
"start": "npm run start:remote"
|
||||||
|
@ -34,7 +34,10 @@ import { globSource, urlSource } from "ipfs-http-client";
|
|||||||
|
|
||||||
async function main(environment: Node[]) {
|
async function main(environment: Node[]) {
|
||||||
// setLogLevel('DEBUG');
|
// setLogLevel('DEBUG');
|
||||||
let providerHost = environment[0];
|
let providerHost = environment[4];
|
||||||
|
let relay = environment[3];
|
||||||
|
let serviceHost = environment[2];
|
||||||
|
|
||||||
let providerClient = new FluencePeer();
|
let providerClient = new FluencePeer();
|
||||||
await providerClient.start({ connectTo: providerHost });
|
await providerClient.start({ connectTo: providerHost });
|
||||||
console.log("📘 uploading .wasm to node %s", providerHost.multiaddr);
|
console.log("📘 uploading .wasm to node %s", providerHost.multiaddr);
|
||||||
@ -43,7 +46,7 @@ async function main(environment: Node[]) {
|
|||||||
console.log("📗 swarmAddr", swarmAddr);
|
console.log("📗 swarmAddr", swarmAddr);
|
||||||
console.log("📗 rpcAddr", rpcAddr);
|
console.log("📗 rpcAddr", rpcAddr);
|
||||||
|
|
||||||
await Fluence.start({ connectTo: environment[1] });
|
await Fluence.start({ connectTo: relay });
|
||||||
console.log(
|
console.log(
|
||||||
"📗 created a fluence client %s with relay %s",
|
"📗 created a fluence client %s with relay %s",
|
||||||
Fluence.getStatus().peerId,
|
Fluence.getStatus().peerId,
|
||||||
@ -51,11 +54,11 @@ async function main(environment: Node[]) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// default IPFS timeout is 1 sec, set to 10 secs to retrieve file from remote node
|
// default IPFS timeout is 1 sec, set to 10 secs to retrieve file from remote node
|
||||||
await set_timeout(environment[2].peerId, 10);
|
await set_timeout(serviceHost.peerId, 10);
|
||||||
|
|
||||||
console.log("\n\n📘 Will deploy ProcessFiles service");
|
console.log("\n\n📘 Will deploy ProcessFiles service");
|
||||||
var service_id = await deploy_service(
|
var service_id = await deploy_service(
|
||||||
environment[2].peerId,
|
serviceHost.peerId,
|
||||||
file.cid.toString(),
|
file.cid.toString(),
|
||||||
rpcAddr,
|
rpcAddr,
|
||||||
(label, error) => {
|
(label, error) => {
|
||||||
@ -79,7 +82,7 @@ async function main(environment: Node[]) {
|
|||||||
providerClient
|
providerClient
|
||||||
);
|
);
|
||||||
var putResult = await put_file_size(
|
var putResult = await put_file_size(
|
||||||
environment[2].peerId,
|
serviceHost.peerId,
|
||||||
newFile.cid.toString(),
|
newFile.cid.toString(),
|
||||||
rpcAddr,
|
rpcAddr,
|
||||||
service_id,
|
service_id,
|
||||||
@ -94,7 +97,7 @@ async function main(environment: Node[]) {
|
|||||||
console.log("📗 File size is saved to IPFS:", putResult);
|
console.log("📗 File size is saved to IPFS:", putResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = await remove_service(environment[2].peerId, service_id);
|
let result = await remove_service(serviceHost.peerId, service_id);
|
||||||
console.log("📗 ProcessFiles service removed", result);
|
console.log("📗 ProcessFiles service removed", result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ import {
|
|||||||
} from "./appState";
|
} from "./appState";
|
||||||
import { decapsulateP2P, fromOption } from "./util";
|
import { decapsulateP2P, fromOption } from "./util";
|
||||||
|
|
||||||
export const relayNodes = [krasnodar[0], krasnodar[1], krasnodar[2]];
|
export const relayNodes = [krasnodar[2], krasnodar[3], krasnodar[4]];
|
||||||
|
|
||||||
const requestRpcAddr = async () => {
|
const requestRpcAddr = async () => {
|
||||||
let result = await get_external_api_multiaddr(
|
let result = await get_external_api_multiaddr(
|
||||||
@ -122,13 +122,15 @@ export const useRemoveService = () => {
|
|||||||
const setFileSizeCID = useSetRecoilState(fileSizeCIDState);
|
const setFileSizeCID = useSetRecoilState(fileSizeCIDState);
|
||||||
|
|
||||||
return async () => {
|
return async () => {
|
||||||
if (isConnected || serviceId === null) {
|
console.dir(isConnected, serviceId);
|
||||||
|
if (!isConnected || serviceId === null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await remove_service(relay!, serviceId, {
|
await remove_service(relay!, serviceId, {
|
||||||
ttl: 10000,
|
ttl: 10000,
|
||||||
});
|
});
|
||||||
|
console.log(`Service ${serviceId} was removed`);
|
||||||
setServiceId(null);
|
setServiceId(null);
|
||||||
setFileCID(null);
|
setFileCID(null);
|
||||||
setFileSize(null);
|
setFileSize(null);
|
||||||
|
@ -22,7 +22,7 @@ export const serviceIdState = atom<string | null>({
|
|||||||
|
|
||||||
export const wasmState = atom<string>({
|
export const wasmState = atom<string>({
|
||||||
key: "serviceState",
|
key: "serviceState",
|
||||||
default: "Qmf8fH2cDZXGKS9uDGBcHxv5uQ51ChrigdZKe3QxS2C1AF",
|
default: "QmSvjkzXbXYwFXcWuFWqFdksvQDgpCeADNxkgkfzCLA4rk",
|
||||||
});
|
});
|
||||||
|
|
||||||
export const rpcAddrState = atom<string | null>({
|
export const rpcAddrState = atom<string | null>({
|
||||||
@ -32,7 +32,7 @@ export const rpcAddrState = atom<string | null>({
|
|||||||
|
|
||||||
export const fileCIDState = atom<string | null>({
|
export const fileCIDState = atom<string | null>({
|
||||||
key: "fileCIDState",
|
key: "fileCIDState",
|
||||||
default: "Qmf8fH2cDZXGKS9uDGBcHxv5uQ51ChrigdZKe3QxS2C1AF",
|
default: "QmSvjkzXbXYwFXcWuFWqFdksvQDgpCeADNxkgkfzCLA4rk",
|
||||||
});
|
});
|
||||||
|
|
||||||
export const fileSizeState = atom<string | null>({
|
export const fileSizeState = atom<string | null>({
|
||||||
|
Reference in New Issue
Block a user