initial commit
This commit is contained in:
commit
ce79c0150a
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
node_modules/
|
11
Dockerfile
Normal file
11
Dockerfile
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
FROM node:20-slim
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY index.js package*.json .
|
||||||
|
|
||||||
|
RUN npm install --production
|
||||||
|
|
||||||
|
EXPOSE 4000
|
||||||
|
|
||||||
|
CMD ["node", "index.js"]
|
52
index.js
Normal file
52
index.js
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
import { createLibp2p } from 'libp2p'
|
||||||
|
import { generateKeyPairFromSeed } from '@libp2p/crypto/keys'
|
||||||
|
import { webSockets } from '@libp2p/websockets'
|
||||||
|
import { circuitRelayServer, circuitRelayTransport } from '@libp2p/circuit-relay-v2'
|
||||||
|
import { noise } from '@chainsafe/libp2p-noise'
|
||||||
|
import { yamux } from '@chainsafe/libp2p-yamux'
|
||||||
|
import { identify } from '@libp2p/identify'
|
||||||
|
|
||||||
|
import { createHash } from 'crypto';
|
||||||
|
|
||||||
|
const publicMultiaddr = process.env.PUBLIC_MULTIADDR;
|
||||||
|
const seed = process.env.SEED;
|
||||||
|
|
||||||
|
if (typeof publicMultiaddr !== 'string' || !publicMultiaddr.length) {
|
||||||
|
console.log('no PUBLIC_MULTIADDR or invalid PUBLIC_MULTIADDR specified');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof seed !== 'string' || !seed.length) {
|
||||||
|
console.log('no SEED or invalid SEED specified');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const seedHash = createHash('sha512').update(seed).digest('base64');
|
||||||
|
const key = await generateKeyPairFromSeed('Ed25519', new TextEncoder().encode(seedHash).slice(0, 32));
|
||||||
|
|
||||||
|
const relay = await createLibp2p({
|
||||||
|
privateKey: key,
|
||||||
|
transports: [
|
||||||
|
webSockets(),
|
||||||
|
circuitRelayTransport(),
|
||||||
|
],
|
||||||
|
addresses: {
|
||||||
|
listen: [`/ip4/0.0.0.0/tcp/4000/ws`],
|
||||||
|
announce: [publicMultiaddr],
|
||||||
|
},
|
||||||
|
connectionEncrypters: [noise()],
|
||||||
|
streamMuxers: [yamux()],
|
||||||
|
services: {
|
||||||
|
identify: identify(),
|
||||||
|
relay: circuitRelayServer({
|
||||||
|
reservations: 512,
|
||||||
|
reservationTTL: 2 * 60 * 60 * 1000,
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
await relay.start()
|
||||||
|
|
||||||
|
console.log('Relay listening on:')
|
||||||
|
relay.getMultiaddrs().forEach(ma => console.log(ma.toString()))
|
1314
package-lock.json
generated
Normal file
1314
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
25
package.json
Normal file
25
package.json
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
"name": "libp2p-circuit-relay-v2",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"type": "module",
|
||||||
|
"dependencies": {
|
||||||
|
"@chainsafe/libp2p-noise": "^16.1.3",
|
||||||
|
"@chainsafe/libp2p-yamux": "^7.0.1",
|
||||||
|
"@libp2p/circuit-relay-v2": "^3.2.11",
|
||||||
|
"@libp2p/crypto": "^5.1.1",
|
||||||
|
"@libp2p/identify": "^3.0.29",
|
||||||
|
"@libp2p/kad-dht": "^15.0.2",
|
||||||
|
"@libp2p/ping": "^2.0.29",
|
||||||
|
"@libp2p/websockets": "^9.2.10",
|
||||||
|
"crypto": "^1.0.1",
|
||||||
|
"libp2p": "^2.8.5"
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user