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

Commit

Permalink
deps: update uint8arraylist and interface deps (#21)
Browse files Browse the repository at this point in the history
To support no-copy operations, update all deps
  • Loading branch information
achingbrain committed Aug 3, 2022
1 parent fce3db5 commit f693e84
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 22 deletions.
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@
"@libp2p/interface-peer-id": "^1.0.2",
"@libp2p/interface-peer-info": "^1.0.1",
"@libp2p/interface-peer-store": "^1.1.0",
"@libp2p/interface-record": "^1.0.1",
"@libp2p/interface-record": "^2.0.0",
"@libp2p/interfaces": "^3.0.2",
"@libp2p/logger": "^2.0.0",
"@libp2p/peer-id": "^1.1.0",
"@libp2p/peer-record": "^2.0.0",
"@libp2p/peer-record": "^4.0.0",
"@multiformats/multiaddr": "^10.2.0",
"err-code": "^3.0.1",
"interface-datastore": "^6.1.0",
Expand All @@ -162,19 +162,20 @@
"it-pipe": "^2.0.3",
"mortice": "^3.0.0",
"multiformats": "^9.6.3",
"protons-runtime": "^1.0.4",
"uint8arrays": "^3.0.0"
"protons-runtime": "^2.0.2",
"uint8arraylist": "^2.1.1",
"uint8arrays": "^3.1.0"
},
"devDependencies": {
"@libp2p/interface-compliance-tests": "^3.0.1",
"@libp2p/peer-id-factory": "^1.0.0",
"@libp2p/utils": "^2.0.0",
"@libp2p/utils": "^3.0.0",
"aegir": "^37.4.0",
"datastore-core": "^7.0.1",
"delay": "^5.0.0",
"p-defer": "^4.0.0",
"p-wait-for": "^4.1.0",
"protons": "^3.0.4",
"p-wait-for": "^5.0.0",
"protons": "^4.0.1",
"sinon": "^14.0.0"
}
}
2 changes: 1 addition & 1 deletion src/address-book.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class PeerStoreAddressBook {
// TODO: Once we have ttls for the addresses, we should merge these in
updatedPeer = await this.store.patchOrCreate(peerId, {
addresses,
peerRecordEnvelope: envelope.marshal()
peerRecordEnvelope: envelope.marshal().subarray()
})

log('stored provided peer record for %p', peerRecord.peerId)
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class PersistentPeerStore extends EventEmitter<PeerStoreEvents> implement
expiry: ttl == null ? undefined : BigInt(Date.now() + ttl)
})

await this.metadataBook.setValue(peerId, 'tags', Tags.encode({ tags }))
await this.metadataBook.setValue(peerId, 'tags', Tags.encode({ tags }).subarray())
}

async unTagPeer (peerId: PeerId, tag: string) {
Expand All @@ -159,7 +159,7 @@ export class PersistentPeerStore extends EventEmitter<PeerStoreEvents> implement

tags = tags.filter(t => t.name !== tag)

await this.metadataBook.setValue(peerId, 'tags', Tags.encode({ tags }))
await this.metadataBook.setValue(peerId, 'tags', Tags.encode({ tags }).subarray())
}

async getTags (peerId: PeerId) {
Expand All @@ -175,7 +175,7 @@ export class PersistentPeerStore extends EventEmitter<PeerStoreEvents> implement

if (unexpiredTags.length !== tags.length) {
// remove any expired tags
await this.metadataBook.setValue(peerId, 'tags', Tags.encode({ tags: unexpiredTags }))
await this.metadataBook.setValue(peerId, 'tags', Tags.encode({ tags: unexpiredTags }).subarray())
}

return unexpiredTags.map(t => ({
Expand Down
13 changes: 7 additions & 6 deletions src/pb/peer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import { encodeMessage, decodeMessage, message, string, bytes, bool } from 'protons-runtime'
import type { Codec } from 'protons-runtime'
import type { Uint8ArrayList } from 'uint8arraylist'

export interface Peer {
addresses: Address[]
Expand All @@ -23,11 +24,11 @@ export namespace Peer {
})
}

export const encode = (obj: Peer): Uint8Array => {
export const encode = (obj: Peer): Uint8ArrayList => {
return encodeMessage(obj, Peer.codec())
}

export const decode = (buf: Uint8Array): Peer => {
export const decode = (buf: Uint8Array | Uint8ArrayList): Peer => {
return decodeMessage(buf, Peer.codec())
}
}
Expand All @@ -45,11 +46,11 @@ export namespace Address {
})
}

export const encode = (obj: Address): Uint8Array => {
export const encode = (obj: Address): Uint8ArrayList => {
return encodeMessage(obj, Address.codec())
}

export const decode = (buf: Uint8Array): Address => {
export const decode = (buf: Uint8Array | Uint8ArrayList): Address => {
return decodeMessage(buf, Address.codec())
}
}
Expand All @@ -67,11 +68,11 @@ export namespace Metadata {
})
}

export const encode = (obj: Metadata): Uint8Array => {
export const encode = (obj: Metadata): Uint8ArrayList => {
return encodeMessage(obj, Metadata.codec())
}

export const decode = (buf: Uint8Array): Metadata => {
export const decode = (buf: Uint8Array | Uint8ArrayList): Metadata => {
return decodeMessage(buf, Metadata.codec())
}
}
9 changes: 5 additions & 4 deletions src/pb/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import { encodeMessage, decodeMessage, message, string, uint32, uint64 } from 'protons-runtime'
import type { Codec } from 'protons-runtime'
import type { Uint8ArrayList } from 'uint8arraylist'

export interface Tags {
tags: Tag[]
Expand All @@ -15,11 +16,11 @@ export namespace Tags {
})
}

export const encode = (obj: Tags): Uint8Array => {
export const encode = (obj: Tags): Uint8ArrayList => {
return encodeMessage(obj, Tags.codec())
}

export const decode = (buf: Uint8Array): Tags => {
export const decode = (buf: Uint8Array | Uint8ArrayList): Tags => {
return decodeMessage(buf, Tags.codec())
}
}
Expand All @@ -39,11 +40,11 @@ export namespace Tag {
})
}

export const encode = (obj: Tag): Uint8Array => {
export const encode = (obj: Tag): Uint8ArrayList => {
return encodeMessage(obj, Tag.codec())
}

export const decode = (buf: Uint8Array): Tag => {
export const decode = (buf: Uint8Array | Uint8ArrayList): Tag => {
return decodeMessage(buf, Tag.codec())
}
}
2 changes: 1 addition & 1 deletion src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export class PersistentStore {
peerRecordEnvelope: peer.peerRecordEnvelope
})

await this.components.getDatastore().put(this._peerIdToDatastoreKey(peer.id), buf)
await this.components.getDatastore().put(this._peerIdToDatastoreKey(peer.id), buf.subarray())

return await this.load(peer.id)
}
Expand Down

0 comments on commit f693e84

Please sign in to comment.