Skip to content

Commit 413ebe9

Browse files
authored
feat!: update to latest libp2p interfaces (#76)
BREAKING CHANGE: uses new single-issue libp2p interface modules
1 parent a39af37 commit 413ebe9

File tree

3 files changed

+37
-24
lines changed

3 files changed

+37
-24
lines changed

README.md

+22-15
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
1-
# js-libp2p-delegated-peer-routing <!-- omit in toc -->
1+
# @libp2p/delegated-peer-routing <!-- omit in toc -->
22

3-
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)
4-
[![](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
5-
[![](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23libp2p)
6-
[![Discourse posts](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg)](https://discuss.libp2p.io)
7-
[![](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-delegated-peer-routing.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-delegated-peer-routing)
8-
[![Build Status](https://github.com/libp2p/js-libp2p-delegated-peer-routing/actions/workflows/js-test-and-release.yml/badge.svg?branch=main)](https://github.com/libp2p/js-libp2p-delegated-peer-routing/actions/workflows/js-test-and-release.yml)
9-
[![Dependency Status](https://david-dm.org/libp2p/js-libp2p-delegated-peer-routing.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-delegated-peer-routing)
3+
[![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
4+
[![IRC](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23libp2p)
5+
[![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io)
6+
[![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-delegated-peer-routing.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-delegated-peer-routing)
7+
[![CI](https://img.shields.io/github/workflow/status/libp2p/js-libp2p-interfaces/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/libp2p/js-libp2p-delegated-peer-routing/actions/workflows/js-test-and-release.yml)
108

11-
Leverage other peers in the network to perform Peer Routing calls.
12-
13-
Requires access to `/api/v0/dht/findpeer` and `/api/v0/dht/query` HTTP API endpoints of the delegate node.
9+
> Leverage other peers in the libp2p network to perform Peer Routing calls.
1410
1511
## Table of contents <!-- omit in toc -->
1612

13+
- [Install](#install)
1714
- [Requirements](#requirements)
1815
- [Example](#example)
1916
- [License](#license)
20-
- [Contribution](#contribution)
17+
- [Contribution](#contribution)
18+
19+
## Install
20+
21+
```console
22+
$ npm i @libp2p/delegated-peer-routing
23+
```
24+
25+
Leverage other peers in the network to perform Peer Routing calls.
26+
27+
Requires access to `/api/v0/dht/findpeer` and `/api/v0/dht/query` HTTP API endpoints of the delegate node.
2128

2229
## Requirements
2330

@@ -60,9 +67,9 @@ for await (const event of routing.getClosestPeers(peerId.id)) {
6067

6168
Licensed under either of
6269

63-
* Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / http://www.apache.org/licenses/LICENSE-2.0)
64-
* MIT ([LICENSE-MIT](LICENSE-MIT) / http://opensource.org/licenses/MIT)
70+
- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
71+
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
6572

66-
### Contribution
73+
## Contribution
6774

6875
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

package.json

+7-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
],
2626
"exports": {
2727
".": {
28+
"types": "./src/index.d.ts",
2829
"import": "./dist/src/index.js"
2930
}
3031
},
@@ -130,7 +131,10 @@
130131
"release": "aegir release"
131132
},
132133
"dependencies": {
133-
"@libp2p/interfaces": "^2.0.3",
134+
"@libp2p/interface-peer-id": "^1.0.2",
135+
"@libp2p/interface-peer-info": "^1.0.1",
136+
"@libp2p/interface-peer-routing": "^1.0.0",
137+
"@libp2p/interfaces": "^3.0.2",
134138
"@libp2p/logger": "^1.1.5",
135139
"@libp2p/peer-id": "^1.1.11",
136140
"@multiformats/multiaddr": "^10.1.8",
@@ -142,8 +146,8 @@
142146
},
143147
"devDependencies": {
144148
"@libp2p/peer-id-factory": "^1.0.11",
145-
"aegir": "^37.0.15",
146-
"go-ipfs": "^0.12.0",
149+
"aegir": "^37.2.0",
150+
"go-ipfs": "^0.13.0",
147151
"ipfs-http-client": "^57.0.1",
148152
"ipfsd-ctl": "^11.0.1",
149153
"it-all": "^1.0.6",

src/index.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import { CID } from 'multiformats/cid'
33
import PQueue from 'p-queue'
44
import defer from 'p-defer'
55
import errCode from 'err-code'
6-
import { Multiaddr } from '@multiformats/multiaddr'
6+
import { multiaddr } from '@multiformats/multiaddr'
77
import anySignal from 'any-signal'
8-
import type { PeerId } from '@libp2p/interfaces/peer-id'
8+
import type { PeerId } from '@libp2p/interface-peer-id'
99
import type { IPFSHTTPClient, HTTPClientExtraOptions } from 'ipfs-http-client'
1010
import type { AbortOptions } from 'ipfs-core-types/src/utils'
11-
import type { PeerRouting } from '@libp2p/interfaces/peer-routing'
12-
import type { PeerInfo } from '@libp2p/interfaces/peer-info'
11+
import type { PeerRouting } from '@libp2p/interface-peer-routing'
12+
import type { PeerInfo } from '@libp2p/interface-peer-info'
1313
import type { Startable } from '@libp2p/interfaces/startable'
1414
import { peerIdFromBytes } from '@libp2p/peer-id'
1515

@@ -89,7 +89,8 @@ export class DelegatedPeerRouting implements PeerRouting, Startable {
8989
if (event.name === 'FINAL_PEER') {
9090
const peerInfo: PeerInfo = {
9191
id: event.peer.id,
92-
multiaddrs: event.peer.multiaddrs.map(ma => new Multiaddr(ma.toString())),
92+
// @ts-expect-error ipfs-core types need updating
93+
multiaddrs: event.peer.multiaddrs.map(ma => multiaddr(ma.toString())),
9394
protocols: []
9495
}
9596

@@ -140,7 +141,8 @@ export class DelegatedPeerRouting implements PeerRouting, Startable {
140141
if (event.name === 'PEER_RESPONSE') {
141142
yield * event.closer.map(closer => ({
142143
id: closer.id,
143-
multiaddrs: closer.multiaddrs.map(ma => new Multiaddr(ma.toString())),
144+
// @ts-expect-error ipfs-core types need updating
145+
multiaddrs: closer.multiaddrs.map(ma => multiaddr(ma.toString())),
144146
protocols: []
145147
}))
146148
}

0 commit comments

Comments
 (0)