Skip to content

Commit

Permalink
fix: handle unparsable peer ids (#118)
Browse files Browse the repository at this point in the history
* deps(dev): bump aegir from 42.2.11 to 43.0.1

Bumps [aegir](https://github.com/ipfs/aegir) from 42.2.11 to 43.0.1.
- [Release notes](https://github.com/ipfs/aegir/releases)
- [Changelog](https://github.com/ipfs/aegir/blob/master/CHANGELOG.md)
- [Commits](ipfs/aegir@v42.2.11...v43.0.1)

---
updated-dependencies:
- dependency-name: aegir
  dependency-type: direct:development
  update-type: version-update:semver-major
...

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

* chore: fix tests

---------

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 authored Jun 20, 2024
1 parent bfbba0f commit 9bdbe46
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"docs:no-publish": "aegir docs --publish false"
},
"devDependencies": {
"aegir": "^42.2.0",
"aegir": "^43.0.1",
"npm-run-all": "^4.1.5"
},
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
},
"devDependencies": {
"@libp2p/peer-id-factory": "^4.0.4",
"aegir": "^42.2.0",
"aegir": "^43.0.1",
"body-parser": "^1.20.2",
"it-all": "^3.0.2"
},
Expand Down
34 changes: 19 additions & 15 deletions packages/client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,24 +301,28 @@ export class DefaultDelegatedRoutingV1HttpApiClient implements DelegatedRoutingV
}

#conformToPeerSchema (record: any): PeerRecord | undefined {
const protocols: string[] = []
const multiaddrs: Multiaddr[] = record.Addrs?.map(multiaddr) ?? []
try {
const protocols: string[] = []
const multiaddrs: Multiaddr[] = record.Addrs?.map(multiaddr) ?? []

if (record.Protocols != null) {
protocols.push(...record.Protocols)
}
if (record.Protocols != null) {
protocols.push(...record.Protocols)
}

if (record.Protocol != null) {
protocols.push(record.Protocol)
delete record.Protocol
}
if (record.Protocol != null) {
protocols.push(record.Protocol)
delete record.Protocol
}

return {
...record,
Schema: 'peer',
ID: peerIdFromString(record.ID),
Addrs: multiaddrs,
Protocols: protocols
return {
...record,
Schema: 'peer',
ID: peerIdFromString(record.ID),
Addrs: multiaddrs,
Protocols: protocols
}
} catch (err) {
log.error('could not conform record to peer schema', err)
}
}
}
4 changes: 2 additions & 2 deletions packages/interop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@
"@helia/delegated-routing-v1-http-api-client": "^3.0.0",
"@helia/delegated-routing-v1-http-api-server": "^3.0.0",
"@helia/ipns": "^7.1.0",
"@libp2p/identify": "^1.0.10",
"@libp2p/identify": "^2.1.0",
"@libp2p/interface": "^1.1.1",
"@libp2p/kad-dht": "^12.0.3",
"@libp2p/peer-id-factory": "^4.0.4",
"aegir": "^42.2.0",
"aegir": "^43.0.1",
"fastify": "^4.17.0",
"helia": "^4.0.0",
"ipns": "^9.0.0",
Expand Down
1 change: 1 addition & 0 deletions packages/interop/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ describe('delegated-routing-v1-http-api interop', () => {
const cid = CID.createV1(raw.code, digest)

await network[1].blockstore.put(cid, input)
await network[1].routing.provide(cid)

let foundProvider = false

Expand Down
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"@libp2p/peer-id-factory": "^4.0.4",
"@multiformats/multiaddr": "^12.1.3",
"@types/sinon": "^17.0.0",
"aegir": "^42.2.0",
"aegir": "^43.0.1",
"sinon": "^17.0.0",
"sinon-ts": "^2.0.0"
}
Expand Down

0 comments on commit 9bdbe46

Please sign in to comment.