Skip to content

Commit

Permalink
WIP change relays to use javascript
Browse files Browse the repository at this point in the history
  • Loading branch information
AnnaBlume99 committed Jul 12, 2023
1 parent 8f5f0c8 commit a64a500
Show file tree
Hide file tree
Showing 3 changed files with 248 additions and 59 deletions.
1 change: 1 addition & 0 deletions relay/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ start-relay:
./troupe-p2p-relay --key=keys/relay.priv

generate-relay-key:
mkdir -p keys
node $(TROUPE)/rt/built/p2p/mkid.mjs --privkeyfile=keys/relay.priv --idfile=keys/relay.id --verbose
46 changes: 46 additions & 0 deletions relay/relay.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { noise } from '@chainsafe/libp2p-noise'
import { yamux } from '@chainsafe/libp2p-yamux'
import { mplex } from '@libp2p/mplex'
import { webSockets } from '@libp2p/websockets'
import { createLibp2p } from 'libp2p'
import { circuitRelayServer } from 'libp2p/circuit-relay'
import { identifyService } from 'libp2p/identify'
import { createFromJSON } from '@libp2p/peer-id-factory'

async function main () {
const id = await createFromJSON({id : "12D3KooWShh9qmeS1UEgwWpjAsrjsigu8UGh8DRKyx1UG6HeHzjf",
privKey : "CAESQEQ7HBed1HEMpRHdhDmsJOlzHsVNBEWVc7DjEzuQtElv+uET7jQtZlGNKpltf2w4P7UqMdSYm4cYAGzjHcGcSj4="});
const node = await createLibp2p({
peerId : id,
addresses: {
listen: ['/ip4/0.0.0.0/tcp/5555/ws']
// TODO check "What is next?" section
// announce: ['/dns4/auto-relay.libp2p.io/tcp/443/wss/p2p/QmWDn2LY8nannvSWJzruUYoLZ4vV83vfCBwd8DipvdgQc3']
},
transports: [
webSockets()
],
connectionEncryption: [
noise()
],
streamMuxers: [
yamux(),
mplex()
],
services: {
identify: identifyService(),
relay: circuitRelayServer()
}
})

await node.handle("/trouperelay/keepalive", async ({ connection, stream }) => {
console.log(`Relay handling protocol, id: ${connection.remotePeer}`)
//setupConnection(connection.remotePeer, stream)
})

console.log(`Node started with id ${node.peerId.toString()}`)
console.log('Listening on:')
node.getMultiaddrs().forEach((ma) => console.log(ma.toString()))
}

main()
Loading

0 comments on commit a64a500

Please sign in to comment.