From 9c3e70dc2eb773e2b9411d78088c63486487ecc7 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 21 Sep 2022 10:46:49 +0100 Subject: [PATCH] deps: update @multiformats/multiaddr to 11.0.0 --- packages/libp2p-daemon-client/README.md | 4 ++-- packages/libp2p-daemon-client/package.json | 2 +- packages/libp2p-daemon-client/src/dht.ts | 6 +++--- packages/libp2p-daemon-client/src/index.ts | 9 +++++---- packages/libp2p-daemon-client/test/dht.spec.ts | 4 ++-- packages/libp2p-daemon-client/test/index.spec.ts | 14 +++++++------- packages/libp2p-daemon-client/test/pubsub.spec.ts | 4 ++-- packages/libp2p-daemon-client/test/stream.spec.ts | 4 ++-- packages/libp2p-daemon-server/README.md | 3 ++- packages/libp2p-daemon-server/package.json | 2 +- packages/libp2p-daemon-server/src/index.ts | 7 ++++--- packages/libp2p-daemon-server/test/index.spec.ts | 10 +++++----- packages/libp2p-daemon/package.json | 2 +- packages/libp2p-daemon/src/index.ts | 7 ++++--- 14 files changed, 41 insertions(+), 37 deletions(-) diff --git a/packages/libp2p-daemon-client/README.md b/packages/libp2p-daemon-client/README.md index aefccdbd..2c420efc 100644 --- a/packages/libp2p-daemon-client/README.md +++ b/packages/libp2p-daemon-client/README.md @@ -43,9 +43,9 @@ There are currently two implementations of the `libp2p-daemon`: ```js import { createClient } from '@libp2p/daemon-client' -import { Multiaddr } from '@multiformats/multiaddr' +import { multiaddr } from '@multiformats/multiaddr' -const serverAddr = new Multiaddr('/ip4/127.0.0.1/tcp/1234') +const serverAddr = multiaddr('/ip4/127.0.0.1/tcp/1234') const client = createClient(serverAddr) // interact with the daemon diff --git a/packages/libp2p-daemon-client/package.json b/packages/libp2p-daemon-client/package.json index 04d72cb5..871e8c24 100644 --- a/packages/libp2p-daemon-client/package.json +++ b/packages/libp2p-daemon-client/package.json @@ -140,7 +140,7 @@ "@libp2p/logger": "^2.0.0", "@libp2p/peer-id": "^1.1.10", "@libp2p/tcp": "^3.0.0", - "@multiformats/multiaddr": "^10.1.8", + "@multiformats/multiaddr": "^11.0.0", "err-code": "^3.0.1", "it-stream-types": "^1.0.4", "multiformats": "^9.6.4", diff --git a/packages/libp2p-daemon-client/src/dht.ts b/packages/libp2p-daemon-client/src/dht.ts index 739a861b..a495d011 100644 --- a/packages/libp2p-daemon-client/src/dht.ts +++ b/packages/libp2p-daemon-client/src/dht.ts @@ -1,5 +1,5 @@ import { CID } from 'multiformats/cid' -import { Multiaddr } from '@multiformats/multiaddr' +import { multiaddr } from '@multiformats/multiaddr' import errcode from 'err-code' import { Request, @@ -113,7 +113,7 @@ export class DHT { return { id: peerIdFromBytes(response.dht.peer.id), - multiaddrs: response.dht.peer.addrs.map((a) => new Multiaddr(a)), + multiaddrs: response.dht.peer.addrs.map((a) => multiaddr(a)), protocols: [] } } @@ -185,7 +185,7 @@ export class DHT { if (response.type === DHTResponse.Type.VALUE && response.peer != null && response.peer?.addrs != null) { yield { id: peerIdFromBytes(response.peer.id), - multiaddrs: response.peer.addrs.map((a) => new Multiaddr(a)), + multiaddrs: response.peer.addrs.map((a) => multiaddr(a)), protocols: [] } } else { diff --git a/packages/libp2p-daemon-client/src/index.ts b/packages/libp2p-daemon-client/src/index.ts index 8d95b1e0..20d3b01a 100644 --- a/packages/libp2p-daemon-client/src/index.ts +++ b/packages/libp2p-daemon-client/src/index.ts @@ -2,7 +2,8 @@ import errcode from 'err-code' import { TCP } from '@libp2p/tcp' import { PSMessage, Request, Response, StreamInfo } from '@libp2p/daemon-protocol' import { StreamHandler } from '@libp2p/daemon-protocol/stream-handler' -import { Multiaddr } from '@multiformats/multiaddr' +import type { Multiaddr } from '@multiformats/multiaddr' +import { multiaddr, isMultiaddr } from '@multiformats/multiaddr' import { DHT } from './dht.js' import { Pubsub } from './pubsub.js' import { isPeerId, PeerId } from '@libp2p/interface-peer-id' @@ -70,7 +71,7 @@ class Client implements DaemonClient { } addrs.forEach((addr) => { - if (!Multiaddr.isMultiaddr(addr)) { + if (!isMultiaddr(addr)) { throw errcode(new Error('received an address that is not a multiaddr'), 'ERR_NO_MULTIADDR_RECEIVED') } }) @@ -123,7 +124,7 @@ class Client implements DaemonClient { } const peerId = peerIdFromBytes(response.identify?.id) - const addrs = response.identify.addrs.map((a) => new Multiaddr(a)) + const addrs = response.identify.addrs.map((a) => multiaddr(a)) await sh.close() @@ -225,7 +226,7 @@ class Client implements DaemonClient { }) } }) - await listener.listen(new Multiaddr('/ip4/127.0.0.1/tcp/0')) + await listener.listen(multiaddr('/ip4/127.0.0.1/tcp/0')) const address = listener.getAddrs()[0] if (address == null) { diff --git a/packages/libp2p-daemon-client/test/dht.spec.ts b/packages/libp2p-daemon-client/test/dht.spec.ts index 0fce6f29..280d9c0c 100644 --- a/packages/libp2p-daemon-client/test/dht.spec.ts +++ b/packages/libp2p-daemon-client/test/dht.spec.ts @@ -5,14 +5,14 @@ import sinon from 'sinon' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { createServer, Libp2p, Libp2pServer } from '@libp2p/daemon-server' import { createClient, DaemonClient } from '../src/index.js' -import { Multiaddr } from '@multiformats/multiaddr' +import { multiaddr } from '@multiformats/multiaddr' import { StubbedInstance, stubInterface } from 'ts-sinon' import { DualDHT, ValueEvent, FinalPeerEvent, PeerResponseEvent, MessageType, EventTypes } from '@libp2p/interface-dht' import { peerIdFromString } from '@libp2p/peer-id' import { CID } from 'multiformats/cid' import all from 'it-all' -const defaultMultiaddr = new Multiaddr('/ip4/0.0.0.0/tcp/12345') +const defaultMultiaddr = multiaddr('/ip4/0.0.0.0/tcp/12345') describe('daemon dht client', function () { this.timeout(30e3) diff --git a/packages/libp2p-daemon-client/test/index.spec.ts b/packages/libp2p-daemon-client/test/index.spec.ts index 256186a2..1bd2eda3 100644 --- a/packages/libp2p-daemon-client/test/index.spec.ts +++ b/packages/libp2p-daemon-client/test/index.spec.ts @@ -4,14 +4,14 @@ import { expect } from 'aegir/chai' import sinon from 'sinon' import { createServer, Libp2p, Libp2pServer } from '@libp2p/daemon-server' import { createClient, DaemonClient } from '../src/index.js' -import { Multiaddr } from '@multiformats/multiaddr' +import { multiaddr } from '@multiformats/multiaddr' import { StubbedInstance, stubInterface } from 'ts-sinon' import { isPeerId } from '@libp2p/interface-peer-id' import { peerIdFromString } from '@libp2p/peer-id' import { mockConnection, mockDuplex, mockMultiaddrConnection } from '@libp2p/interface-mocks' import type { PeerStore, AddressBook } from '@libp2p/interface-peer-store' -const defaultMultiaddr = new Multiaddr('/ip4/0.0.0.0/tcp/0') +const defaultMultiaddr = multiaddr('/ip4/0.0.0.0/tcp/0') describe('daemon client', function () { this.timeout(30e3) @@ -44,7 +44,7 @@ describe('daemon client', function () { it('should be able to identify', async () => { libp2p.peerId = peerIdFromString('12D3KooWJKCJW8Y26pRFNv78TCMGLNTfyN8oKaFswMRYXTzSbSsa') libp2p.getMultiaddrs.returns([ - new Multiaddr('/ip4/0.0.0.0/tcp/1234/p2p/12D3KooWJKCJW8Y26pRFNv78TCMGLNTfyN8oKaFswMRYXTzSbSsa') + multiaddr('/ip4/0.0.0.0/tcp/1234/p2p/12D3KooWJKCJW8Y26pRFNv78TCMGLNTfyN8oKaFswMRYXTzSbSsa') ]) const identify = await client.identify() @@ -87,20 +87,20 @@ describe('daemon client', function () { describe('connect', () => { it('should be able to connect', async () => { const remotePeer = peerIdFromString('12D3KooWJKCJW8Y26pRFNv78TCMGLNTfyN8oKaFswMRYXTzSbSsa') - const multiaddr = new Multiaddr('/ip4/1.2.3.4/tcp/1234') + const ma = multiaddr('/ip4/1.2.3.4/tcp/1234') - await client.connect(remotePeer, [multiaddr]) + await client.connect(remotePeer, [ma]) expect(libp2p.dial.calledWith(remotePeer)).to.be.true() }) it('should error if receive an error message', async () => { const remotePeer = peerIdFromString('12D3KooWJKCJW8Y26pRFNv78TCMGLNTfyN8oKaFswMRYXTzSbSsa') - const multiaddr = new Multiaddr('/ip4/1.2.3.4/tcp/1234') + const ma = multiaddr('/ip4/1.2.3.4/tcp/1234') libp2p.dial.rejects(new Error('Urk!')) - await expect(client.connect(remotePeer, [multiaddr])).to.eventually.be.rejectedWith(/Urk!/) + await expect(client.connect(remotePeer, [ma])).to.eventually.be.rejectedWith(/Urk!/) }) }) }) diff --git a/packages/libp2p-daemon-client/test/pubsub.spec.ts b/packages/libp2p-daemon-client/test/pubsub.spec.ts index e455717a..10242e11 100644 --- a/packages/libp2p-daemon-client/test/pubsub.spec.ts +++ b/packages/libp2p-daemon-client/test/pubsub.spec.ts @@ -5,11 +5,11 @@ import sinon from 'sinon' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { createServer, Libp2p, Libp2pServer } from '@libp2p/daemon-server' import { createClient, DaemonClient } from '../src/index.js' -import { Multiaddr } from '@multiformats/multiaddr' +import { multiaddr } from '@multiformats/multiaddr' import { StubbedInstance, stubInterface } from 'ts-sinon' import type { PubSub } from '@libp2p/interface-pubsub' -const defaultMultiaddr = new Multiaddr('/ip4/0.0.0.0/tcp/12345') +const defaultMultiaddr = multiaddr('/ip4/0.0.0.0/tcp/12345') describe('daemon pubsub client', function () { this.timeout(30e3) diff --git a/packages/libp2p-daemon-client/test/stream.spec.ts b/packages/libp2p-daemon-client/test/stream.spec.ts index fcdfbd90..d3159a21 100644 --- a/packages/libp2p-daemon-client/test/stream.spec.ts +++ b/packages/libp2p-daemon-client/test/stream.spec.ts @@ -4,7 +4,7 @@ import { expect } from 'aegir/chai' import sinon from 'sinon' import { createServer, Libp2p, Libp2pServer } from '@libp2p/daemon-server' import { createClient, DaemonClient } from '../src/index.js' -import { Multiaddr } from '@multiformats/multiaddr' +import { multiaddr } from '@multiformats/multiaddr' import { StubbedInstance, stubInterface } from 'ts-sinon' import { peerIdFromString } from '@libp2p/peer-id' import { mockRegistrar, connectionPair } from '@libp2p/interface-mocks' @@ -15,7 +15,7 @@ import all from 'it-all' import { pipe } from 'it-pipe' import { Components } from '@libp2p/components' -const defaultMultiaddr = new Multiaddr('/ip4/0.0.0.0/tcp/0') +const defaultMultiaddr = multiaddr('/ip4/0.0.0.0/tcp/0') describe('daemon stream client', function () { this.timeout(50e3) diff --git a/packages/libp2p-daemon-server/README.md b/packages/libp2p-daemon-server/README.md index e8837e8e..2d749e3b 100644 --- a/packages/libp2p-daemon-server/README.md +++ b/packages/libp2p-daemon-server/README.md @@ -32,12 +32,13 @@ The specs for the daemon are currently housed in the go implementation. You can ```js import { createServer } from '@libp2p/daemon-server' import { createLibp2p } from 'libp2p' +import { multiaddr } from '@multiformats/multiaddr' const libp2p = await createLibp2p({ // ..config }) -const multiaddr = new Multiaddr('/ip4/0.0.0.0/tcp/0') +const multiaddr = multiaddr('/ip4/0.0.0.0/tcp/0') const server = await createServer(multiaddr, libp2p) await server.start() diff --git a/packages/libp2p-daemon-server/package.json b/packages/libp2p-daemon-server/package.json index 69c59c84..a1839d3b 100644 --- a/packages/libp2p-daemon-server/package.json +++ b/packages/libp2p-daemon-server/package.json @@ -148,7 +148,7 @@ "@libp2p/logger": "^2.0.0", "@libp2p/peer-id": "^1.1.10", "@libp2p/tcp": "^3.0.0", - "@multiformats/multiaddr": "^10.1.8", + "@multiformats/multiaddr": "^11.0.0", "it-drain": "^1.0.5", "it-length-prefixed": "^8.0.2", "it-pipe": "^2.0.3", diff --git a/packages/libp2p-daemon-server/src/index.ts b/packages/libp2p-daemon-server/src/index.ts index 5e91ec28..e48bbf46 100644 --- a/packages/libp2p-daemon-server/src/index.ts +++ b/packages/libp2p-daemon-server/src/index.ts @@ -1,7 +1,8 @@ /* eslint max-depth: ["error", 6] */ import { TCP } from '@libp2p/tcp' -import { Multiaddr, protocols } from '@multiformats/multiaddr' +import { multiaddr, protocols } from '@multiformats/multiaddr' +import type { Multiaddr } from '@multiformats/multiaddr' import { CID } from 'multiformats/cid' import * as lp from 'it-length-prefixed' import { pipe } from 'it-pipe' @@ -100,7 +101,7 @@ export class Server implements Libp2pServer { } const peer = request.connect.peer - const addrs = request.connect.addrs.map((a) => new Multiaddr(a)) + const addrs = request.connect.addrs.map((a) => multiaddr(a)) const peerId = peerIdFromBytes(peer) await this.libp2p.peerStore.addressBook.set(peerId, addrs) @@ -141,7 +142,7 @@ export class Server implements Libp2pServer { } const protocols = request.streamHandler.proto - const addr = new Multiaddr(request.streamHandler.addr) + const addr = multiaddr(request.streamHandler.addr) let conn: MultiaddrConnection await this.libp2p.handle(protocols, ({ connection, stream }) => { diff --git a/packages/libp2p-daemon-server/test/index.spec.ts b/packages/libp2p-daemon-server/test/index.spec.ts index 32856316..fc24faa2 100644 --- a/packages/libp2p-daemon-server/test/index.spec.ts +++ b/packages/libp2p-daemon-server/test/index.spec.ts @@ -1,18 +1,18 @@ /* eslint-env mocha */ /* eslint max-nested-callbacks: ["error", 5] */ -import { Multiaddr } from '@multiformats/multiaddr' +import { multiaddr } from '@multiformats/multiaddr' import { expect } from 'aegir/chai' import { createServer, Libp2p } from '../src/index.js' import { stubInterface } from 'ts-sinon' -const multiaddr = new Multiaddr('/ip4/0.0.0.0/tcp/0') +const ma = multiaddr('/ip4/0.0.0.0/tcp/0') describe('server', () => { it('should start', async () => { const libp2p = stubInterface() - const server = await createServer(multiaddr, libp2p) + const server = await createServer(ma, libp2p) await server.start() @@ -24,7 +24,7 @@ describe('server', () => { it('should stop', async () => { const libp2p = stubInterface() - const server = await createServer(multiaddr, libp2p) + const server = await createServer(ma, libp2p) await server.start() await server.stop() @@ -35,7 +35,7 @@ describe('server', () => { it('should return multiaddrs', async () => { const libp2p = stubInterface() - const server = await createServer(multiaddr, libp2p) + const server = await createServer(ma, libp2p) expect(() => server.getMultiaddr()).to.throw(/Not started/) diff --git a/packages/libp2p-daemon/package.json b/packages/libp2p-daemon/package.json index a5d3c82b..d43451f2 100644 --- a/packages/libp2p-daemon/package.json +++ b/packages/libp2p-daemon/package.json @@ -137,7 +137,7 @@ }, "dependencies": { "@libp2p/daemon-server": "^3.0.0", - "@multiformats/multiaddr": "^10.1.8", + "@multiformats/multiaddr": "^11.0.0", "es-main": "^1.0.2", "yargs": "^17.3.1", "yargs-promise": "^1.1.0" diff --git a/packages/libp2p-daemon/src/index.ts b/packages/libp2p-daemon/src/index.ts index 8cafda71..866fc109 100755 --- a/packages/libp2p-daemon/src/index.ts +++ b/packages/libp2p-daemon/src/index.ts @@ -1,7 +1,8 @@ #! /usr/bin/env node /* eslint no-console: ["error", { allow: ["log", "warn", "error"] }] */ -import { Multiaddr } from '@multiformats/multiaddr' +import type { Multiaddr } from '@multiformats/multiaddr' +import { multiaddr } from '@multiformats/multiaddr' import yargs from 'yargs' // @ts-expect-error no types import YargsPromise from 'yargs-promise' @@ -112,7 +113,7 @@ export default async function main (processArgs: string[]) { process.exit(0) } - const daemon = await createLibp2pServer(new Multiaddr(argv.listen), argv) + const daemon = await createLibp2pServer(multiaddr(argv.listen), argv) await daemon.start() if (argv.quiet !== true) { @@ -123,7 +124,7 @@ export default async function main (processArgs: string[]) { export async function createLibp2pServer (listenAddr: Multiaddr, argv: any): Promise { // const libp2p = await createLibp2p(argv) - // const daemon = await createServer(new Multiaddr(argv.listen), libp2p) + // const daemon = await createServer(multiaddr(argv.listen), libp2p) throw new Error('Not implemented yet') }