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