initial commit
This commit is contained in:
commit
b07177c4e1
|
@ -0,0 +1 @@
|
||||||
|
node_modules
|
|
@ -0,0 +1,59 @@
|
||||||
|
version: '3.1'
|
||||||
|
services:
|
||||||
|
ipfs:
|
||||||
|
image: ipfs/go-ipfs@sha256:bba42c9cc48625e165c90809b63348f54d3e9d9036d23344dd3fb8edd24ddf5d
|
||||||
|
volumes:
|
||||||
|
- ipfs_data:/data/ipfs
|
||||||
|
- zen_data:/root/.zen
|
||||||
|
environment:
|
||||||
|
- IPFS_PROFILE=server
|
||||||
|
ports:
|
||||||
|
- 4001:4001
|
||||||
|
- 5001:5001
|
||||||
|
- 8080:8080
|
||||||
|
|
||||||
|
oasis:
|
||||||
|
image: josselinchevalay/oasis
|
||||||
|
environment:
|
||||||
|
- HOST_ALLOW=*
|
||||||
|
ports:
|
||||||
|
- 3000:3000
|
||||||
|
volumes:
|
||||||
|
- ssb_data:/home/astroport/.ssb
|
||||||
|
|
||||||
|
registry:
|
||||||
|
image: josselinchevalay/ipdr
|
||||||
|
volumes:
|
||||||
|
- registry_ipfs_data:/home/astroport/.ipfs
|
||||||
|
ports:
|
||||||
|
- 5000:5000
|
||||||
|
- 5002:5001
|
||||||
|
- 4002:4001
|
||||||
|
- 8081:8080
|
||||||
|
|
||||||
|
scheduler:
|
||||||
|
image: mcuadros/ofelia
|
||||||
|
volumes:
|
||||||
|
- /var/run/docker.sock:/var/run/docker.sock:ro
|
||||||
|
depends_on:
|
||||||
|
- registry
|
||||||
|
|
||||||
|
cleanerSwarm:
|
||||||
|
image: node
|
||||||
|
volumes:
|
||||||
|
- ./ipfs-swarm-cleaner:/usr/src/app
|
||||||
|
- ssb_data:/root/.ssb
|
||||||
|
- zen_data:/root/.zen
|
||||||
|
depends_on:
|
||||||
|
- oasis
|
||||||
|
- ipfs
|
||||||
|
links:
|
||||||
|
- oasis
|
||||||
|
- ipfs
|
||||||
|
entrypoint: "tail -f /dev/null"
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
ipfs_data:
|
||||||
|
ssb_data:
|
||||||
|
registry_ipfs_data:
|
||||||
|
zen_data:
|
|
@ -0,0 +1,152 @@
|
||||||
|
const ipfsClient = require('ipfs-http-client');
|
||||||
|
const ssbClient = require('ssb-client');
|
||||||
|
const FS = require('fs');
|
||||||
|
const Path = require('path');
|
||||||
|
const pull = require('pull-stream');
|
||||||
|
const sbotOpts = {host:"oasis", port:8008};
|
||||||
|
const ipfsOpts = { host: 'ipfs', port: '5001', protocol: 'http' };
|
||||||
|
const homePath = "/root/.zen";
|
||||||
|
const ipfsWebUiHash = "bafybeidatpz2hli6fgu3zul5woi27ujesdf5o5a7bu622qj6ugharciwjq";
|
||||||
|
|
||||||
|
let clearSwarmPeers = async(ipfs) => {
|
||||||
|
const peersInfo = await ipfs.swarm.addrs();
|
||||||
|
peersInfo.forEach((peer) => {
|
||||||
|
ipfs.swarm.disconnect(peer.addrs[0]).then(() => {
|
||||||
|
console.log(`${peer.id} disconnected`)
|
||||||
|
}).catch((err) => {
|
||||||
|
console.log(`${peer.id} not disconnect : ${err.message}`)
|
||||||
|
} )
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
let clearBootstrapPeers = async(ipfs) => {
|
||||||
|
const bootstraps = await ipfs.bootstrap.list()
|
||||||
|
bootstraps.Peers.forEach((bootstrap) => {
|
||||||
|
ipfs.bootstrap.rm(bootstrap)
|
||||||
|
.then((done) => {console.log(`${bootstrap} disconnected`)})
|
||||||
|
.catch((err) => {console.log(`${bootstrap} not diconnect : ${error.message}`)})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
let connectOnSwarm = async(ipfs, addr) => {
|
||||||
|
ipfs.swarm.connect(addr)
|
||||||
|
.then((done) => {console.log(`${addr} connected`)})
|
||||||
|
.catch((err) => { console.log(`${addr} not connected error : ${err.message}`)})
|
||||||
|
}
|
||||||
|
|
||||||
|
let whoami = () => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
ssbClient(sbotOpts, (err, sbot) => {
|
||||||
|
if(err) reject(err);
|
||||||
|
sbot.whoami((err, id) => {
|
||||||
|
if(err) reject(err);
|
||||||
|
sbot.close();
|
||||||
|
resolve(id);
|
||||||
|
})
|
||||||
|
});
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
let ssbRequest = (query) => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
ssbClient(sbotOpts, (err, sbot) => {
|
||||||
|
if(err) reject(err);
|
||||||
|
pull(sbot.query.read(query), pull.collect((error, results) => {
|
||||||
|
if(error) reject(error);
|
||||||
|
sbot.close();
|
||||||
|
resolve(results);
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
let ssbFriends = () => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
ssbClient(sbotOpts, (err, sbot) => {
|
||||||
|
if(err) reject(err);
|
||||||
|
pull(sbot.friends.createFriendStream(), pull.collect((err, friends) => {
|
||||||
|
if(err) reject(err);
|
||||||
|
sbot.close();
|
||||||
|
resolve(friends);
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
let findRecent = (arr) => {
|
||||||
|
let recent = arr[0];
|
||||||
|
arr.forEach((a) => {
|
||||||
|
if(a.timestamp > recent.timestamp) {
|
||||||
|
recent = a;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return recent;
|
||||||
|
}
|
||||||
|
|
||||||
|
excludeLan = (addrs) => {
|
||||||
|
return addrs.filter((a) => !a.toString().match( /(127\.)|(10\.)|(172\.1[6-9]\.)|(172\.2[0-9]\.)|172\.3[0-1]\.|(192\.168\.)/gm))
|
||||||
|
}
|
||||||
|
|
||||||
|
let publish = (message) => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
ssbClient(sbotOpts, (err, sbot) => {
|
||||||
|
if(err) reject(err);
|
||||||
|
sbot.publish(message)
|
||||||
|
.then((d) => {
|
||||||
|
console.log(`your message : ${JSON.stringify(message)} plubished`);
|
||||||
|
sbot.close();
|
||||||
|
resolve();
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
reject(err)
|
||||||
|
});
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
let main = async() => {
|
||||||
|
const ipfs = ipfsClient(ipfsOpts);
|
||||||
|
let identity = await ipfs.id();
|
||||||
|
let addrs = await ipfs.swarm.localAddrs();
|
||||||
|
let ipfsWebUIpinSet = await ipfs.pin.add(ipfsWebUiHash);
|
||||||
|
let wholeAddrs = excludeLan(addrs);
|
||||||
|
let ssbId = await whoami();
|
||||||
|
let friends = await ssbFriends();
|
||||||
|
let localRepositoryPath = Path.join(homePath, identity.id);
|
||||||
|
console.log(`Checking local repository ${localRepositoryPath}`)
|
||||||
|
console.log(`pin set webui ${JSON.stringify(ipfsWebUIpinSet)}`)
|
||||||
|
if(!FS.existsSync(localRepositoryPath)){
|
||||||
|
console.log(`Create ${localRepositoryPath}`)
|
||||||
|
FS.mkdirSync(localRepositoryPath);
|
||||||
|
FS.mkdirSync(Path.join(localRepositoryPath, 'G1SSB'))
|
||||||
|
}else {
|
||||||
|
console.log(`${localRepositoryPath} exist`)
|
||||||
|
}
|
||||||
|
|
||||||
|
let ipfsNodeIdRequest = await ssbRequest({"query":[{"$filter":{"value":{"content":{"type":"ipfsnodeid"}}}}]});
|
||||||
|
publish({"type":"ipfsnodeid", "text": identity.id});
|
||||||
|
|
||||||
|
for(var i = 0; i < wholeAddrs.length; i++) {
|
||||||
|
publish({"type": "ipfstryme", "text": wholeAddrs[i].toString() + "/p2p/"+identity.id})
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`${identity.id} checking bootstrap peer`);
|
||||||
|
clearBootstrapPeers(ipfs);
|
||||||
|
console.log(`${identity.id} checking swarm peers`);
|
||||||
|
clearSwarmPeers(ipfs);
|
||||||
|
console.log(`${identity.id} all bootstrap peers and swarm peers are disconnected`)
|
||||||
|
console.log(`your ssb id ${ssbId.id}`)
|
||||||
|
for(var i = 0; i < friends.length; i++) {
|
||||||
|
console.log(`checking ${friends[i]} have ipfs node`);
|
||||||
|
let ipfsTryMes = await ssbRequest({"query":[{"$filter":{"value":{"author": friends[i], "content":{"type":"ipfstryme"}}}}]});
|
||||||
|
let recentIpfsTryMe = findRecent(ipfsTryMes);
|
||||||
|
if(recentIpfsTryMe)
|
||||||
|
connectOnSwarm(ipfs, recentIpfsTryMe.value.content.text);
|
||||||
|
else
|
||||||
|
console.log(`checking ${friends[i]} haven't ipfs node`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,18 @@
|
||||||
|
{
|
||||||
|
"name": "ipfs-swarm-cleaner",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"ipfs-http-client": "^44.1.0",
|
||||||
|
"moment": "^2.26.0",
|
||||||
|
"pull-stream": "^3.6.14",
|
||||||
|
"ssb-client": "4.9.0"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue