Skip to content

Commit

Permalink
Merge branch 'master' into marco/js-libp2p-test-webkit
Browse files Browse the repository at this point in the history
  • Loading branch information
maschad committed May 31, 2023
2 parents 3da460d + 41641f1 commit ede58c6
Show file tree
Hide file tree
Showing 19 changed files with 650 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .aegir.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ export default {
})

return {
libp2p
libp2p,
env: {
RELAY_MULTIADDR: MULTIADDRS_WEBSOCKETS[0]
}
}
},
after: async (_, before) => {
Expand Down
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ChromiumDockerfile
Dockerfile
35 changes: 35 additions & 0 deletions .github/workflows/interop-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Interoperability Testing
on:
pull_request:
push:
branches:
- "master"

jobs:
run-multidim-interop:
name: Run multidimensional interoperability tests
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: ipfs/aegir/actions/cache-node-modules@master
with:
directories: |
./interop/node_modules
- name: Build interop
run: (cd interop && npm i && npm run build)
- name: Build images
run: (cd interop && make)
- name: Save package-lock.json as artifact
uses: actions/upload-artifact@v2
with:
name: package locks
path: |
package-lock.json
interop/package-lock.json
- uses: libp2p/test-plans/.github/actions/run-interop-ping-test@master
with:
test-filter: js-libp2p-head
extra-versions: ${{ github.workspace }}/interop/node-version.json ${{ github.workspace }}/interop/chromium-version.json ${{ github.workspace }}/interop/firefox-version.json
s3-cache-bucket: ${{ vars.S3_LIBP2P_BUILD_CACHE_BUCKET_NAME }}
s3-access-key-id: ${{ vars.S3_LIBP2P_BUILD_CACHE_AWS_ACCESS_KEY_ID }}
s3-secret-access-key: ${{ secrets.S3_LIBP2P_BUILD_CACHE_AWS_SECRET_ACCESS_KEY }}
5 changes: 5 additions & 0 deletions doc/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- [Modules](#modules)
- [Transport](#transport)
- [Stream Multiplexing](#stream-multiplexing)
- [Muxer Selection](#muxer-selection)
- [Connection Encryption](#connection-encryption)
- [Peer Discovery](#peer-discovery)
- [Content Routing](#content-routing)
Expand Down Expand Up @@ -89,6 +90,10 @@ Some available stream multiplexers are:
- [@libp2p/mplex](https://github.com/libp2p/js-libp2p-mplex)
- [@chainsafe/libp2p-yamux](https://github.com/chainsafe/js-libp2p-yamux)

Some transports such as WebRTC and WebTransport come with their own built-in stream multiplexing capabilities.

If you configure multiple muxers for use in your application, js-libp2p will choose the first muxer in the list. Therefore, ordering matters.

If none of the available stream multiplexers fulfills your needs, you can create a libp2p compatible stream multiplexer. A libp2p multiplexer just needs to be compliant with the [Stream Muxer Interface](https://github.com/libp2p/js-interfaces/tree/master/src/stream-muxer).

If you want to know more about libp2p stream multiplexing, you should read the following content:
Expand Down
79 changes: 79 additions & 0 deletions interop/.aegir.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { createClient } from 'redis'
import http from "http"

const redis_addr = process.env.redis_addr || 'redis:6379'

/** @type {import('aegir/types').PartialOptions} */
export default {
test: {
browser: {
config: {
// Ignore self signed certificates
browserContextOptions: { ignoreHTTPSErrors: true }
}
},
async before() {
const redisClient = createClient({
url: `redis://${redis_addr}`
})
redisClient.on('error', (err) => console.error(`Redis Client Error: ${err}`))
await redisClient.connect()

const requestListener = async function (req, res) {
const requestJSON = await new Promise(resolve => {
let body = ""
req.on('data', function (data) {
body += data;
});

req.on('end', function () {
resolve(JSON.parse(body))
});
})

try {
const redisRes = await redisClient.sendCommand(requestJSON)
if (redisRes === null) {
throw new Error("redis sent back null")
}

res.writeHead(200, {
'Access-Control-Allow-Origin': '*'
})
res.end(JSON.stringify(redisRes))
} catch (err) {
console.error("Error in redis command:", err)
res.writeHead(500, {
'Access-Control-Allow-Origin': '*'
})
res.end(err.toString())
return
}


};

const proxyServer = http.createServer(requestListener);
await new Promise(resolve => { proxyServer.listen(0, "localhost", () => { resolve() }); })

return {
redisClient,
proxyServer: proxyServer,
env: {
...process.env,
proxyPort: proxyServer.address().port
}
}
},
async after(_, { proxyServer, redisClient }) {
await new Promise(resolve => {
proxyServer.close(() => resolve());
})

try {
// We don't care if this fails
await redisClient.disconnect()
} catch { }
}
}
}
5 changes: 5 additions & 0 deletions interop/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dist
node-image.json
chromium-image.json
firefox-image.json
webkit-image.json
11 changes: 11 additions & 0 deletions interop/BrowserDockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# syntax=docker/dockerfile:1

FROM mcr.microsoft.com/playwright

COPY --from=node-js-libp2p-head /app/ /app/
WORKDIR /app/interop
RUN ./node_modules/.bin/playwright install
ARG BROWSER=chromium # Options: chromium, firefox, webkit
ENV BROWSER=$BROWSER

ENTRYPOINT npm test -- --build false --types false -t browser -- --browser $BROWSER
18 changes: 18 additions & 0 deletions interop/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM node:18
WORKDIR /app
COPY package.json .
COPY ./node_modules ./node_modules

WORKDIR /app/interop
COPY ./interop/node_modules ./node_modules

WORKDIR /app
COPY ./dist ./dist

WORKDIR /app/interop
COPY ./interop/dist ./dist

COPY ./interop/package.json .
COPY ./interop/.aegir.js .

ENTRYPOINT [ "npm", "test", "--", "--build", "false", "--types", "false", "-t", "node" ]
31 changes: 31 additions & 0 deletions interop/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
image_name := js-libp2p-head
TEST_SOURCES := $(wildcard test/*.ts)

# Enable webkit once https://github.com/libp2p/js-libp2p/pull/1627 is in
# all: node-image.json webkit-image.json firefox-image.json chromium-image.json
all: node-image.json firefox-image.json chromium-image.json

node-image.json: Dockerfile $(TEST_SOURCES) package.json .aegir.js
cd .. && docker build -f interop/Dockerfile -t node-${image_name} .
docker image inspect node-${image_name} -f "{{.Id}}" | \
xargs -I {} echo "{\"imageID\": \"{}\"}" > $@

chromium-image.json: node-image.json BrowserDockerfile $(TEST_SOURCES) package.json .aegir.js
cd .. && docker build -f interop/BrowserDockerfile --build-arg=BROWSER=chromium -t chromium-${image_name} .
docker image inspect chromium-${image_name} -f "{{.Id}}" | \
xargs -I {} echo "{\"imageID\": \"{}\"}" > $@

firefox-image.json: node-image.json BrowserDockerfile $(TEST_SOURCES) package.json .aegir.js
cd .. && docker build -f interop/BrowserDockerfile --build-arg=BROWSER=firefox -t firefox-${image_name} .
docker image inspect firefox-${image_name} -f "{{.Id}}" | \
xargs -I {} echo "{\"imageID\": \"{}\"}" > $@

webkit-image.json: node-image.json BrowserDockerfile $(TEST_SOURCES) package.json .aegir.js
cd .. && docker build -f interop/BrowserDockerfile --build-arg=BROWSER=webkit -t webkit-${image_name} .
docker image inspect webkit-${image_name} -f "{{.Id}}" | \
xargs -I {} echo "{\"imageID\": \"{}\"}" > $@

.PHONY: clean

clean:
rm *image.json
25 changes: 25 additions & 0 deletions interop/chromium-version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"id": "chromium-js-libp2p-head",
"containerImageID": "chromium-js-libp2p-head",
"transports": [
{
"name": "webtransport",
"onlyDial": true
},
{
"name": "webrtc",
"onlyDial": true
},
{
"name": "wss",
"onlyDial": true
}
],
"secureChannels": [
"noise"
],
"muxers": [
"mplex",
"yamux"
]
}
21 changes: 21 additions & 0 deletions interop/firefox-version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"id": "firefox-js-libp2p-head",
"containerImageID": "firefox-js-libp2p-head",
"transports": [
{
"name": "webrtc",
"onlyDial": true
},
{
"name": "wss",
"onlyDial": true
}
],
"secureChannels": [
"noise"
],
"muxers": [
"mplex",
"yamux"
]
}
19 changes: 19 additions & 0 deletions interop/node-version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"id": "node-js-libp2p-head",
"containerImageID": "node-js-libp2p-head",
"transports": [
"tcp",
"ws",
{
"name": "wss",
"onlyDial": true
}
],
"secureChannels": [
"noise"
],
"muxers": [
"mplex",
"yamux"
]
}
37 changes: 37 additions & 0 deletions interop/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "multidim-interop",
"private": true,
"version": "1.0.0",
"description": "Multidimension Interop Test",
"type": "module",
"main": "index.js",
"author": "Glen De Cauwsemaecker <glen@littlebearlabs.io> / @marcopolo",
"license": "MIT",
"engines": {
"node": ">=18"
},
"scripts": {
"start": "node index.js",
"build": "aegir build",
"test": "aegir test"
},
"dependencies": {
"@chainsafe/libp2p-noise": "^12.0.0",
"@chainsafe/libp2p-yamux": "^4.0.1",
"@libp2p/mplex": "^8.0.1",
"@libp2p/tcp": "^7.0.1",
"@libp2p/webrtc": "^2.0.2",
"@libp2p/websockets": "^6.0.1",
"@libp2p/webtransport": "^2.0.1",
"@multiformats/mafmt": "^12.1.2",
"@multiformats/multiaddr": "^12.1.3",
"libp2p": "../",
"redis": "4.5.1"
},
"browser": {
"@libp2p/tcp": false
},
"devDependencies": {
"aegir": "^39.0.5"
}
}
3 changes: 3 additions & 0 deletions interop/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
console.log("Everything is defined in the test folder")

export { }
Loading

0 comments on commit ede58c6

Please sign in to comment.