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

fix!: remove gossipsub from default libp2p services #401

Merged
merged 2 commits into from
Jan 24, 2024
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
1 change: 0 additions & 1 deletion packages/helia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
"prepublishOnly": "node scripts/update-version.js && npm run build"
},
"dependencies": {
"@chainsafe/libp2p-gossipsub": "^11.0.0",
"@chainsafe/libp2p-noise": "^15.0.0",
"@chainsafe/libp2p-yamux": "^6.0.1",
"@helia/block-brokers": "^1.0.0",
Expand Down
6 changes: 1 addition & 5 deletions packages/helia/src/utils/libp2p-defaults.browser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { gossipsub } from '@chainsafe/libp2p-gossipsub'
import { noise } from '@chainsafe/libp2p-noise'
import { yamux } from '@chainsafe/libp2p-yamux'
import { createDelegatedRoutingV1HttpApiClient } from '@helia/delegated-routing-v1-http-api-client'
Expand All @@ -20,7 +19,6 @@ import * as libp2pInfo from 'libp2p/version'
import { name, version } from '../version.js'
import { bootstrapConfig } from './bootstrappers.js'
import type { Libp2pDefaultsOptions } from './libp2p.js'
import type { PubSub } from '@libp2p/interface'
import type { Libp2pOptions } from 'libp2p'

export interface DefaultLibp2pServices extends Record<string, unknown> {
Expand All @@ -31,7 +29,6 @@ export interface DefaultLibp2pServices extends Record<string, unknown> {
identify: Identify
keychain: Keychain
ping: PingService
pubsub: PubSub
}

export function libp2pDefaults (options: Libp2pDefaultsOptions = {}): Libp2pOptions<DefaultLibp2pServices> {
Expand Down Expand Up @@ -78,8 +75,7 @@ export function libp2pDefaults (options: Libp2pDefaultsOptions = {}): Libp2pOpti
agentVersion: `${name}/${version} ${libp2pInfo.name}/${libp2pInfo.version} UserAgent=${globalThis.navigator.userAgent}`
}),
keychain: keychain(options.keychain),
ping: ping(),
pubsub: gossipsub()
ping: ping()
}
}
}
4 changes: 0 additions & 4 deletions packages/helia/src/utils/libp2p-defaults.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { gossipsub } from '@chainsafe/libp2p-gossipsub'
import { noise } from '@chainsafe/libp2p-noise'
import { yamux } from '@chainsafe/libp2p-yamux'
import { createDelegatedRoutingV1HttpApiClient } from '@helia/delegated-routing-v1-http-api-client'
Expand All @@ -22,7 +21,6 @@ import * as libp2pInfo from 'libp2p/version'
import { name, version } from '../version.js'
import { bootstrapConfig } from './bootstrappers.js'
import type { Libp2pDefaultsOptions } from './libp2p.js'
import type { PubSub } from '@libp2p/interface'
import type { Libp2pOptions } from 'libp2p'

export interface DefaultLibp2pServices extends Record<string, unknown> {
Expand All @@ -33,7 +31,6 @@ export interface DefaultLibp2pServices extends Record<string, unknown> {
identify: Identify
keychain: Keychain
ping: PingService
pubsub: PubSub
relay: CircuitRelayService
upnp: unknown
}
Expand Down Expand Up @@ -85,7 +82,6 @@ export function libp2pDefaults (options: Libp2pDefaultsOptions = {}): Libp2pOpti
}),
keychain: keychain(options.keychain),
ping: ping(),
pubsub: gossipsub(),
relay: circuitRelayServer({
advertise: true
}),
Expand Down
3 changes: 3 additions & 0 deletions packages/interop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"test:electron-main": "aegir test -t electron-main"
},
"dependencies": {
"@chainsafe/libp2p-gossipsub": "^11.1.0",
"@helia/block-brokers": "^1.0.0",
"@helia/car": "^2.0.1",
"@helia/dag-cbor": "^2.0.1",
Expand All @@ -73,6 +74,7 @@
"@ipld/dag-cbor": "^9.0.7",
"@libp2p/interface": "^1.1.1",
"@libp2p/kad-dht": "^12.0.2",
"@libp2p/keychain": "^4.0.7",
"@libp2p/peer-id": "^4.0.5",
"@libp2p/peer-id-factory": "^4.0.3",
"@libp2p/websockets": "^8.0.10",
Expand All @@ -89,6 +91,7 @@
"it-to-buffer": "^4.0.2",
"kubo": "^0.26.0",
"kubo-rpc-client": "^3.0.1",
"libp2p": "^1.2.0",
"multiformats": "^13.0.0",
"p-defer": "^4.0.0",
"uint8arrays": "^5.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/interop/src/fixtures/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Controller } from 'ipfsd-ctl'
/**
* Connect the two nodes by dialing a protocol stream
*/
export async function connect (helia: HeliaLibp2p, kubo: Controller, protocol: string): Promise<void> {
export async function connect (helia: HeliaLibp2p<any>, kubo: Controller, protocol: string): Promise<void> {
let connected = false
for (const addr of kubo.peer.addresses) {
try {
Expand Down
6 changes: 5 additions & 1 deletion packages/interop/src/fixtures/create-helia.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import { sha3512 } from '@multiformats/sha3'
import { createHelia, libp2pDefaults } from 'helia'
import type { Libp2p } from '@libp2p/interface'
import type { DefaultLibp2pServices, HeliaLibp2p } from 'helia'
import type { Libp2pOptions } from 'libp2p'

export async function createHeliaNode (): Promise<HeliaLibp2p<Libp2p<DefaultLibp2pServices>>> {
export async function createHeliaNode (): Promise<HeliaLibp2p<Libp2p<DefaultLibp2pServices>>>
export async function createHeliaNode <Services extends Record<string, unknown>> (libp2pOptions: Libp2pOptions<Services>): Promise<HeliaLibp2p<Libp2p<Services & DefaultLibp2pServices>>>
export async function createHeliaNode (libp2pOptions?: Libp2pOptions): Promise<HeliaLibp2p<Libp2p<DefaultLibp2pServices>>> {
const defaults = libp2pDefaults()

// allow dialing insecure WebSockets
Expand All @@ -28,6 +31,7 @@ export async function createHeliaNode (): Promise<HeliaLibp2p<Libp2p<DefaultLibp
// use LAN DHT
defaults.services = {
...(defaults.services ?? {}),
...(libp2pOptions?.services ?? {}),
dht: kadDHT({
validators: {
ipns: ipnsValidator
Expand Down
6 changes: 5 additions & 1 deletion packages/interop/src/fixtures/create-helia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import { sha3512 } from '@multiformats/sha3'
import { createHelia, libp2pDefaults } from 'helia'
import type { Libp2p } from '@libp2p/interface'
import type { DefaultLibp2pServices, HeliaLibp2p } from 'helia'
import type { Libp2pOptions } from 'libp2p'

export async function createHeliaNode (): Promise<HeliaLibp2p<Libp2p<DefaultLibp2pServices>>> {
export async function createHeliaNode (): Promise<HeliaLibp2p<Libp2p<DefaultLibp2pServices>>>
export async function createHeliaNode <Services extends Record<string, unknown>> (libp2pOptions: Libp2pOptions<Services>): Promise<HeliaLibp2p<Libp2p<Services & DefaultLibp2pServices>>>
export async function createHeliaNode (libp2pOptions?: Libp2pOptions): Promise<HeliaLibp2p<Libp2p<DefaultLibp2pServices>>> {
const defaults = libp2pDefaults()
defaults.addresses = {
listen: [
Expand All @@ -15,6 +18,7 @@ export async function createHeliaNode (): Promise<HeliaLibp2p<Libp2p<DefaultLibp
}
defaults.services = {
...(defaults.services ?? {}),
...(libp2pOptions?.services ?? {}),
dht: kadDHT({
validators: {
ipns: ipnsValidator
Expand Down
11 changes: 9 additions & 2 deletions packages/interop/src/ipns-pubsub.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-env mocha */
/* eslint max-nested-callbacks: ["error", 5] */

import { gossipsub } from '@chainsafe/libp2p-gossipsub'
import { ipns } from '@helia/ipns'
import { pubsub } from '@helia/ipns/routing'
import { peerIdFromKeys } from '@libp2p/peer-id'
Expand All @@ -20,6 +21,8 @@ import { createKuboNode } from './fixtures/create-kubo.js'
import { keyTypes } from './fixtures/key-types.js'
import { waitFor } from './fixtures/wait-for.js'
import type { IPNS } from '@helia/ipns'
import type { Libp2p, PubSub } from '@libp2p/interface'
import type { Keychain } from '@libp2p/keychain'
import type { HeliaLibp2p } from 'helia'
import type { Controller } from 'ipfsd-ctl'

Expand All @@ -30,12 +33,16 @@ const LIBP2P_KEY_CODEC = 0x72
// resolution because Kubo will use the DHT as well
keyTypes.filter(keyType => keyType !== 'RSA').forEach(keyType => {
describe(`@helia/ipns - pubsub routing with ${keyType} keys`, () => {
let helia: HeliaLibp2p
let helia: HeliaLibp2p<Libp2p<{ pubsub: PubSub, keychain: Keychain }>>
let kubo: Controller
let name: IPNS

beforeEach(async () => {
helia = await createHeliaNode()
helia = await createHeliaNode({
services: {
pubsub: gossipsub()
}
})
kubo = await createKuboNode()

// connect the two nodes
Expand Down
10 changes: 8 additions & 2 deletions packages/ipns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,18 @@ and multiple peers are listening on the topic(s), otherwise update messages
may fail to be published with "Insufficient peers" errors.

```typescript
import { createHelia } from 'helia'
import { createHelia, libp2pDefaults } from 'helia'
import { ipns } from '@helia/ipns'
import { pubsub } from '@helia/ipns/routing'
import { unixfs } from '@helia/unixfs'
import { gossipsub } from '@chainsafe/libp2p-gossipsub'

const helia = await createHelia()
const libp2pOptions = libp2pDefaults()
libp2pOptions.services.pubsub = gossipsub()

const helia = await createHelia({
libp2p: libp2pOptions
})
const name = ipns(helia, {
routers: [
pubsub(helia)
Expand Down
10 changes: 8 additions & 2 deletions packages/ipns/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,18 @@
* may fail to be published with "Insufficient peers" errors.
*
* ```typescript
* import { createHelia } from 'helia'
* import { createHelia, libp2pDefaults } from 'helia'
* import { ipns } from '@helia/ipns'
* import { pubsub } from '@helia/ipns/routing'
* import { unixfs } from '@helia/unixfs'
* import { gossipsub } from '@chainsafe/libp2p-gossipsub'
*
* const helia = await createHelia()
* const libp2pOptions = libp2pDefaults()
* libp2pOptions.services.pubsub = gossipsub()
*
* const helia = await createHelia({
* libp2p: libp2pOptions
* })
* const name = ipns(helia, {
* routers: [
* pubsub(helia)
Expand Down