Skip to content

Commit

Permalink
refactor!: extract identify service into separate module (#2219)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: imports from `libp2p/identify` need to change to `@libp2p/identify`
  • Loading branch information
achingbrain committed Nov 15, 2023
1 parent 556282a commit 72c2f77
Show file tree
Hide file tree
Showing 46 changed files with 990 additions and 1,384 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ jobs:
- '@libp2p/tcp@$PWD/packages/transport-tcp'
- '@libp2p/websockets@$PWD/packages/transport-websockets'
- 'libp2p@$PWD/packages/libp2p'
- name: js-libp2p-example-circuit-relay
repo: https://github.com/libp2p/js-libp2p-example-circuit-relay.git
deps:
- '@libp2p/websockets@$PWD/packages/transport-websockets'
- 'libp2p@$PWD/packages/libp2p'
# disabled until @libp2p/identify and @libp2p/circuit-relay are published
# - name: js-libp2p-example-circuit-relay
# repo: https://github.com/libp2p/js-libp2p-example-circuit-relay.git
# deps:
# - '@libp2p/circuit-relay@$PWD/packages/transport-circuit-relay'
# - '@libp2p/identify@$PWD/packages/protocol-identify'
# - '@libp2p/websockets@$PWD/packages/transport-websockets'
# - 'libp2p@$PWD/packages/libp2p'
- name: js-libp2p-example-connection-encryption
repo: https://github.com/libp2p/js-libp2p-example-connection-encryption.git
deps:
Expand Down
1 change: 1 addition & 0 deletions .release-please.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"packages/peer-record": {},
"packages/peer-store": {},
"packages/protocol-autonat": {},
"packages/protocol-identify": {},
"packages/protocol-perf": {},
"packages/protocol-ping": {},
"packages/pubsub": {},
Expand Down
16 changes: 8 additions & 8 deletions doc/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ import { yamux } from '@chainsafe/libp2p-yamux'
import { noise } from '@chainsafe/libp2p-noise'
import { gossipsub } from 'libp2p-gossipsub'
import { SignaturePolicy } from '@libp2p/interface/pubsub'
import { identifyService } from 'libp2p/identify'
import { identify } from '@libp2p/identify'

const node = await createLibp2p({
transports: [
Expand All @@ -333,7 +333,7 @@ const node = await createLibp2p({
noise()
],
services: {
identify: identifyService(),
identify: identify(),
pubsub: gossipsub({
emitSelf: false, // whether the node should emit to self on publish
globalSignaturePolicy: SignaturePolicy.StrictSign // message signing policy
Expand All @@ -356,7 +356,7 @@ import { tcp } from '@libp2p/tcp'
import { mplex } from '@libp2p/mplex'
import { noise } from '@chainsafe/libp2p-noise'
import { kadDHT } from '@libp2p/kad-dht'
import { identifyService } from 'libp2p-identify'
import { identify } from '@libp2p/identify'

const node = await createLibp2p({
transports: [
Expand All @@ -370,7 +370,7 @@ const node = await createLibp2p({
noise()
],
services: {
identify: identifyService(),
identify: identify(),
dht: kadDHT({
kBucketSize: 20,
clientMode: false // Whether to run the WAN DHT in client or server mode (default: client mode)
Expand Down Expand Up @@ -444,7 +444,7 @@ import { mplex } from '@libp2p/mplex'
import { yamux } from '@chainsafe/libp2p-yamux'
import { noise } from '@chainsafe/libp2p-noise'
import { circuitRelayTransport, circuitRelayServer } from 'libp2p/circuit-relay'
import { identifyService } from 'libp2p-identify'
import { identify } from '@libp2p/identify'


const node = await createLibp2p({
Expand Down Expand Up @@ -473,7 +473,7 @@ const node = await createLibp2p({
denyInboundRelayedConnection: (relay: PeerId, remotePeer: PeerId) => Promise<boolean>
},
services: {
identify: identifyService(),
identify: identify(),
relay: circuitRelayServer({ // makes the node function as a relay server
hopTimeout: 30 * 1000, // incoming relay requests must be resolved within this time limit
advertise: true,
Expand Down Expand Up @@ -986,12 +986,12 @@ Changing the protocol name prefix can isolate default public network (IPFS) for

```js
import { createLibp2p } from 'libp2p'
import { identifyService } from 'libp2p/identify'
import { identify } from '@libp2p/identify'
import { ping } from 'libp2p/@ping'

const node = await createLibp2p({
services: {
identify: identifyService({
identify: identify({
protocolPrefix: 'ipfs' // default
}),
ping: ping({
Expand Down
31 changes: 31 additions & 0 deletions doc/migrations/v0.46-v1.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ A migration guide for refactoring your application code from libp2p `v0.46` to `

- [AutoNAT](#autonat)
- [Ping](#ping)
- [Identify](#identify)
- [KeyChain](#keychain)
- [UPnPNat](#upnpnat)
- [Pnet](#pnet)
Expand Down Expand Up @@ -72,6 +73,36 @@ const node = await createLibp2p({
})
```

## Identify

The Identify service is now published in its own package.

**Before**

```ts
import { createLibp2p } from 'libp2p'
import { identifyService } from 'libp2p/identify'

const node = await createLibp2p({
services: {
identify: identifyService()
}
})
```

**After**

```ts
import { createLibp2p } from 'libp2p'
import { identify } from '@libp2p/identify'

const node = await createLibp2p({
services: {
identify: identify()
}
})
```

## KeyChain

The KeyChain object is no longer included on Libp2p and must be instantiated explicitly if desired.
Expand Down
1 change: 1 addition & 0 deletions interop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"dependencies": {
"@chainsafe/libp2p-noise": "^13.0.0",
"@chainsafe/libp2p-yamux": "^5.0.0",
"@libp2p/identify": "^0.0.0",
"@libp2p/mplex": "^9.0.12",
"@libp2p/ping": "^0.0.0",
"@libp2p/tcp": "^8.0.13",
Expand Down
4 changes: 2 additions & 2 deletions interop/relay.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { noise } from '@chainsafe/libp2p-noise'
import { yamux } from '@chainsafe/libp2p-yamux'
import { identify } from '@libp2p/identify'
import { webSockets } from '@libp2p/websockets'
import * as filters from '@libp2p/websockets/filters'
import { createLibp2p } from 'libp2p'
import { circuitRelayServer } from 'libp2p/circuit-relay'
import { identifyService } from 'libp2p/identify'

export async function createRelay () {
const server = await createLibp2p({
Expand All @@ -19,7 +19,7 @@ export async function createRelay () {
connectionEncryption: [noise()],
streamMuxers: [yamux()],
services: {
identify: identifyService(),
identify: identify(),
relay: circuitRelayServer()
}
})
Expand Down
8 changes: 4 additions & 4 deletions interop/test/ping.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { } from 'aegir/chai'
import { noise } from '@chainsafe/libp2p-noise'
import { yamux } from '@chainsafe/libp2p-yamux'
import { type Identify, identify } from '@libp2p/identify'
import { mplex } from '@libp2p/mplex'
import { ping, type PingService } from '@libp2p/ping'
import { tcp } from '@libp2p/tcp'
Expand All @@ -14,7 +15,6 @@ import { webTransport } from '@libp2p/webtransport'
import { type Multiaddr, multiaddr } from '@multiformats/multiaddr'
import { createLibp2p, type Libp2p, type Libp2pOptions } from 'libp2p'
import { circuitRelayTransport } from 'libp2p/circuit-relay'
import { type IdentifyService, identifyService } from 'libp2p/identify'

async function redisProxy (commands: any[]): Promise<any> {
const res = await fetch(`http://localhost:${process.env.proxyPort ?? ''}/`, { body: JSON.stringify(commands), method: 'POST' })
Expand All @@ -24,7 +24,7 @@ async function redisProxy (commands: any[]): Promise<any> {
return res.json()
}

let node: Libp2p<{ ping: PingService, identify: IdentifyService }>
let node: Libp2p<{ ping: PingService, identify: Identify }>
const isDialer: boolean = process.env.is_dialer === 'true'
const timeoutSecs: string = process.env.test_timeout_secs ?? '180'

Expand All @@ -40,7 +40,7 @@ describe('ping test', function () {
const MUXER = process.env.muxer
const IP = process.env.ip ?? '0.0.0.0'

const options: Libp2pOptions<{ ping: PingService, identify: IdentifyService }> = {
const options: Libp2pOptions<{ ping: PingService, identify: Identify }> = {
start: true,
connectionManager: {
minConnections: 0
Expand All @@ -50,7 +50,7 @@ describe('ping test', function () {
},
services: {
ping: ping(),
identify: identifyService()
identify: identify()
}
}

Expand Down
3 changes: 3 additions & 0 deletions interop/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
{
"path": "../packages/libp2p"
},
{
"path": "../packages/protocol-identify"
},
{
"path": "../packages/protocol-ping"
},
Expand Down
1 change: 1 addition & 0 deletions packages/interface/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,4 @@ export class InvalidCryptoTransmissionError extends Error {

export const ERR_TIMEOUT = 'ERR_TIMEOUT'
export const ERR_INVALID_PARAMETERS = 'ERR_INVALID_PARAMETERS'
export const ERR_NOT_FOUND = 'ERR_NOT_FOUND'
4 changes: 2 additions & 2 deletions packages/libp2p/.aegir.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default {
const { createLibp2p } = await import('./dist/src/index.js')
const { plaintext } = await import('./dist/src/insecure/index.js')
const { circuitRelayServer, circuitRelayTransport } = await import('./dist/src/circuit-relay/index.js')
const { identifyService } = await import('./dist/src/identify/index.js')
const { identify } = await import('@libp2p/identify')
const { fetchService } = await import('./dist/src/fetch/index.js')

const peerId = await createEd25519PeerId()
Expand Down Expand Up @@ -45,7 +45,7 @@ export default {
plaintext()
],
services: {
identify: identifyService(),
identify: identify(),
fetch: fetchService(),
relay: circuitRelayServer({
reservations: {
Expand Down
8 changes: 2 additions & 6 deletions packages/libp2p/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@
"types": "./dist/src/fetch/index.d.ts",
"import": "./dist/src/fetch/index.js"
},
"./identify": {
"types": "./dist/src/identify/index.d.ts",
"import": "./dist/src/identify/index.js"
},
"./insecure": {
"types": "./dist/src/insecure/index.d.ts",
"import": "./dist/src/insecure/index.js"
Expand Down Expand Up @@ -142,8 +138,7 @@
"protons-runtime": "^5.0.0",
"rate-limiter-flexible": "^3.0.0",
"uint8arraylist": "^2.4.3",
"uint8arrays": "^4.0.6",
"wherearewe": "^2.0.1"
"uint8arrays": "^4.0.6"
},
"devDependencies": {
"@chainsafe/libp2p-gossipsub": "^10.0.0",
Expand All @@ -153,6 +148,7 @@
"@libp2p/daemon-client": "^7.0.0",
"@libp2p/daemon-server": "^6.0.0",
"@libp2p/floodsub": "^8.0.13",
"@libp2p/identify": "^0.0.0",
"@libp2p/interface-compliance-tests": "^4.1.5",
"@libp2p/interop": "^9.0.0",
"@libp2p/kad-dht": "^10.0.15",
Expand Down
4 changes: 2 additions & 2 deletions packages/libp2p/src/dcutr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* import { createLibp2p } from 'libp2p'
* import { circuitRelayTransport } from 'libp2p/circuit-relay'
* import { tcp } from '@libp2p/tcp'
* import { identifyService } from 'libp2p/identify'
* import { identify } from '@libp2p/identify'
* import { dCUtRService } from 'libp2p/dcutr'
*
* const node = await createLibp2p({
Expand All @@ -24,7 +24,7 @@
* tcp()
* ],
* services: {
* identify: identifyService(),
* identify: identify(),
* dcutr: dcutrService()
* }
* })
Expand Down
13 changes: 0 additions & 13 deletions packages/libp2p/src/identify/README.md

This file was deleted.

6 changes: 3 additions & 3 deletions packages/libp2p/test/circuit-relay/relay.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* eslint max-nested-callbacks: ['error', 6] */

import { yamux } from '@chainsafe/libp2p-yamux'
import { identify } from '@libp2p/identify'
import { mplex } from '@libp2p/mplex'
import { tcp } from '@libp2p/tcp'
import { Circuit } from '@multiformats/mafmt'
Expand All @@ -18,7 +19,6 @@ import { Uint8ArrayList } from 'uint8arraylist'
import { DEFAULT_DATA_LIMIT, RELAY_V2_HOP_CODEC } from '../../src/circuit-relay/constants.js'
import { circuitRelayServer, type CircuitRelayService, circuitRelayTransport } from '../../src/circuit-relay/index.js'
import { HopMessage, Status } from '../../src/circuit-relay/pb/index.js'
import { identifyService } from '../../src/identify/index.js'
import { createLibp2p, type Libp2pOptions } from '../../src/index.js'
import { plaintext } from '../../src/insecure/index.js'
import { discoveredRelayConfig, doesNotHaveRelay, getRelayAddress, hasRelay, notUsingAsRelay, usingAsRelay, usingAsRelayCount } from './utils.js'
Expand Down Expand Up @@ -46,7 +46,7 @@ async function createClient (options: Libp2pOptions = {}): Promise<Libp2p> {
minConnections: 0
},
services: {
identify: identifyService()
identify: identify()
},
...options
})
Expand All @@ -71,7 +71,7 @@ async function createRelay (options: Libp2pOptions = {}): Promise<Libp2p<{ relay
...options,
services: {
relay: circuitRelayServer(),
identify: identifyService(),
identify: identify(),
...(options.services ?? {})
}
})
Expand Down
6 changes: 3 additions & 3 deletions packages/libp2p/test/circuit-relay/relay.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
/* eslint max-nested-callbacks: ['error', 6] */

import { yamux } from '@chainsafe/libp2p-yamux'
import { identify } from '@libp2p/identify'
import { mplex } from '@libp2p/mplex'
import { webSockets } from '@libp2p/websockets'
import * as filters from '@libp2p/websockets/filters'
import { Circuit } from '@multiformats/mafmt'
import { expect } from 'aegir/chai'
import { pEvent } from 'p-event'
import { circuitRelayTransport } from '../../src/circuit-relay/index.js'
import { identifyService } from '../../src/identify/index.js'
import { createLibp2p } from '../../src/index.js'
import { plaintext } from '../../src/insecure/index.js'
import { hasRelay } from './utils.js'
Expand Down Expand Up @@ -41,7 +41,7 @@ describe('circuit-relay', () => {
denyDialMultiaddr: () => false
},
services: {
identify: identifyService()
identify: identify()
}
}),
createLibp2p({
Expand All @@ -67,7 +67,7 @@ describe('circuit-relay', () => {
denyDialMultiaddr: () => false
},
services: {
identify: identifyService()
identify: identify()
}
})
])
Expand Down
Loading

0 comments on commit 72c2f77

Please sign in to comment.