mirror of
https://github.com/Permissionless-Software-Foundation/ipfs-bch-wallet-consumer.git
synced 2026-09-21 16:52:03 -07:00
feat(/ipfs/connect): Adding REST API endpoint to connect to an IPFS peer
This commit is contained in:
Generated
+84
-2198
File diff suppressed because it is too large
Load Diff
+1
-2
@@ -35,8 +35,7 @@
|
|||||||
"datastore-fs": "9.1.5",
|
"datastore-fs": "9.1.5",
|
||||||
"glob": "7.1.6",
|
"glob": "7.1.6",
|
||||||
"helia": "2.0.3",
|
"helia": "2.0.3",
|
||||||
"helia-coord": "1.1.4",
|
"helia-coord": "1.2.0",
|
||||||
"ipfs-http-client": "58.0.0",
|
|
||||||
"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",
|
||||||
|
|||||||
+25
-10
@@ -132,16 +132,31 @@ class IpfsAdapter {
|
|||||||
peerDiscovery: [
|
peerDiscovery: [
|
||||||
bootstrap({
|
bootstrap({
|
||||||
list: [
|
list: [
|
||||||
// '/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN',
|
|
||||||
// '/dnsaddr/bootstrap.libp2p.io/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa',
|
// launchpad-p2wdb-service (Launchpad pinning service)
|
||||||
// '/dnsaddr/bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb',
|
'/ip4/137.184.13.92/tcp/4001/p2p/12D3KooWPpBXhhAeoCZCGuQ3KR4xwHzzvtP57f6zLmo8P7ZFBJFE',
|
||||||
// '/dnsaddr/bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt'
|
|
||||||
'/ip4/5.161.108.190/tcp/4102/p2p/12D3KooWKNuBjaMgEDN2tGqzmdfM2bmd22VEuboC4X7x8ua4DvUg',
|
// PSFoundation.info metrics
|
||||||
'/ip4/5.161.108.190/tcp/4001/p2p/12D3KooWMW3u8ygGHqNHjxXsw7TA39vgrSQEx7vEGoUh7EiCwGGv',
|
'/ip4/5.161.72.148/tcp/4001/p2p/12D3KooWDL1kPixc6hcT4s7teWGufrxXmZFD1kPeGdDrsKgYrFUt',
|
||||||
'/ip4/137.184.13.92/tcp/4001/p2p/12D3KooWMbpo92kSGwWiN6QH7fvstMWiLZKcxmReq3Hhbpya2bq4',
|
|
||||||
'/ip4/78.46.129.7/tcp/4001/p2p/12D3KooWJyc54njjeZGbLew4D8u1ghrmZTTPyh3QpBF7dxtd3zGY',
|
// PSFoundation.info P2WDB
|
||||||
'/ip4/5.161.72.148/tcp/4001/p2p/12D3KooWAVG5kn46P9mjKCLUSPesmmLeKf2a79qRt6u22hJaEARJ',
|
'/ip4/5.161.72.148/tcp/4101/p2p/12D3KooWHz1sRB94EEVRQRJvUX9MyRm3xhr4QSyCoJbTdu2AYheq',
|
||||||
'/ip4/161.35.99.207/tcp/4001/p2p/12D3KooWDtj9cfj1SKuLbDNKvKRKSsGN8qivq9M8CYpLPDpcD5pu'
|
|
||||||
|
// 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',
|
||||||
|
|
||||||
|
// v1 & v2 Circuit Relay (Token Tiger)
|
||||||
|
'/ip4/137.184.93.145/tcp/6001/p2p/12D3KooWBTkiEn4fSGYRMtNT2ZTKhjguymGFHjiJeVVPSwEjXJwq',
|
||||||
|
|
||||||
|
// v1 & v2 Circuit Relay server (FullStack.cash)
|
||||||
|
'/ip4/78.46.129.7/tcp/4002/p2p/12D3KooWBigV2M3Sx4KmM3m2DQMznnZzyNuXPawPsZWRpZmiJ8Kp',
|
||||||
|
|
||||||
|
// helia-p2wdb-dev-server-01 prototype P2WDB server using Helia (FullStack.cash)
|
||||||
|
'/ip4/78.46.129.7/tcp/7001/p2p/12D3KooWBigV2M3Sx4KmM3m2DQMznnZzyNuXPawPsZWRpZmiJ8Kp'
|
||||||
|
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ class IpfsRESTControllerLib {
|
|||||||
this.getPeers = this.getPeers.bind(this)
|
this.getPeers = this.getPeers.bind(this)
|
||||||
this.getRelays = this.getRelays.bind(this)
|
this.getRelays = this.getRelays.bind(this)
|
||||||
this.handleError = this.handleError.bind(this)
|
this.handleError = this.handleError.bind(this)
|
||||||
|
this.connect = this.connect.bind(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -81,6 +82,23 @@ class IpfsRESTControllerLib {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async connect (ctx) {
|
||||||
|
try {
|
||||||
|
const multiaddr = ctx.request.body.multiaddr
|
||||||
|
const getDetails = ctx.request.body.getDetails
|
||||||
|
|
||||||
|
// console.log('this.adapters.ipfs.ipfsCoordAdapter.ipfsCoord.adapters.ipfs: ', this.adapters.ipfs.ipfsCoordAdapter.ipfsCoord.adapters.ipfs)
|
||||||
|
const result = await this.adapters.ipfs.ipfsCoordAdapter.ipfsCoord.adapters.ipfs.connectToPeer({ multiaddr, getDetails })
|
||||||
|
// console.log('result: ', result)
|
||||||
|
|
||||||
|
ctx.body = result
|
||||||
|
} catch (err) {
|
||||||
|
wlogger.error('Error in ipfs/controller.js/connect():', err)
|
||||||
|
// ctx.throw(422, err.message)
|
||||||
|
this.handleError(ctx, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// DRY error handler
|
// DRY error handler
|
||||||
handleError (ctx, err) {
|
handleError (ctx, err) {
|
||||||
// If an HTTP status is specified by the buisiness logic, use that.
|
// If an HTTP status is specified by the buisiness logic, use that.
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ class IpfsRouter {
|
|||||||
this.router.get('/', this.ipfsRESTController.getStatus)
|
this.router.get('/', this.ipfsRESTController.getStatus)
|
||||||
this.router.post('/peers', this.ipfsRESTController.getPeers)
|
this.router.post('/peers', this.ipfsRESTController.getPeers)
|
||||||
this.router.post('/relays', this.ipfsRESTController.getRelays)
|
this.router.post('/relays', this.ipfsRESTController.getRelays)
|
||||||
|
this.router.post('/connect', this.ipfsRESTController.connect)
|
||||||
|
|
||||||
// Attach the Controller routes to the Koa app.
|
// Attach the Controller routes to the Koa app.
|
||||||
app.use(this.router.routes())
|
app.use(this.router.routes())
|
||||||
|
|||||||
@@ -150,6 +150,41 @@ describe('#IPFS REST API', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('#POST /connect', () => {
|
||||||
|
it('should return 422 status on biz logic error', async () => {
|
||||||
|
try {
|
||||||
|
// Force an error
|
||||||
|
sandbox.stub(uut.adapters.ipfs.ipfsCoordAdapter.ipfsCoord.adapters.ipfs, 'connectToPeer').rejects(new Error('test error'))
|
||||||
|
|
||||||
|
ctx.request.body = {
|
||||||
|
multiaddr: '/ip4/161.35.99.207/tcp/4001/p2p/12D3KooWDtj9cfj1SKuLbDNKvKRKSsGN8qivq9M8CYpLPDpcD5pu'
|
||||||
|
}
|
||||||
|
|
||||||
|
await uut.connect(ctx)
|
||||||
|
|
||||||
|
assert.fail('Unexpected result')
|
||||||
|
} catch (err) {
|
||||||
|
assert.equal(err.status, 422)
|
||||||
|
assert.include(err.message, 'test error')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should return 200 status on success', async () => {
|
||||||
|
// Mock dependencies
|
||||||
|
sandbox.stub(uut.adapters.ipfs.ipfsCoordAdapter.ipfsCoord.adapters.ipfs, 'connectToPeer').resolves({ success: true })
|
||||||
|
|
||||||
|
ctx.request.body = {
|
||||||
|
multiaddr: '/ip4/161.35.99.207/tcp/4001/p2p/12D3KooWDtj9cfj1SKuLbDNKvKRKSsGN8qivq9M8CYpLPDpcD5pu'
|
||||||
|
}
|
||||||
|
|
||||||
|
await uut.connect(ctx)
|
||||||
|
// console.log('ctx.body: ', ctx.body)
|
||||||
|
|
||||||
|
assert.property(ctx.body, 'success')
|
||||||
|
assert.equal(ctx.body.success, true)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('#handleError', () => {
|
describe('#handleError', () => {
|
||||||
it('should still throw error if there is no message', () => {
|
it('should still throw error if there is no message', () => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -15,6 +15,11 @@ class IpfsAdapter {
|
|||||||
class IpfsCoordAdapter {
|
class IpfsCoordAdapter {
|
||||||
constructor () {
|
constructor () {
|
||||||
this.ipfsCoord = {
|
this.ipfsCoord = {
|
||||||
|
adapters: {
|
||||||
|
ipfs: {
|
||||||
|
connectToPeer: async () => {}
|
||||||
|
}
|
||||||
|
},
|
||||||
useCases: {
|
useCases: {
|
||||||
peer: {
|
peer: {
|
||||||
sendPrivateMessage: () => {}
|
sendPrivateMessage: () => {}
|
||||||
|
|||||||
Reference in New Issue
Block a user