Merge pull request #134 from Permissionless-Software-Foundation/v1.0.10

libp2p v1.2.1
This commit is contained in:
Chris Troutner
2024-01-28 19:36:24 -08:00
committed by GitHub
5 changed files with 1724 additions and 2907 deletions
+1655 -2865
View File
File diff suppressed because it is too large Load Diff
+6 -2
View File
@@ -28,6 +28,10 @@
"@chainsafe/libp2p-noise": "14.1.0", "@chainsafe/libp2p-noise": "14.1.0",
"@chainsafe/libp2p-yamux": "6.0.1", "@chainsafe/libp2p-yamux": "6.0.1",
"@libp2p/bootstrap": "10.0.7", "@libp2p/bootstrap": "10.0.7",
"@libp2p/circuit-relay-v2": "1.0.13",
"@libp2p/identify": "1.0.6",
"@libp2p/keychain": "4.0.7",
"@libp2p/logger": "4.0.5",
"@libp2p/tcp": "9.0.7", "@libp2p/tcp": "9.0.7",
"axios": "0.27.2", "axios": "0.27.2",
"bcryptjs": "2.4.3", "bcryptjs": "2.4.3",
@@ -35,7 +39,7 @@
"datastore-fs": "9.1.6", "datastore-fs": "9.1.6",
"glob": "7.1.6", "glob": "7.1.6",
"helia": "2.1.0", "helia": "2.1.0",
"helia-coord": "1.4.2", "helia-coord": "1.4.3",
"jsonrpc-lite": "2.2.0", "jsonrpc-lite": "2.2.0",
"jsonwebtoken": "8.5.1", "jsonwebtoken": "8.5.1",
"jwt-bch-lib": "1.3.0", "jwt-bch-lib": "1.3.0",
@@ -50,7 +54,7 @@
"koa-router": "10.0.0", "koa-router": "10.0.0",
"koa-static": "5.0.0", "koa-static": "5.0.0",
"koa2-ratelimit": "0.9.1", "koa2-ratelimit": "0.9.1",
"libp2p": "0.46.21", "libp2p": "1.2.1",
"line-reader": "0.4.0", "line-reader": "0.4.0",
"minimal-slp-wallet": "5.11.1", "minimal-slp-wallet": "5.11.1",
"mongoose": "5.13.14", "mongoose": "5.13.14",
+1 -1
View File
@@ -53,7 +53,7 @@ RUN git clone https://github.com/Permissionless-Software-Foundation/ipfs-service
WORKDIR /home/safeuser/ipfs-service-provider WORKDIR /home/safeuser/ipfs-service-provider
# For development: switch to unstable branch # For development: switch to unstable branch
RUN git checkout ct-unstable RUN git checkout v1.0.10
# Install dependencies # Install dependencies
#RUN mkdir .ipfsdata #RUN mkdir .ipfsdata
+4 -2
View File
@@ -14,8 +14,8 @@ services:
restart: always restart: always
ipfs-service: ipfs-service:
#build: . build: .
image: christroutner/ipfs-service-provider:v5.0.1 #image: christroutner/ipfs-service-provider:v5.0.1
container_name: ipfs-service container_name: ipfs-service
logging: logging:
driver: 'json-file' driver: 'json-file'
@@ -27,6 +27,8 @@ services:
- mongo-ipfs-service - mongo-ipfs-service
ports: ports:
- '5010:5010' # <host port>:<container port> - '5010:5010' # <host port>:<container port>
- '4001:4001'
- '4003:4003'
volumes: volumes:
- ../data/ipfsdata:/home/safeuser/ipfs-service-provider/.ipfsdata - ../data/ipfsdata:/home/safeuser/ipfs-service-provider/.ipfsdata
- ./start-production.sh:/home/safeuser/ipfs-service-provider/start-production.sh - ./start-production.sh:/home/safeuser/ipfs-service-provider/start-production.sh
+58 -37
View File
@@ -18,18 +18,21 @@ import { tcp } from '@libp2p/tcp'
import { noise } from '@chainsafe/libp2p-noise' import { noise } from '@chainsafe/libp2p-noise'
import { yamux } from '@chainsafe/libp2p-yamux' import { yamux } from '@chainsafe/libp2p-yamux'
// import { bootstrap } from '@libp2p/bootstrap' // import { bootstrap } from '@libp2p/bootstrap'
import { identifyService } from 'libp2p/identify' // import { identifyService } from 'libp2p/identify'
// import { identify } from '@libp2p/identify' import { identify } from '@libp2p/identify'
import { circuitRelayServer, circuitRelayTransport } from 'libp2p/circuit-relay' // import { circuitRelayServer, circuitRelayTransport } from 'libp2p/circuit-relay'
// import { circuitRelayServer, circuitRelayTransport } from '@libp2p/circuit-relay-v2' import { circuitRelayServer, circuitRelayTransport } from '@libp2p/circuit-relay-v2'
import { gossipsub } from '@chainsafe/libp2p-gossipsub' import { gossipsub } from '@chainsafe/libp2p-gossipsub'
import { webSockets } from '@libp2p/websockets' import { webSockets } from '@libp2p/websockets'
import { publicIpv4 } from 'public-ip' import { publicIpv4 } from 'public-ip'
import { multiaddr } from '@multiformats/multiaddr' import { multiaddr } from '@multiformats/multiaddr'
import { webRTC } from '@libp2p/webrtc' import { webRTC } from '@libp2p/webrtc'
import { keychain } from '@libp2p/keychain'
import { defaultLogger } from '@libp2p/logger'
// Local libraries // Local libraries
import config from '../../../config/index.js' import config from '../../../config/index.js'
import JsonFiles from '../json-files.js'
// Hack to get __dirname back. // Hack to get __dirname back.
// https://blog.logrocket.com/alternatives-dirname-node-js-es-modules/ // https://blog.logrocket.com/alternatives-dirname-node-js-es-modules/
@@ -48,6 +51,7 @@ class IpfsAdapter {
this.createLibp2p = createLibp2p this.createLibp2p = createLibp2p
this.publicIp = publicIpv4 this.publicIp = publicIpv4
this.multiaddr = multiaddr this.multiaddr = multiaddr
this.jsonFiles = new JsonFiles()
// Properties of this class instance. // Properties of this class instance.
this.isReady = false this.isReady = false
@@ -57,6 +61,7 @@ class IpfsAdapter {
this.createNode = this.createNode.bind(this) this.createNode = this.createNode.bind(this)
this.stop = this.stop.bind(this) this.stop = this.stop.bind(this)
this.ensureBlocksDir = this.ensureBlocksDir.bind(this) this.ensureBlocksDir = this.ensureBlocksDir.bind(this)
this.getSeed = this.getSeed.bind(this)
} }
// Start an IPFS node. // Start an IPFS node.
@@ -110,9 +115,28 @@ class IpfsAdapter {
const blockstore = new FsBlockstore(`${IPFS_DIR}/blockstore`) const blockstore = new FsBlockstore(`${IPFS_DIR}/blockstore`)
const datastore = new FsDatastore(`${IPFS_DIR}/datastore`) const datastore = new FsDatastore(`${IPFS_DIR}/datastore`)
// TODO: Replace this with a random string generator.
// const keychainInit = await this.getSeed()
const keychainInit = {
pass: await this.getSeed()
}
// Create an identity
let peerId
const chain = keychain(keychainInit)({
datastore,
logger: defaultLogger()
})
try {
peerId = await chain.exportPeerId('myKey')
} catch (err) {
await chain.createKey('myKey', 'RSA', 4096)
peerId = await chain.exportPeerId('myKey')
}
// Configure services // Configure services
const services = { const services = {
identify: identifyService(), identify: identify(),
pubsub: gossipsub({ allowPublishToZeroPeers: true }) pubsub: gossipsub({ allowPublishToZeroPeers: true })
} }
if (this.config.isCircuitRelay) { if (this.config.isCircuitRelay) {
@@ -134,31 +158,9 @@ class IpfsAdapter {
console.log('Helia (IPFS) node IS NOT configured as Circuit Relay') console.log('Helia (IPFS) node IS NOT configured as Circuit Relay')
} }
// const bootstrapList = [
// //
// // // launchpad-p2wdb-service (Launchpad pinning service)
// // '/ip4/137.184.13.92/tcp/4001/p2p/12D3KooWPpBXhhAeoCZCGuQ3KR4xwHzzvtP57f6zLmo8P7ZFBJFE',
// //
// // // PSFoundation.info metrics
// // '/ip4/5.161.72.148/tcp/4001/p2p/12D3KooWDL1kPixc6hcT4s7teWGufrxXmZFD1kPeGdDrsKgYrFUt',
// //
// // // PSFoundation.info P2WDB
// // '/ip4/5.161.72.148/tcp/4101/p2p/12D3KooWHz1sRB94EEVRQRJvUX9MyRm3xhr4QSyCoJbTdu2AYheq',
// //
// // // TokenTiger.com backup P2WDB
// // '/ip4/161.35.99.207/tcp/4001/p2p/12D3KooWDtj9cfj1SKuLbDNKvKRKSsGN8qivq9M8CYpLPDpcD5pu',
// //
// // // helia-p2wdb-dev-server-01 prototype P2WDB server using Helia (Token Tiger)
// // '/ip4/137.184.93.145/tcp/4001/p2p/12D3KooWGZCpD5Ue3CJCBBEKowcuKEgeVKbTM7VMbJ8xm1bqST1j',
// //
// // // helia-p2wdb-dev-server-01 prototype P2WDB server using Helia (FullStack.cash)
// // '/ip4/78.46.129.7/tcp/7001/p2p/12D3KooWRqe7TwTj8apPxmpPqPgHiv7qv5YBJTo1VeQ7zrdyA2HN'
// ]
// bootstrapList = bootstrapList.concat(this.config.bootstrapRelays)
// console.log('bootstrapList: ', bootstrapList)
// libp2p is the networking layer that underpins Helia // libp2p is the networking layer that underpins Helia
const libp2p = await this.createLibp2p({ const libp2p = await this.createLibp2p({
peerId,
datastore, datastore,
addresses: { addresses: {
listen: [ listen: [
@@ -183,18 +185,9 @@ class IpfsAdapter {
streamMuxers: [ streamMuxers: [
yamux() yamux()
], ],
// peerDiscovery: [
// bootstrap({
// list: bootstrapList
// })
// ],
services services
}) })
// console.log(`Node started with id ${libp2p.peerId.toString()}`)
// console.log('Listening on:')
// libp2p.getMultiaddrs().forEach((ma) => console.log(ma.toString()))
// create a Helia node // create a Helia node
const helia = await createHelia({ const helia = await createHelia({
blockstore, blockstore,
@@ -234,6 +227,34 @@ class IpfsAdapter {
throw err throw err
} }
} }
// This function opens the seed used to generate the key for this IPFS peer.
// The seed is stored in a JSON file. If it doesn't exist, a new one is created.
async getSeed () {
try {
let seed
const filename = `${IPFS_DIR}/seed.json`
try {
// Try to read the JSON file containing the seed.
seed = await this.jsonFiles.readJSON(filename)
} catch (err) {
const seedNum = Math.floor(Math.random() * 1000000000000000000000)
seed = seedNum.toString()
// Save the newly generated seed
await this.jsonFiles.writeJSON(seed, filename)
}
// console.log('getSeed() seed: ', seed)
return seed
} catch (err) {
console.error('Error in getSeed()')
throw err
}
}
} }
export default IpfsAdapter export default IpfsAdapter