mirror of
https://github.com/Permissionless-Software-Foundation/x402-base-facilitator.git
synced 2026-09-21 16:52:01 -07:00
Merge pull request #140 from Permissionless-Software-Foundation/ct-unstable
Removing Circuit Relay for nodes configured for direct connection
This commit is contained in:
Generated
+10323
-374
File diff suppressed because it is too large
Load Diff
@@ -33,6 +33,7 @@
|
|||||||
"@libp2p/keychain": "4.0.7",
|
"@libp2p/keychain": "4.0.7",
|
||||||
"@libp2p/logger": "4.0.5",
|
"@libp2p/logger": "4.0.5",
|
||||||
"@libp2p/tcp": "9.0.7",
|
"@libp2p/tcp": "9.0.7",
|
||||||
|
"@libp2p/webrtc": "4.0.17",
|
||||||
"axios": "0.27.2",
|
"axios": "0.27.2",
|
||||||
"bcryptjs": "2.4.3",
|
"bcryptjs": "2.4.3",
|
||||||
"blockstore-fs": "1.1.8",
|
"blockstore-fs": "1.1.8",
|
||||||
|
|||||||
@@ -158,6 +158,26 @@ class IpfsAdapter {
|
|||||||
console.log('Helia (IPFS) node IS NOT configured as Circuit Relay')
|
console.log('Helia (IPFS) node IS NOT configured as Circuit Relay')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Configure transports
|
||||||
|
let transports
|
||||||
|
if (process.env.CONNECT_PREF === 'direct') {
|
||||||
|
transports = [
|
||||||
|
tcp(),
|
||||||
|
webSockets(),
|
||||||
|
webRTC()
|
||||||
|
]
|
||||||
|
} else {
|
||||||
|
transports = [
|
||||||
|
tcp(),
|
||||||
|
webSockets(),
|
||||||
|
circuitRelayTransport({
|
||||||
|
discoverRelays: 3,
|
||||||
|
reservationConcurrency: 3
|
||||||
|
}),
|
||||||
|
webRTC()
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
// 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,
|
peerId,
|
||||||
@@ -170,15 +190,7 @@ class IpfsAdapter {
|
|||||||
'/webrtc'
|
'/webrtc'
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
transports: [
|
transports,
|
||||||
tcp(),
|
|
||||||
webSockets(),
|
|
||||||
circuitRelayTransport({
|
|
||||||
discoverRelays: 3,
|
|
||||||
reservationConcurrency: 3
|
|
||||||
}),
|
|
||||||
webRTC()
|
|
||||||
],
|
|
||||||
connectionEncryption: [
|
connectionEncryption: [
|
||||||
noise()
|
noise()
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ class IpfsRESTControllerLib {
|
|||||||
this.handleError = this.handleError.bind(this)
|
this.handleError = this.handleError.bind(this)
|
||||||
this.connect = this.connect.bind(this)
|
this.connect = this.connect.bind(this)
|
||||||
this.getThisNode = this.getThisNode.bind(this)
|
this.getThisNode = this.getThisNode.bind(this)
|
||||||
|
this.downloadFile = this.downloadFile.bind(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -123,6 +124,18 @@ class IpfsRESTControllerLib {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async downloadFile (ctx) {
|
||||||
|
try {
|
||||||
|
const { cid } = ctx.params
|
||||||
|
|
||||||
|
const file = await this.adapters.ipfs.ipfs.blockstore.get(cid)
|
||||||
|
return file
|
||||||
|
} catch (err) {
|
||||||
|
wlogger.error('Error in ipfs/controller.js/downloadFile(): ', err)
|
||||||
|
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.
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ class IpfsRouter {
|
|||||||
this.router.post('/relays', this.ipfsRESTController.getRelays)
|
this.router.post('/relays', this.ipfsRESTController.getRelays)
|
||||||
this.router.post('/connect', this.ipfsRESTController.connect)
|
this.router.post('/connect', this.ipfsRESTController.connect)
|
||||||
this.router.get('/node', this.ipfsRESTController.getThisNode)
|
this.router.get('/node', this.ipfsRESTController.getThisNode)
|
||||||
|
this.router.get('/download/:cid', this.ipfsRESTController.downloadFile)
|
||||||
|
|
||||||
// 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())
|
||||||
|
|||||||
Reference in New Issue
Block a user