Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 0 additions & 162 deletions .github/workflows/main.yml

This file was deleted.

47 changes: 47 additions & 0 deletions .github/workflows/test-examples.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: test examples
on:
push:
branches:
- main
pull_request:
branches:
- "**"

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- run: npm i
working-directory: ./examples
- uses: ipfs/aegir/actions/cache-node-modules@master
with:
directories: |
./examples/node_modules

test-examples:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- uses: ipfs/aegir/actions/cache-node-modules@master
with:
directories: |
./examples/node_modules
- uses: actions/setup-go@v5
- run: go build -o test-runner main.go
working-directory: ./examples/test-runner
- run: ../test-runner/test-runner -hasProxy
working-directory: ./examples/go-libp2p-http-proxy
- run: ../test-runner/test-runner
working-directory: ./examples/js-libp2p-client-and-node-server/
- run: ../test-runner/test-runner
working-directory: ./examples/two-js-peers
- run: ./runTest.sh
working-directory: ./examples/peer-id-auth
58 changes: 58 additions & 0 deletions examples/go-libp2p-http-proxy/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* eslint-disable no-console */

import { noise } from '@chainsafe/libp2p-noise'
import { yamux } from '@chainsafe/libp2p-yamux'
import { http } from '@libp2p/http-fetch'
import { tcp } from '@libp2p/tcp'
import { multiaddr } from '@multiformats/multiaddr'
import { createLibp2p } from 'libp2p'

const node = await createLibp2p({
// libp2p nodes are started by default, pass false to override this
start: false,
addresses: {
listen: []
},
transports: [tcp()],
connectionEncrypters: [noise()],
streamMuxers: [yamux()],
services: { http: http() }
})

// start libp2p
await node.start()
console.error('libp2p has started')

// Read server multiaddr from the command line
const serverAddr = process.argv[2]
if (!serverAddr) {
console.error('Please provide the server multiaddr as an argument')
process.exit(1)
}

let serverMA = multiaddr(serverAddr)

// check if this is an http transport multiaddr
const isHTTPTransport = serverMA.protos().find(p => p.name === 'http')
if (!isHTTPTransport && serverMA.getPeerId() === null) {
// Learn the peer id of the server. This lets us reuse the connection for all our HTTP requests.
// Otherwise js-libp2p will open a new connection for each request.
const conn = await node.dial(serverMA)
serverMA = serverMA.encapsulate(`/p2p/${conn.remotePeer.toString()}`)
}

console.error(`Making request to ${serverMA.toString()}`)
try {
const resp = await node.services.http.fetch(new Request(`multiaddr:${serverMA}`))
const respBody = await resp.text()
if (resp.status !== 200) {
throw new Error(`Unexpected status code: ${resp.status}`)
}
if (respBody !== 'Hello, World!') {
throw new Error(`Unexpected response body: ${respBody}`)
}
console.error('Got response:', respBody)
} finally {
// stop libp2p
await node.stop()
}
57 changes: 0 additions & 57 deletions examples/go-libp2p-http-proxy/client.mjs

This file was deleted.

18 changes: 18 additions & 0 deletions examples/go-libp2p-http-proxy/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* eslint-disable no-console */

import http from 'http'

const port = 55776

const server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' })
res.end('Hello, World!')
})

server.listen(port, () => {
console.error(`Server running at: http://localhost:${port}/`)
// Print multiaddr on stdout for test
console.error("Server's multiaddr is:")
console.log(`/dns4/localhost/tcp/${port}/http`)
console.log('') // Empty line to signal we have no more addresses (for test runner)
})
16 changes: 0 additions & 16 deletions examples/go-libp2p-http-proxy/server.mjs

This file was deleted.

Loading
Loading