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!: update to libp2p v1 deps #473

Merged
merged 1 commit into from
Dec 3, 2023
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
816 changes: 304 additions & 512 deletions package-lock.json

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,11 @@
},
"homepage": "https://github.com/ChainSafe/js-libp2p-gossipsub#readme",
"dependencies": {
"@libp2p/crypto": "^2.0.0",
"@libp2p/interface": "^0.1.4",
"@libp2p/interface-internal": "^0.1.0",
"@libp2p/logger": "^3.0.0",
"@libp2p/peer-id": "^3.0.0",
"@libp2p/pubsub": "^8.0.0",
"@libp2p/crypto": "^3.0.1",
"@libp2p/interface": "^1.0.1",
"@libp2p/interface-internal": "^1.0.1",
"@libp2p/peer-id": "^4.0.1",
"@libp2p/pubsub": "^9.0.0",
"@multiformats/multiaddr": "^12.1.3",
"abortable-iterator": "^5.0.1",
"denque": "^2.1.0",
Expand All @@ -92,10 +91,11 @@
"devDependencies": {
"@chainsafe/as-sha256": "^0.2.4",
"@dapplion/benchmark": "^0.2.4",
"@libp2p/floodsub": "^8.0.0",
"@libp2p/interface-compliance-tests": "^4.0.0",
"@libp2p/peer-id-factory": "^3.0.0",
"@libp2p/peer-store": "^9.0.0",
"@libp2p/floodsub": "^9.0.0",
"@libp2p/interface-compliance-tests": "^5.0.2",
"@libp2p/logger": "^4.0.1",
"@libp2p/peer-id-factory": "^4.0.0",
"@libp2p/peer-store": "^10.0.0",
"@types/node": "^17.0.21",
"aegir": "^41.0.0",
"datastore-core": "^9.1.1",
Expand Down
17 changes: 8 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { CustomEvent, TypedEventEmitter } from '@libp2p/interface/events'
import { StrictSign, StrictNoSign, TopicValidatorResult } from '@libp2p/interface/pubsub'
import { type Logger, logger } from '@libp2p/logger'
import { CustomEvent, TypedEventEmitter, StrictSign, StrictNoSign, TopicValidatorResult } from '@libp2p/interface'
import { peerIdFromBytes, peerIdFromString } from '@libp2p/peer-id'
import { pipe } from 'it-pipe'
import { pushable } from 'it-pushable'
Expand Down Expand Up @@ -62,18 +60,18 @@ import { getPublishConfigFromPeerId } from './utils/publishConfig.js'
import { removeFirstNItemsFromSet, removeItemsFromSet } from './utils/set.js'
import { SimpleTimeCache } from './utils/time-cache.js'
import type { GossipsubOptsSpec } from './config.js'
import type { Connection, Stream } from '@libp2p/interface/connection'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { Peer, PeerStore } from '@libp2p/interface/peer-store'
import type {
Connection, Stream, PeerId, Peer, PeerStore,
Message,
PublishResult,
PubSub,
PubSubEvents,
PubSubInit,
SubscriptionChangeData,
TopicValidatorFn
} from '@libp2p/interface/pubsub'
TopicValidatorFn,
Logger,
ComponentLogger
} from '@libp2p/interface'
import type { ConnectionManager } from '@libp2p/interface-internal/connection-manager'
import type { IncomingStreamData, Registrar } from '@libp2p/interface-internal/registrar'
import type { Multiaddr } from '@multiformats/multiaddr'
Expand Down Expand Up @@ -224,6 +222,7 @@ export interface GossipSubComponents {
peerStore: PeerStore
registrar: Registrar
connectionManager: ConnectionManager
logger: ComponentLogger
}

export class GossipSub extends TypedEventEmitter<GossipsubEvents> implements PubSub<GossipsubEvents> {
Expand Down Expand Up @@ -431,7 +430,7 @@ export class GossipSub extends TypedEventEmitter<GossipsubEvents> implements Pub
}

// From pubsub
this.log = logger(opts.debugName ?? 'libp2p:gossipsub')
this.log = components.logger.forComponent(opts.debugName ?? 'libp2p:gossipsub')

// Gossipsub

Expand Down
2 changes: 1 addition & 1 deletion src/metrics.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TopicValidatorResult } from '@libp2p/interface/pubsub'
import { TopicValidatorResult } from '@libp2p/interface'
import {
MessageStatus,
type PeerIdStr,
Expand Down
2 changes: 1 addition & 1 deletion src/score/peer-score-params.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CodeError } from '@libp2p/interface/errors'
import { CodeError } from '@libp2p/interface'
import { ERR_INVALID_PEER_SCORE_PARAMS } from './constants.js'

// This file defines PeerScoreParams and TopicScoreParams interfaces
Expand Down
2 changes: 1 addition & 1 deletion src/score/peer-score-thresholds.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CodeError } from '@libp2p/interface/errors'
import { CodeError } from '@libp2p/interface'
import { ERR_INVALID_PEER_SCORE_THRESHOLDS } from './constants.js'

// This file defines PeerScoreThresholds interface
Expand Down
2 changes: 1 addition & 1 deletion src/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { abortableSource } from 'abortable-iterator'
import { encode, decode } from 'it-length-prefixed'
import { pipe } from 'it-pipe'
import { pushable, type Pushable } from 'it-pushable'
import type { Stream } from '@libp2p/interface/connection'
import type { Stream } from '@libp2p/interface'
import type { Uint8ArrayList } from 'uint8arraylist'

interface OutboundStreamOpts {
Expand Down
4 changes: 1 addition & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { type Message, TopicValidatorResult } from '@libp2p/interface/pubsub'
import { type Message, TopicValidatorResult, type PrivateKey, type PeerId } from '@libp2p/interface'
import type { RPC } from './message/rpc.js'
import type { PrivateKey } from '@libp2p/interface/keys'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { Multiaddr } from '@multiformats/multiaddr'

export type MsgIdStr = string
Expand Down
4 changes: 1 addition & 3 deletions src/utils/buildRawMessage.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { randomBytes } from '@libp2p/crypto'
import { marshalPublicKey, unmarshalPublicKey } from '@libp2p/crypto/keys'
import { StrictSign, StrictNoSign, type Message } from '@libp2p/interface/pubsub'
import { StrictSign, StrictNoSign, type Message, type PublicKey, type PeerId } from '@libp2p/interface'
import { peerIdFromBytes } from '@libp2p/peer-id'
import { concat as uint8ArrayConcat } from 'uint8arrays/concat'
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
import { RPC } from '../message/rpc.js'
import { type PublishConfig, PublishConfigType, type TopicStr, ValidateError } from '../types.js'
import type { PublicKey } from '@libp2p/interface/keys'
import type { PeerId } from '@libp2p/interface/peer-id'

export const SignPrefix = uint8ArrayFromString('libp2p-pubsub:')

Expand Down
2 changes: 1 addition & 1 deletion src/utils/msgIdFn.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { msgId } from '@libp2p/pubsub/utils'
import { sha256 } from 'multiformats/hashes/sha2'
import type { Message } from '@libp2p/interface/pubsub'
import type { Message } from '@libp2p/interface'

/**
* Generate a message id, based on the `key` and `seqno`
Expand Down
4 changes: 2 additions & 2 deletions src/utils/publishConfig.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { unmarshalPrivateKey } from '@libp2p/crypto/keys'
import { StrictSign, StrictNoSign } from '@libp2p/interface/pubsub'
import { StrictSign, StrictNoSign } from '@libp2p/interface'
import { type PublishConfig, PublishConfigType } from '../types.js'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { PeerId } from '@libp2p/interface'

/**
* Prepare a PublishConfig object from a PeerId.
Expand Down
4 changes: 2 additions & 2 deletions test/2-nodes.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { stop } from '@libp2p/interface/startable'
import { stop } from '@libp2p/interface'
import { mockNetwork } from '@libp2p/interface-compliance-tests/mocks'
import { expect } from 'aegir/chai'
import defer from 'p-defer'
Expand All @@ -12,7 +12,7 @@ import {
createComponentsArray,
type GossipSubAndComponents
} from './utils/create-pubsub.js'
import type { Message, SubscriptionChangeData } from '@libp2p/interface/pubsub'
import type { Message, SubscriptionChangeData } from '@libp2p/interface'

const shouldNotHappen = (): never => expect.fail()

Expand Down
6 changes: 4 additions & 2 deletions test/accept-from.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { type PeerStore } from '@libp2p/interface'
import { defaultLogger } from '@libp2p/logger'
import { expect } from 'aegir/chai'
import sinon from 'sinon'
import { stubInterface } from 'ts-sinon'
import { GossipSub } from '../src/index.js'
import { createPeerId } from './utils/index.js'
import { fastMsgIdFn } from './utils/msgId.js'
import type { PeerStore } from '@libp2p/interface/peer-store'
import type { ConnectionManager } from '@libp2p/interface-internal/connection-manager'
import type { Registrar } from '@libp2p/interface-internal/registrar'

Expand All @@ -26,7 +27,8 @@ describe('Gossipsub acceptFrom', () => {
peerId,
registrar: stubInterface<Registrar>(),
peerStore: stubInterface<PeerStore>(),
connectionManager: stubInterface<ConnectionManager>()
connectionManager: stubInterface<ConnectionManager>(),
logger: defaultLogger()
},
{ emitSelf: false, fastMsgIdFn }
)
Expand Down
2 changes: 1 addition & 1 deletion test/allowedTopics.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { stop } from '@libp2p/interface/startable'
import { stop } from '@libp2p/interface'
import { mockNetwork } from '@libp2p/interface-compliance-tests/mocks'
import { expect } from 'aegir/chai'
import { pEvent } from 'p-event'
Expand Down
6 changes: 4 additions & 2 deletions test/compliance.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { TypedEventEmitter } from '@libp2p/interface/events'
import { TypedEventEmitter } from '@libp2p/interface'
import tests from '@libp2p/interface-compliance-tests/pubsub'
import { defaultLogger } from '@libp2p/logger'
import { PersistentPeerStore } from '@libp2p/peer-store'
import { MemoryDatastore } from 'datastore-core'
import { GossipSub } from '../src/index.js'
Expand All @@ -20,7 +21,8 @@ describe.skip('interface compliance', function () {
peerStore: new PersistentPeerStore({
peerId: args.components.peerId,
datastore: new MemoryDatastore(),
events: new TypedEventEmitter<Libp2pEvents>()
events: new TypedEventEmitter<Libp2pEvents>(),
logger: defaultLogger()
})
},
{
Expand Down
5 changes: 2 additions & 3 deletions test/e2e/go-gossipsub.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FloodSub } from '@libp2p/floodsub'
import { type Message, TopicValidatorResult } from '@libp2p/interface/pubsub'
import { stop } from '@libp2p/interface/startable'
import { type Message, TopicValidatorResult, type Libp2pEvents } from '@libp2p/interface'
import { stop } from '@libp2p/interface'
import { mockNetwork } from '@libp2p/interface-compliance-tests/mocks'
import { expect } from 'aegir/chai'
import delay from 'delay'
Expand All @@ -22,7 +22,6 @@ import { awaitEvents, checkReceivedSubscription, checkReceivedSubscriptions } fr
import { fastMsgIdFn } from '../utils/index.js'
import type { IRPC, RPC } from '../../src/message/rpc.js'
import type { TopicScoreParams } from '../../src/score/peer-score-params.js'
import type { Libp2pEvents } from '@libp2p/interface'

/**
* These tests were translated from:
Expand Down
4 changes: 2 additions & 2 deletions test/floodsub.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { FloodSub } from '@libp2p/floodsub'
import { stop } from '@libp2p/interface/startable'
import { stop } from '@libp2p/interface'
import { mockNetwork } from '@libp2p/interface-compliance-tests/mocks'
import { expect } from 'aegir/chai'
import delay from 'delay'
import { pEvent } from 'p-event'
import pRetry from 'p-retry'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import { connectPubsubNodes, createComponents, type GossipSubAndComponents } from './utils/create-pubsub.js'
import type { SubscriptionChangeData, Message } from '@libp2p/interface/pubsub'
import type { SubscriptionChangeData, Message } from '@libp2p/interface'

describe('gossipsub fallbacks to floodsub', () => {
describe('basics', () => {
Expand Down
8 changes: 5 additions & 3 deletions test/gossip.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { stop } from '@libp2p/interface/startable'
import { stop } from '@libp2p/interface'
import { mockNetwork } from '@libp2p/interface-compliance-tests/mocks'
import { defaultLogger } from '@libp2p/logger'
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
import { expect } from 'aegir/chai'
import { pEvent } from 'p-event'
Expand All @@ -9,7 +10,7 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import { GossipsubDhi } from '../src/constants.js'
import { GossipSub } from '../src/index.js'
import { connectAllPubSubNodes, createComponentsArray, type GossipSubAndComponents } from './utils/create-pubsub.js'
import type { PeerStore } from '@libp2p/interface/peer-store'
import type { PeerStore } from '@libp2p/interface'
import type { ConnectionManager } from '@libp2p/interface-internal/connection-manager'
import type { Registrar } from '@libp2p/interface-internal/registrar'

Expand Down Expand Up @@ -218,7 +219,8 @@ describe('gossip', () => {
peerId: await createEd25519PeerId(),
registrar,
peerStore: stubInterface<PeerStore>(),
connectionManager: stubInterface<ConnectionManager>()
connectionManager: stubInterface<ConnectionManager>(),
logger: defaultLogger()
},
{
maxInboundStreams,
Expand Down
2 changes: 1 addition & 1 deletion test/heartbeat.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { stop } from '@libp2p/interface/startable'
import { stop } from '@libp2p/interface'
import { mockNetwork } from '@libp2p/interface-compliance-tests/mocks'
import { expect } from 'aegir/chai'
import { pEvent } from 'p-event'
Expand Down
2 changes: 1 addition & 1 deletion test/mesh.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { stop } from '@libp2p/interface/startable'
import { stop } from '@libp2p/interface'
import { mockNetwork } from '@libp2p/interface-compliance-tests/mocks'
import { expect } from 'aegir/chai'
import delay from 'delay'
Expand Down
2 changes: 1 addition & 1 deletion test/signature-policy.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { stop } from '@libp2p/interface/startable'
import { stop } from '@libp2p/interface'
import { mockNetwork } from '@libp2p/interface-compliance-tests/mocks'
import { expect } from 'aegir/chai'
import { pEvent } from 'p-event'
Expand Down
14 changes: 8 additions & 6 deletions test/utils/create-pubsub.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { setMaxListeners } from 'events'
import { TypedEventEmitter, type TypedEventTarget } from '@libp2p/interface/events'
import { start } from '@libp2p/interface/startable'
import { TypedEventEmitter, start } from '@libp2p/interface'
import { mockRegistrar, mockConnectionManager, mockNetwork } from '@libp2p/interface-compliance-tests/mocks'
import { defaultLogger } from '@libp2p/logger'
import { createRSAPeerId } from '@libp2p/peer-id-factory'
import { PersistentPeerStore } from '@libp2p/peer-store'
import { MemoryDatastore } from 'datastore-core'
import { stubInterface } from 'ts-sinon'
import { GossipSub, type GossipSubComponents, type GossipsubOpts } from '../../src/index.js'
import type { Libp2pEvents } from '@libp2p/interface'
import type { PubSub } from '@libp2p/interface/pubsub'
import type { TypedEventTarget, Libp2pEvents, PubSub } from '@libp2p/interface'
import type { ConnectionManager } from '@libp2p/interface-internal/connection-manager'

export interface CreateComponentsOpts {
Expand All @@ -30,6 +29,7 @@ export const createComponents = async (opts: CreateComponentsOpts): Promise<Goss
const peerId = await createRSAPeerId({ bits: 512 })

const events = new TypedEventEmitter<Libp2pEvents>()
const logger = defaultLogger()

const components: GossipSubTestComponents = {
peerId,
Expand All @@ -38,9 +38,11 @@ export const createComponents = async (opts: CreateComponentsOpts): Promise<Goss
peerStore: new PersistentPeerStore({
peerId,
datastore: new MemoryDatastore(),
events
events,
logger
}),
events
events,
logger
}
components.connectionManager = mockConnectionManager(components)

Expand Down
3 changes: 1 addition & 2 deletions test/utils/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { expect } from 'aegir/chai'
import pWaitFor from 'p-wait-for'
import type { GossipSubAndComponents } from './create-pubsub.js'
import type { GossipsubEvents } from '../../src/index.js'
import type { TypedEventTarget } from '@libp2p/interface/events'
import type { SubscriptionChangeData } from '@libp2p/interface/pubsub'
import type { TypedEventTarget, SubscriptionChangeData } from '@libp2p/interface'

export const checkReceivedSubscription = async (
node: GossipSubAndComponents,
Expand Down
2 changes: 1 addition & 1 deletion test/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createEd25519PeerId } from '@libp2p/peer-id-factory'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import type { RPC } from '../../src/message/rpc.js'
import type { TopicStr } from '../../src/types.js'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { PeerId } from '@libp2p/interface'

export * from './msgId.js'

Expand Down
Loading