Skip to content

Commit 1034416

Browse files
committed
refactor!: rename perf exports to remove Service (#2227)
Removes the redundant `Service` from perf exports in line with other changes to modules in v1. BREAKING CHANGE: the `perfService` export is now just `perf`
1 parent 57f077c commit 1034416

File tree

5 files changed

+57
-25
lines changed

5 files changed

+57
-25
lines changed

doc/migrations/v0.46-v1.0.0.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ A migration guide for refactoring your application code from libp2p `v0.46` to `
1212
- [Fetch](#fetch)
1313
- [KeyChain](#keychain)
1414
- [UPnPNat](#upnpnat)
15+
- [Perf](#perf)
1516
- [Plaintext](#plaintext)
1617
- [Pnet](#pnet)
1718
- [Metrics](#metrics)
@@ -225,6 +226,37 @@ const node = await createLibp2p({
225226
})
226227
```
227228

229+
## Perf
230+
231+
The Perf service module exports have been renamed in line with the other changes
232+
here.
233+
234+
**Before**
235+
236+
```ts
237+
import { createLibp2p } from 'libp2p'
238+
import { perService } from '@libp2p/perf'
239+
240+
const node = await createLibp2p({
241+
services: {
242+
perf: perService()
243+
}
244+
})
245+
```
246+
247+
**After**
248+
249+
```ts
250+
import { createLibp2p } from 'libp2p'
251+
import { perf } from '@libp2p/perf'
252+
253+
const node = await createLibp2p({
254+
services: {
255+
perf: perf()
256+
}
257+
})
258+
```
259+
228260
## Plaintext
229261

230262
The Plaintext connection encrypter module is now published in its own package.

packages/protocol-perf/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ import { mplex } from '@libp2p/mplex'
1818
import { tcp } from '@libp2p/tcp'
1919
import { createLibp2p, type Libp2p } from 'libp2p'
2020
import { plaintext } from '@libp2p/plaintext'
21-
import { perfService, type PerfService } from '@libp2p/perf'
21+
import { perf, type Perf } from '@libp2p/perf'
2222

2323
const ONE_MEG = 1024 * 1024
2424
const UPLOAD_BYTES = ONE_MEG * 1024
2525
const DOWNLOAD_BYTES = ONE_MEG * 1024
2626

27-
async function createNode (): Promise<Libp2p<{ perf: PerfService }>> {
27+
async function createNode (): Promise<Libp2p<{ perf: Perf }>> {
2828
return createLibp2p({
2929
addresses: {
3030
listen: [
@@ -41,7 +41,7 @@ async function createNode (): Promise<Libp2p<{ perf: PerfService }>> {
4141
yamux(), mplex()
4242
],
4343
services: {
44-
perf: perfService()
44+
perf: perf()
4545
}
4646
})
4747
}

packages/protocol-perf/src/index.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
* import { tcp } from '@libp2p/tcp'
1313
* import { createLibp2p, type Libp2p } from 'libp2p'
1414
* import { plaintext } from '@libp2p/plaintext'
15-
* import { perfService, type PerfService } from '@libp2p/perf'
15+
* import { perf, type Perf } from '@libp2p/perf'
1616
*
1717
* const ONE_MEG = 1024 * 1024
1818
* const UPLOAD_BYTES = ONE_MEG * 1024
1919
* const DOWNLOAD_BYTES = ONE_MEG * 1024
2020
*
21-
* async function createNode (): Promise<Libp2p<{ perf: PerfService }>> {
21+
* async function createNode (): Promise<Libp2p<{ perf: Perf }>> {
2222
* return createLibp2p({
2323
* addresses: {
2424
* listen: [
@@ -35,7 +35,7 @@
3535
* yamux(), mplex()
3636
* ],
3737
* services: {
38-
* perf: perfService()
38+
* perf: perf()
3939
* }
4040
* })
4141
* }
@@ -52,7 +52,7 @@
5252
* ```
5353
*/
5454

55-
import { PerfService as PerfServiceClass } from './perf-service.js'
55+
import { Perf as PerfClass } from './perf-service.js'
5656
import type { AbortOptions } from '@libp2p/interface'
5757
import type { ConnectionManager } from '@libp2p/interface-internal/connection-manager'
5858
import type { Registrar } from '@libp2p/interface-internal/registrar'
@@ -69,7 +69,7 @@ export interface PerfOptions extends AbortOptions {
6969
reuseExistingConnection?: boolean
7070
}
7171

72-
export interface PerfService {
72+
export interface Perf {
7373
measurePerformance(multiaddr: Multiaddr, sendBytes: number, recvBytes: number, options?: PerfOptions): AsyncGenerator<PerfOutput>
7474
}
7575

@@ -80,7 +80,7 @@ export interface PerfOutput {
8080
downloadBytes: number
8181
}
8282

83-
export interface PerfServiceInit {
83+
export interface PerfInit {
8484
protocolName?: string
8585
maxInboundStreams?: number
8686
maxOutboundStreams?: number
@@ -92,11 +92,11 @@ export interface PerfServiceInit {
9292
writeBlockSize?: number
9393
}
9494

95-
export interface PerfServiceComponents {
95+
export interface PerfComponents {
9696
registrar: Registrar
9797
connectionManager: ConnectionManager
9898
}
9999

100-
export function perfService (init: PerfServiceInit = {}): (components: PerfServiceComponents) => PerfService {
101-
return (components) => new PerfServiceClass(components, init)
100+
export function perf (init: PerfInit = {}): (components: PerfComponents) => Perf {
101+
return (components) => new PerfClass(components, init)
102102
}

packages/protocol-perf/src/perf-service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
import { logger } from '@libp2p/logger'
22
import { pushable } from 'it-pushable'
33
import { MAX_INBOUND_STREAMS, MAX_OUTBOUND_STREAMS, PROTOCOL_NAME, RUN_ON_TRANSIENT_CONNECTION, WRITE_BLOCK_SIZE } from './constants.js'
4-
import type { PerfOptions, PerfOutput, PerfServiceComponents, PerfServiceInit, PerfService as PerfServiceInterface } from './index.js'
4+
import type { PerfOptions, PerfOutput, PerfComponents, PerfInit, Perf as PerfInterface } from './index.js'
55
import type { Startable } from '@libp2p/interface/startable'
66
import type { IncomingStreamData } from '@libp2p/interface-internal/registrar'
77
import type { Multiaddr } from '@multiformats/multiaddr'
88

99
const log = logger('libp2p:perf')
1010

11-
export class PerfService implements Startable, PerfServiceInterface {
11+
export class Perf implements Startable, PerfInterface {
1212
public readonly protocol: string
13-
private readonly components: PerfServiceComponents
13+
private readonly components: PerfComponents
1414
private started: boolean
1515
private readonly databuf: ArrayBuffer
1616
private readonly writeBlockSize: number
1717
private readonly maxInboundStreams: number
1818
private readonly maxOutboundStreams: number
1919
private readonly runOnTransientConnection: boolean
2020

21-
constructor (components: PerfServiceComponents, init: PerfServiceInit = {}) {
21+
constructor (components: PerfComponents, init: PerfInit = {}) {
2222
this.components = components
2323
this.started = false
2424
this.protocol = init.protocolName ?? PROTOCOL_NAME

packages/protocol-perf/test/index.spec.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,26 @@ import { expect } from 'aegir/chai'
77
import last from 'it-last'
88
import { duplexPair } from 'it-pair/duplex'
99
import { stubInterface, type StubbedInstance } from 'sinon-ts'
10-
import { PerfService } from '../src/perf-service.js'
10+
import { Perf } from '../src/perf-service.js'
1111
import type { Connection } from '@libp2p/interface/connection'
1212
import type { ConnectionManager } from '@libp2p/interface-internal/connection-manager'
1313
import type { Registrar } from '@libp2p/interface-internal/registrar'
1414

15-
interface StubbedPerfServiceComponents {
15+
interface StubbedPerfComponents {
1616
registrar: StubbedInstance<Registrar>
1717
connectionManager: StubbedInstance<ConnectionManager>
1818
}
1919

20-
export function createComponents (): StubbedPerfServiceComponents {
20+
export function createComponents (): StubbedPerfComponents {
2121
return {
2222
registrar: stubInterface<Registrar>(),
2323
connectionManager: stubInterface<ConnectionManager>()
2424
}
2525
}
2626

2727
describe('perf', () => {
28-
let localComponents: StubbedPerfServiceComponents
29-
let remoteComponents: StubbedPerfServiceComponents
28+
let localComponents: StubbedPerfComponents
29+
let remoteComponents: StubbedPerfComponents
3030

3131
beforeEach(async () => {
3232
localComponents = createComponents()
@@ -46,8 +46,8 @@ describe('perf', () => {
4646
})
4747

4848
it('should run perf', async () => {
49-
const client = new PerfService(localComponents)
50-
const server = new PerfService(remoteComponents)
49+
const client = new Perf(localComponents)
50+
const server = new Perf(remoteComponents)
5151

5252
await start(client)
5353
await start(server)
@@ -77,8 +77,8 @@ describe('perf', () => {
7777
})
7878

7979
it('should reuse existing connection', async () => {
80-
const client = new PerfService(localComponents)
81-
const server = new PerfService(remoteComponents)
80+
const client = new Perf(localComponents)
81+
const server = new Perf(remoteComponents)
8282

8383
await start(client)
8484
await start(server)

0 commit comments

Comments
 (0)