Applying 'server' IPFS profile

This commit is contained in:
Chris Troutner
2021-04-06 12:08:42 -07:00
parent e03657f97e
commit 72c72bcf40
5 changed files with 37 additions and 60 deletions
+3 -3
View File
@@ -8676,9 +8676,9 @@
}
},
"ipfs-coord": {
"version": "2.2.6",
"resolved": "https://registry.npmjs.org/ipfs-coord/-/ipfs-coord-2.2.6.tgz",
"integrity": "sha512-+EM4JUuWpIoc9Je7GSZzrKvCPzwYMgIAiq6659GeTN6oIp4SqyBZBUhtUQTy/lMwSha5F7Jgjc4BjErpIgp8EA==",
"version": "2.2.10",
"resolved": "https://registry.npmjs.org/ipfs-coord/-/ipfs-coord-2.2.10.tgz",
"integrity": "sha512-45jNX3hUjYYrLs6HLTRYRYkkK9+V204eVt8r/0SZ1nV8Q0V8BPmcQ4UhA5zxOyk77GcrtcdyPyDgeVM9sThOlQ==",
"requires": {
"bch-encrypt-lib": "^2.0.0",
"orbit-db": "^0.26.1"
+1 -1
View File
@@ -39,7 +39,7 @@
"bcryptjs": "^2.4.3",
"glob": "^7.1.6",
"ipfs": "^0.54.4",
"ipfs-coord": "^2.2.6",
"ipfs-coord": "^2.2.10",
"jsonrpc-lite": "^2.2.0",
"jsonwebtoken": "^8.5.1",
"kcors": "^2.2.2",
+15 -6
View File
@@ -5,8 +5,8 @@
// Global npm libraries
const IPFS = require('ipfs')
// const IpfsCoord = require('ipfs-coord')
const IpfsCoord = require('../../../ipfs-coord')
const IpfsCoord = require('ipfs-coord')
// const IpfsCoord = require('../../../ipfs-coord')
const BCHJS = require('@psf/bch-js')
// Local libraries
@@ -44,9 +44,9 @@ class IPFSLib {
const ipfsOptions = {
repo: './ipfsdata',
start: true,
EXPERIMENTAL: {
pubsub: true
},
// EXPERIMENTAL: {
// pubsub: true
// },
config: {
relay: {
enabled: true, // enable circuit relay dialer and listener
@@ -54,12 +54,21 @@ class IPFSLib {
enabled: true // enable circuit relay HOP (make this node a relay)
}
},
pubsub: true // enable pubsub
pubsub: true, // enable pubsub
Swarm: {
ConnMgr: {
HighWater: 30,
LowWater: 10
}
}
}
}
// Create a new IPFS node.
this.ipfs = await this.IPFS.create(ipfsOptions)
// Set the 'server' profile so the node does not scan private networks.
await this.ipfs.config.profiles.apply('server')
} catch (err) {
console.error('Error in startIpfs()')
throw err
+15 -36
View File
@@ -24,12 +24,13 @@ class AuthRPC {
try {
console.log('authRouter rpcData: ', rpcData)
// if (rpcData.payload.method === 'getAll') return await this.getAll()
// Default return object.
// let retObj = {}
// Route the call based on the value of the method property.
switch (rpcData.payload.method) {
case 'authUser':
return await this.authUser()
return await this.authUser(rpcData)
}
} catch (err) {
console.error('Error in AuthRPC/authRouter()')
@@ -51,47 +52,25 @@ class AuthRPC {
const login = rpcData.payload.params.login
const password = rpcData.payload.params.password
// const user = await this.passport.authUser(ctx, next)
// if (!user) {
// // ctx.throw(401)
// const retJson =
// }
const user = await this.userLib.authUser(login, password)
console.log('user: ', user)
return user
// console.log('user: ', user)
// const token = user.generateToken()
//
// const response = user.toJSON()
//
// delete response.password
//
// ctx.body = {
// token,
// user: response
// }
const token = user.generateToken()
const response = {
id: user._id,
type: user.type,
name: user.name,
email: user.email,
token
}
return response
} catch (err) {
console.error('Error in authUser()')
throw err
}
}
// Get all Users.
async getAll () {
try {
console.log('Executing get all')
const users = await this.userLib.getAllUsers()
const retJson = this.jsonrpc.success('getAll', users)
const retStr = JSON.stringify(retJson, null, 2)
return retStr
} catch (err) {
console.error('Error in getAll()')
throw err
}
}
}
module.exports = AuthRPC
+3 -14
View File
@@ -22,19 +22,13 @@ class UserRPC {
try {
// console.log('userRouter rpcData: ', rpcData)
// if (rpcData.payload.method === 'getAll') return await this.getAll()
// const retObj = {
// id: 'users'
// }
let retObj = {}
// Default return object.
// let retObj = {}
// Route the call based on the value of the method property.
switch (rpcData.payload.method) {
case 'getAll':
// retObj.method = 'getAll'
retObj = await this.getAll()
return retObj
return await this.getAll()
case 'getUser':
return await this.getUser(rpcData)
}
@@ -51,11 +45,6 @@ class UserRPC {
const users = await this.userLib.getAllUsers()
return users
// const retJson = this.jsonrpc.success('getAll', users)
// const retStr = JSON.stringify(retJson, null, 2)
//
// return retStr
} catch (err) {
console.error('Error in getAll()')
throw err