Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: update @multiformats/multiaddr to 11.0.0 #128

Merged
merged 1 commit into from
Sep 21, 2022
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
4 changes: 2 additions & 2 deletions packages/libp2p-daemon-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/libp2p-daemon-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions packages/libp2p-daemon-client/src/dht.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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: []
}
}
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 5 additions & 4 deletions packages/libp2p-daemon-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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')
}
})
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions packages/libp2p-daemon-client/test/dht.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions packages/libp2p-daemon-client/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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!/)
})
})
})
4 changes: 2 additions & 2 deletions packages/libp2p-daemon-client/test/pubsub.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions packages/libp2p-daemon-client/test/stream.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion packages/libp2p-daemon-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion packages/libp2p-daemon-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 4 additions & 3 deletions packages/libp2p-daemon-server/src/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 }) => {
Expand Down
10 changes: 5 additions & 5 deletions packages/libp2p-daemon-server/test/index.spec.ts
Original file line number Diff line number Diff line change
@@ -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<Libp2p>()

const server = await createServer(multiaddr, libp2p)
const server = await createServer(ma, libp2p)

await server.start()

Expand All @@ -24,7 +24,7 @@ describe('server', () => {
it('should stop', async () => {
const libp2p = stubInterface<Libp2p>()

const server = await createServer(multiaddr, libp2p)
const server = await createServer(ma, libp2p)

await server.start()
await server.stop()
Expand All @@ -35,7 +35,7 @@ describe('server', () => {
it('should return multiaddrs', async () => {
const libp2p = stubInterface<Libp2p>()

const server = await createServer(multiaddr, libp2p)
const server = await createServer(ma, libp2p)

expect(() => server.getMultiaddr()).to.throw(/Not started/)

Expand Down
2 changes: 1 addition & 1 deletion packages/libp2p-daemon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 4 additions & 3 deletions packages/libp2p-daemon/src/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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) {
Expand All @@ -123,7 +124,7 @@ export default async function main (processArgs: string[]) {

export async function createLibp2pServer (listenAddr: Multiaddr, argv: any): Promise<Libp2pServer> {
// 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')
}
Expand Down