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

Commit

Permalink
deps!: bump @libp2p/interface-peer-store from 1.2.9 to 2.0.0 (#171)
Browse files Browse the repository at this point in the history
Bumps [@libp2p/interface-peer-store](https://github.com/libp2p/js-libp2p-interfaces) from 1.2.9 to 2.0.0.
- [Release notes](https://github.com/libp2p/js-libp2p-interfaces/releases)
- [Commits](https://github.com/libp2p/js-libp2p-interfaces/compare/@libp2p/interface-peer-store-v1.2.9...@libp2p/interface-peer-store-v2.0.0)

---
updated-dependencies:
- dependency-name: "@libp2p/interface-peer-store"
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: achingbrain <alex@achingbrain.net>
  • Loading branch information
dependabot[bot] and achingbrain committed Apr 24, 2023
1 parent 6d1b65a commit 9f36bb2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 36 deletions.
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

0 comments on commit 9f36bb2

Please sign in to comment.