From 72c72bcf40d231c20846b34041eb8d8022075a9c Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Tue, 6 Apr 2021 12:08:42 -0700 Subject: [PATCH] Applying 'server' IPFS profile --- package-lock.json | 6 ++--- package.json | 2 +- src/lib/ipfs.js | 21 ++++++++++++----- src/rpc/auth/index.js | 51 +++++++++++++----------------------------- src/rpc/users/index.js | 17 +++----------- 5 files changed, 37 insertions(+), 60 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1b36582..5a4c93e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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" diff --git a/package.json b/package.json index 82d1360..6c574b1 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/lib/ipfs.js b/src/lib/ipfs.js index 24fcd0e..bf654be 100644 --- a/src/lib/ipfs.js +++ b/src/lib/ipfs.js @@ -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 diff --git a/src/rpc/auth/index.js b/src/rpc/auth/index.js index 667ba19..b7683d6 100644 --- a/src/rpc/auth/index.js +++ b/src/rpc/auth/index.js @@ -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 diff --git a/src/rpc/users/index.js b/src/rpc/users/index.js index 10ffbe1..302f6ad 100644 --- a/src/rpc/users/index.js +++ b/src/rpc/users/index.js @@ -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