Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

Commit

Permalink
chore!: update deps (#164)
Browse files Browse the repository at this point in the history
Update to simpler connection api

BREAKING CHANGE: the connection API has changed
  • Loading branch information
achingbrain authored Jun 17, 2022
1 parent 9074c4a commit d474a81
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 96 deletions.
4 changes: 2 additions & 2 deletions .aegir.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Multiaddr } from '@multiformats/multiaddr'
import { multiaddr } from '@multiformats/multiaddr'
import { mockRegistrar, mockUpgrader } from '@libp2p/interface-mocks'
import { pipe }from 'it-pipe'

Expand All @@ -21,7 +21,7 @@ export default {
})

const ws = new WebSockets()
const ma = new Multiaddr('/ip4/127.0.0.1/tcp/9095/ws')
const ma = multiaddr('/ip4/127.0.0.1/tcp/9095/ws')
const listener = ws.createListener({
upgrader
})
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
"release": "aegir release"
},
"dependencies": {
"@libp2p/interface-connection": "^1.0.1",
"@libp2p/interface-connection": "^2.0.0",
"@libp2p/interface-transport": "^1.0.0",
"@libp2p/interfaces": "^3.0.1",
"@libp2p/logger": "^2.0.0",
Expand All @@ -170,8 +170,8 @@
"wherearewe": "^1.0.0"
},
"devDependencies": {
"@libp2p/interface-mocks": "^1.0.1",
"@libp2p/interface-transport-compliance-tests": "^1.0.0",
"@libp2p/interface-mocks": "^2.0.1",
"@libp2p/interface-transport-compliance-tests": "^2.0.0",
"@types/ws": "^8.2.2",
"aegir": "^37.2.0",
"is-loopback-addr": "^2.0.1",
Expand Down
5 changes: 3 additions & 2 deletions src/listener.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os from 'os'
import { Multiaddr, protocols } from '@multiformats/multiaddr'
import { multiaddr, protocols } from '@multiformats/multiaddr'
import { createServer } from 'it-ws/server'
import { logger } from '@libp2p/logger'
import { socketToMaConn } from './socket-to-conn.js'
Expand All @@ -10,6 +10,7 @@ import type { WebSocketServer } from 'it-ws/server'
import type { DuplexWebSocket } from 'it-ws/duplex'
import { EventEmitter, CustomEvent } from '@libp2p/interfaces/events'
import type { Connection } from '@libp2p/interface-connection'
import type { Multiaddr } from '@multiformats/multiaddr'

const log = logger('libp2p:websockets:listener')

Expand Down Expand Up @@ -137,7 +138,7 @@ class WebSocketListener extends EventEmitter<ListenerEvents> implements Listener

niInfos.forEach(ni => {
if (ni.family === 'IPv4') {
multiaddrs.push(new Multiaddr(m.toString().replace('0.0.0.0', ni.address)))
multiaddrs.push(multiaddr(m.toString().replace('0.0.0.0', ni.address)))
}
})
})
Expand Down
18 changes: 9 additions & 9 deletions test/browser.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-env mocha */

import { expect } from 'aegir/chai'
import { Multiaddr } from '@multiformats/multiaddr'
import { multiaddr } from '@multiformats/multiaddr'
import { pipe } from 'it-pipe'
import all from 'it-all'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
Expand All @@ -13,7 +13,7 @@ import type { Connection } from '@libp2p/interface-connection'
const protocol = '/echo/1.0.0'

describe('libp2p-websockets', () => {
const ma = new Multiaddr('/ip4/127.0.0.1/tcp/9095/ws')
const ma = multiaddr('/ip4/127.0.0.1/tcp/9095/ws')
let ws: WebSockets
let conn: Connection

Expand All @@ -28,7 +28,7 @@ describe('libp2p-websockets', () => {

it('echo', async () => {
const data = uint8ArrayFromString('hey')
const { stream } = await conn.newStream([protocol])
const stream = await conn.newStream([protocol])

const res = await pipe(
[data],
Expand All @@ -40,10 +40,10 @@ describe('libp2p-websockets', () => {
})

it('should filter out no DNS websocket addresses', function () {
const ma1 = new Multiaddr('/ip4/127.0.0.1/tcp/80/ws')
const ma2 = new Multiaddr('/ip4/127.0.0.1/tcp/443/wss')
const ma3 = new Multiaddr('/ip6/::1/tcp/80/ws')
const ma4 = new Multiaddr('/ip6/::1/tcp/443/wss')
const ma1 = multiaddr('/ip4/127.0.0.1/tcp/80/ws')
const ma2 = multiaddr('/ip4/127.0.0.1/tcp/443/wss')
const ma3 = multiaddr('/ip6/::1/tcp/80/ws')
const ma4 = multiaddr('/ip6/::1/tcp/443/wss')

const valid = ws.filter([ma1, ma2, ma3, ma4])

Expand All @@ -57,7 +57,7 @@ describe('libp2p-websockets', () => {
describe('stress', () => {
it('one big write', async () => {
const data = new Uint8Array(1000000).fill(5)
const { stream } = await conn.newStream([protocol])
const stream = await conn.newStream([protocol])

const res = await pipe(
[data],
Expand All @@ -73,7 +73,7 @@ describe('libp2p-websockets', () => {

const count = 20000
const data = Array(count).fill(0).map(() => uint8ArrayFromString(Math.random().toString()))
const { stream } = await conn.newStream([protocol])
const stream = await conn.newStream([protocol])

const res = await pipe(
data,
Expand Down
10 changes: 5 additions & 5 deletions test/compliance.node.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-env mocha */

import tests from '@libp2p/interface-transport-compliance-tests'
import { Multiaddr } from '@multiformats/multiaddr'
import { multiaddr } from '@multiformats/multiaddr'
import http from 'http'
import { WebSockets } from '../src/index.js'
import * as filters from '../src/filters.js'
Expand All @@ -12,10 +12,10 @@ describe('interface-transport compliance', () => {
async setup () {
const ws = new WebSockets({ filter: filters.all })
const addrs = [
new Multiaddr('/ip4/127.0.0.1/tcp/9091/ws'),
new Multiaddr('/ip4/127.0.0.1/tcp/9092/ws'),
new Multiaddr('/dns4/ipfs.io/tcp/9092/ws'),
new Multiaddr('/dns4/ipfs.io/tcp/9092/wss')
multiaddr('/ip4/127.0.0.1/tcp/9091/ws'),
multiaddr('/ip4/127.0.0.1/tcp/9092/ws'),
multiaddr('/dns4/ipfs.io/tcp/9092/ws'),
multiaddr('/dns4/ipfs.io/tcp/9092/wss')
]

let delayMs = 0
Expand Down
Loading

0 comments on commit d474a81

Please sign in to comment.