Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

Commit

Permalink
feat: add kubo-rpc-client (#499)
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtPooki authored Oct 6, 2022
1 parent 3ce12be commit d710daa
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 23 deletions.
12 changes: 9 additions & 3 deletions .aegir.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { resolve } from 'import-meta-resolve'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const ipfsModule = await resolve(process.env.IPFS_JS_HTTP_MODULE || 'ipfs', import.meta.url)
const ipfsHttpModule = await resolve(process.env.IPFS_JS_HTTP_MODULE || 'ipfs-http-client', import.meta.url)
const kuboRpcModule = await resolve(process.env.KUBO_RPC_MODULE || 'kubo-rpc-client', import.meta.url)

async function findGoIpfsBin () {
if (process.env.IPFS_GO_EXEC != null) {
Expand All @@ -32,6 +33,9 @@ const esbuild = {
build.onResolve({ filter: /^ipfs-http-client$/ }, () => {
return { path: ipfsHttpModule.replace('file://', '') }
})
build.onResolve({ filter: /^kubo-rpc-client$/ }, () => {
return { path: kuboRpcModule.replace('file://', '') }
})
}
}
]
Expand All @@ -47,6 +51,7 @@ export default {
},
async before (options) {
const ipfsHttpModule = await import(process.env.IPFS_JS_HTTP_MODULE || 'ipfs-http-client')
const kuboRpcModule = await import(process.env.KUBO_RPC_MODULE || 'kubo-rpc-client')
const ipfsModule = await import(process.env.IPFS_JS_MODULE || 'ipfs')

if (options.runner !== 'node') {
Expand All @@ -56,10 +61,10 @@ export default {
}, {
type: 'go',
test: true,
ipfsHttpModule
}, {
go: {
ipfsBin: await findGoIpfsBin()
ipfsBin: await findGoIpfsBin(),
kuboRpcModule: kuboRpcModule
},
js: {
ipfsOptions: {
Expand All @@ -72,7 +77,8 @@ export default {
}
},
ipfsModule,
ipfsBin: process.env.IPFS_JS_EXEC || ipfsModule.path()
ipfsBin: process.env.IPFS_JS_EXEC || ipfsModule.path(),
ipfsHttpModule,
}
}).start()

Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ $ node bin/ipfs-interop.js -- -t node --grep {substring-test-name}

### As a project

This module declares peer dependencies of `ipfs`, `ipfs-http-client` and `go-ipfs` so if you have `ipfs-interop` as a dependecy of your project, simply add the extra IPFS dependencies:
This module declares peer dependencies of `ipfs`, `ipfs-http-client`, `kubo-rpc-client` and `go-ipfs` so if you have `ipfs-interop` as a dependecy of your project, simply add the extra IPFS dependencies:

```json
{
Expand All @@ -61,7 +61,8 @@ This module declares peer dependencies of `ipfs`, `ipfs-http-client` and `go-ipf
"go-ipfs": "...",
"ipfs": "...",
"ipfs-http-client": "...",
"ipfs-interop": "..."
"ipfs-interop": "...",
"kubo-rpc-client": "..."
}
}
```
Expand All @@ -80,6 +81,7 @@ Specify the following environmental variables to control which versions of IPFS
- `IPFS_JS_EXEC` A path to `/src/cli.js` inside a js-IPFS install
- `IPFS_JS_MODULE` A path to a js-IPFS install
- `IPFS_JS_HTTP_MODULE` A path to a ipfs-http-client install (optional)
- `KUBO_RPC_MODULE` A path to a kubo-rpc-client install (optional)

Then run:

Expand All @@ -104,6 +106,7 @@ in `./scripts/custom-runtime.sh`, one can:
export IPFS_JS_EXEC=/tmp/js-ipfs/packages/ipfs/src/cli.js
export IPFS_JS_MODULE=/tmp/js-ipfs/packages/ipfs/src/index.js
export IPFS_JS_HTTP_MODULE=/tmp/js-ipfs/packages/ipfs-http-client/src/index.js
export KUBO_RPC_MODULE=/tmp/kubo-rpc-client/src/index.js
./scripts/custom-runtime.sh
node bin/ipfs-interop.js -- -t node --grep "pubsub"

Expand Down
73 changes: 65 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
"import-meta-resolve": "^2.0.3",
"ipfs-unixfs": "^7.0.0",
"ipfs-utils": "^9.0.1",
"ipfsd-ctl": "^12.0.0",
"ipfsd-ctl": "^12.2.0",
"ipns": "^3.0.0",
"is-ci": "^3.0.0",
"iso-random-stream": "^2.0.0",
Expand All @@ -206,7 +206,8 @@
"devDependencies": {
"go-ipfs": "^0.16.0",
"ipfs": "^0.64.2",
"ipfs-http-client": "^58.0.1"
"ipfs-http-client": "^58.0.1",
"kubo-rpc-client": "^1.0.1"
},
"browser": {
"go-ipfs": false,
Expand Down
1 change: 1 addition & 0 deletions scripts/custom-runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# export IPFS_JS_EXEC=/tmp/js-ipfs/packages/ipfs/src/cli.js
# export IPFS_JS_MODULE=/tmp/js-ipfs/packages/ipfs/src/index.js
# export IPFS_JS_HTTP_MODULE=/tmp/js-ipfs/packages/ipfs-http-client/src/index.js
# export KUBO_RPC_MODULE=/tmp/kubo-rpc-client/src/index.js
# ./scripts/custom-runtime.sh
# node bin/ipfs-interop.js -- -t node --grep "pubsub"

Expand Down
1 change: 1 addition & 0 deletions scripts/download-relay-daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const LIBP2P_RELAY_DAEMON_VERSION = 'v0.1.0'

/**
* avoid expensive fetch if file is already in cache
*
* @param {string} url
*/
async function cachingFetchAndVerify (url) {
Expand Down
1 change: 1 addition & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type CID = import('ipfsd-ctl/node_modules/multiformats/types/src/cid').CID
2 changes: 1 addition & 1 deletion test/exchange-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ describe('exchange files', function () {
})

/**
* @param {import('multiformats/cid').CID} cid
* @param {import('../src/types.js').CID} cid
* @param {Controller["api"]} ipfs
*/
async function countFiles (cid, ipfs) {
Expand Down
3 changes: 2 additions & 1 deletion test/utils/circuit.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { multiaddr } from '@multiformats/multiaddr'
/**
* @typedef {import('ipfsd-ctl').Controller} Controller
* @typedef {import('ipfsd-ctl').Factory} Factory
* @typedef {import('@libp2p/interface-transport').MultiaddrFilter} MultiaddrFilter
*/

export const randomWsAddr = '/ip4/127.0.0.1/tcp/0/ws'
Expand Down Expand Up @@ -44,7 +45,7 @@ export function createProc (addrs, factory, relay) {
libp2p: {
transports: [
new WebSockets({
filter: filters.all
filter: /** @type {MultiaddrFilter} */(/** @type {unknown} */(filters.all))
})
]
}
Expand Down
17 changes: 13 additions & 4 deletions test/utils/daemon-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { isNode, isElectronMain } from 'wherearewe'
export async function daemonFactory () {
let ipfsHttpModule
let ipfsModule
let kuboRpcModule

try {
// @ts-expect-error env var could be undefined
Expand All @@ -12,6 +13,13 @@ export async function daemonFactory () {
ipfsHttpModule = await import('ipfs-http-client')
}

try {
// @ts-expect-error env var could be undefined
kuboRpcModule = await import(process.env.KUBO_RPC_MODULE)
} catch {
kuboRpcModule = await import('kubo-rpc-client')
}

try {
// @ts-expect-error env var could be undefined
ipfsModule = await import(process.env.IPFS_JS_MODULE)
Expand All @@ -21,17 +29,18 @@ export async function daemonFactory () {

return createFactory({
type: 'go',
test: true,
ipfsHttpModule
test: true
}, {
proc: {
ipfsModule
},
js: {
ipfsBin: await findBin('IPFS_JS_EXEC', 'ipfs', ipfsModule)
ipfsBin: await findBin('IPFS_JS_EXEC', 'ipfs', ipfsModule),
ipfsHttpModule
},
go: {
ipfsBin: await findBin('IPFS_GO_EXEC', 'go-ipfs')
ipfsBin: await findBin('IPFS_GO_EXEC', 'go-ipfs'),
kuboRpcModule
}
})
}
Expand Down
4 changes: 3 additions & 1 deletion test/utils/relayd.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ export async function getRelayV (version) {
}
}

/**
* @type {Promise<string | undefined> & {cancel?: () => void}}
*/
const promise = waitForStartup()
// @ts-ignore
promise.cancel = () => {
console.error(`Timed out waiting for ${binaryPath} to start after ${RELAY_STARTUP_TIMEOUT}ms, killing process`) // eslint-disable-line no-console
relayd.kill()
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
"scripts",
"test"
]
}
}

0 comments on commit d710daa

Please sign in to comment.