Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

deps!: bump @libp2p/interface-peer-store from 1.2.9 to 2.0.0 #171

Merged
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
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
"dependencies": {
"@libp2p/interface-peer-discovery": "^1.0.1",
"@libp2p/interface-peer-info": "^1.0.7",
"@libp2p/interface-peer-store": "^1.2.2",
"@libp2p/interface-peer-store": "^2.0.0",
"@libp2p/interfaces": "^3.0.3",
"@libp2p/logger": "^2.0.1",
"@libp2p/peer-id": "^2.0.0",
Expand All @@ -151,10 +151,7 @@
"devDependencies": {
"@libp2p/interface-peer-discovery-compliance-tests": "^2.0.0",
"@libp2p/interface-peer-id": "^2.0.0",
"@libp2p/peer-id-factory": "^2.0.0",
"@libp2p/peer-store": "^7.0.0",
"aegir": "^38.1.7",
"datastore-core": "^9.0.3",
"delay": "^5.0.0"
"sinon-ts": "^1.0.0"
}
}
14 changes: 9 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { multiaddr } from '@multiformats/multiaddr'
import { P2P } from '@multiformats/mafmt'
import { CustomEvent, EventEmitter } from '@libp2p/interfaces/events'
import { EventEmitter } from '@libp2p/interfaces/events'
import { logger } from '@libp2p/logger'
import type { PeerDiscovery, PeerDiscoveryEvents } from '@libp2p/interface-peer-discovery'
import type { PeerInfo } from '@libp2p/interface-peer-info'
Expand Down Expand Up @@ -133,17 +133,21 @@ class Bootstrap extends EventEmitter<PeerDiscoveryEvents> implements PeerDiscove
}

for (const peerData of this.list) {
await this.components.peerStore.tagPeer(peerData.id, this._init.tagName ?? DEFAULT_BOOTSTRAP_TAG_NAME, {
value: this._init.tagValue ?? DEFAULT_BOOTSTRAP_TAG_VALUE,
ttl: this._init.tagTTL ?? DEFAULT_BOOTSTRAP_TAG_TTL
await this.components.peerStore.merge(peerData.id, {
tags: {
[this._init.tagName ?? DEFAULT_BOOTSTRAP_TAG_NAME]: {
value: this._init.tagValue ?? DEFAULT_BOOTSTRAP_TAG_VALUE,
ttl: this._init.tagTTL ?? DEFAULT_BOOTSTRAP_TAG_TTL
}
}
})

// check we are still running
if (this.timer == null) {
return
}

this.dispatchEvent(new CustomEvent<PeerInfo>('peer', { detail: peerData }))
this.safeDispatchEvent('peer', { detail: peerData })
}
}

Expand Down
37 changes: 18 additions & 19 deletions test/bootstrap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,21 @@ import { bootstrap, BootstrapComponents } from '../src/index.js'
import peerList from './fixtures/default-peers.js'
import partialValidPeerList from './fixtures/some-invalid-peers.js'
import { isPeerId } from '@libp2p/interface-peer-id'
import { PersistentPeerStore } from '@libp2p/peer-store'
import { MemoryDatastore } from 'datastore-core'
import { multiaddr } from '@multiformats/multiaddr'
import { peerIdFromString } from '@libp2p/peer-id'
import delay from 'delay'
import { start, stop } from '@libp2p/interfaces/startable'
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
import { StubbedInstance, stubInterface } from 'sinon-ts'
import type { PeerStore } from '@libp2p/interface-peer-store'

describe('bootstrap', () => {
let components: BootstrapComponents
let peerStore: StubbedInstance<PeerStore>

beforeEach(async () => {
peerStore = stubInterface<PeerStore>()

components = {
peerStore: new PersistentPeerStore({
peerId: await createEd25519PeerId(),
datastore: new MemoryDatastore()
})
peerStore
}
})

Expand Down Expand Up @@ -83,17 +81,18 @@ describe('bootstrap', () => {

const bootstrapper0PeerId = peerIdFromString(bootstrapper0PeerIdStr)

const tags = await components.peerStore.getTags(bootstrapper0PeerId)

expect(tags).to.have.lengthOf(1, 'bootstrap tag was not set')
expect(tags).to.have.nested.property('[0].name', tagName, 'bootstrap tag had incorrect name')
expect(tags).to.have.nested.property('[0].value', tagValue, 'bootstrap tag had incorrect value')

await delay(tagTTL * 2)

const tags2 = await components.peerStore.getTags(bootstrapper0PeerId)

expect(tags2).to.have.lengthOf(0, 'bootstrap tag did not expire')
expect(peerStore.merge).to.have.property('called', true)

const call = peerStore.merge.getCall(0)
expect(call).to.have.deep.nested.property('args[0]', bootstrapper0PeerId)
expect(call).to.have.deep.nested.property('args[1]', {
tags: {
[tagName]: {
value: tagValue,
ttl: tagTTL
}
}
})

await stop(r)
})
Expand Down
10 changes: 3 additions & 7 deletions test/compliance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@
import tests from '@libp2p/interface-peer-discovery-compliance-tests'
import { bootstrap } from '../src/index.js'
import peerList from './fixtures/default-peers.js'
import { PersistentPeerStore } from '@libp2p/peer-store'
import { MemoryDatastore } from 'datastore-core'
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
import type { PeerStore } from '@libp2p/interface-peer-store'
import { stubInterface } from 'sinon-ts'

describe('compliance tests', () => {
tests({
async setup () {
const components = {
peerStore: new PersistentPeerStore({
peerId: await createEd25519PeerId(),
datastore: new MemoryDatastore()
})
peerStore: stubInterface<PeerStore>()
}

return bootstrap({
Expand Down