Skip to content

Commit

Permalink
experiment: try different js muxers and encrypters
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Nov 21, 2023
1 parent 9a4c969 commit 87e86e4
Show file tree
Hide file tree
Showing 17 changed files with 3,714 additions and 10 deletions.
16 changes: 8 additions & 8 deletions perf/impl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ QUIC_GO_SUBDIRS := $(wildcard quic-go/*/.)
JS_SUBDIRS := $(wildcard js-libp2p/*/.)

all: $(RUST_SUBDIRS) $(GO_SUBDIRS) $(HTTPS_SUBDIRS) $(QUIC_GO_SUBDIRS) $(JS_SUBDIRS)
$(RUST_SUBDIRS):
$(MAKE) -C $@
$(GO_SUBDIRS):
$(MAKE) -C $@
$(HTTPS_SUBDIRS):
$(MAKE) -C $@
$(QUIC_GO_SUBDIRS):
$(MAKE) -C $@
# $(RUST_SUBDIRS):
# $(MAKE) -C $@
# $(GO_SUBDIRS):
# $(MAKE) -C $@
# $(HTTPS_SUBDIRS):
# $(MAKE) -C $@
# $(QUIC_GO_SUBDIRS):
# $(MAKE) -C $@
$(JS_SUBDIRS):
$(MAKE) -C $@

Expand Down
12 changes: 12 additions & 0 deletions perf/impl/js-libp2p/v1.0-mplex-noise/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
DOCKER_IMAGE := node:20-alpine
DOCKER_RUN := docker run --rm -v "$(shell pwd)":/usr/src/myapp -w /usr/src/myapp $(DOCKER_IMAGE)

all: perf

perf:
$(DOCKER_RUN) npm ci

clean:
rm -rf node_modules

.PHONY: all clean perf
114 changes: 114 additions & 0 deletions perf/impl/js-libp2p/v1.0-mplex-noise/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import { noise } from '@chainsafe/libp2p-noise'
import { mplex } from '@chainsafe/libp2p-mplex'
import { tcp } from '@libp2p/tcp'
import { multiaddr } from '@multiformats/multiaddr'
import { createLibp2p } from 'libp2p'
import { perf } from '@libp2p/perf'
import { parseArgs } from 'node:util'

const argv = parseArgs({
options: {
'run-server': {
type: 'string',
default: 'false'
},
'server-address': {
type: 'string'
},
transport: {
type: 'string',
default: 'tcp'
},
'upload-bytes': {
type: 'string',
default: '0'
},
'download-bytes': {
type: 'string',
default: '0'
}
}
})

/**
* @param {boolean} runServer
* @param {string} serverIpAddress
* @param {string} transport
* @param {number} uploadBytes
* @param {number} downloadBytes
*/
export async function main (runServer, serverIpAddress, transport, uploadBytes, downloadBytes) {
const { host, port } = splitHostPort(serverIpAddress)

const config = {
//peerId,
transports: [tcp({
socket: {
noDelay: true
},
server: {
noDelay: true
}
})],
streamMuxers: [
mplex()
],
connectionEncryption: [
noise()
],
connectionManager: {
minConnections: 0
},
services: {
perf: perf()
}
}

if (runServer) {
Object.assign(config, {
addresses: {
listen: [
// #TODO: right now we only support tcp
`/ip4/${host}/tcp/${port}`
]
}
})
}

const node = await createLibp2p(config)

await node.start()

if (!runServer) {
for await (const output of node.services.perf.measurePerformance(multiaddr(`/ip4/${host}/tcp/${port}`), uploadBytes, downloadBytes)) {
// eslint-disable-next-line no-console
console.log(JSON.stringify(output))
}

await node.stop()
}
}

/**
* @param {string} address
* @returns { host: string, port?: string }
*/
function splitHostPort (address) {
try {
const parts = address.split(':')
const host = parts[0]
const port = parts[1]
return {
host,
port
}
} catch (error) {
throw Error('Invalid server address')
}
}

main(argv.values['run-server'] === 'true', argv.values['server-address'], argv.values.transport, Number(argv.values['upload-bytes']), Number(argv.values['download-bytes'])).catch((err) => {
// eslint-disable-next-line no-console
console.error(err)
process.exit(1)
})
Loading

0 comments on commit 87e86e4

Please sign in to comment.