Skip to content

Commit 21d758b

Browse files
authored
feat: add delegated routing example (#90)
Restores old example but updates it for use with modern delegates.
1 parent 7459bcf commit 21d758b

File tree

17 files changed

+478
-0
lines changed

17 files changed

+478
-0
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
- js-libp2p-example-chat
2525
- js-libp2p-example-circuit-relay
2626
- js-libp2p-example-connection-encryption
27+
- js-libp2p-example-delegated-routing
2728
defaults:
2829
run:
2930
working-directory: examples/${{ matrix.project }}
@@ -75,6 +76,7 @@ jobs:
7576
- js-libp2p-example-chat
7677
- js-libp2p-example-circuit-relay
7778
- js-libp2p-example-connection-encryption
79+
- js-libp2p-example-delegated-routing
7880
steps:
7981
- uses: convictional/trigger-workflow-and-wait@f69fa9eedd3c62a599220f4d5745230e237904be
8082
with:

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Feel free to jump directly into the examples, however going through the followin
5050

5151
- [Circuit Relay](./examples/js-libp2p-example-circuit-relay) - configuring Circuit Relay connections
5252
- [Connection Encryption](./examples/js-libp2p-example-connection-encryption) - how to encrypt connection between libp2p nodes
53+
- [Delegated routing](./examples/js-libp2p-example-delegated-routing) - how to offload network operations and queries onto more capable nodes
5354

5455
#### Other examples
5556

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# ⚠️ IMPORTANT ⚠️
2+
3+
# Please do not create a Pull Request for this repository
4+
5+
The contents of this repository are automatically synced from the parent [js-libp2p Examples Project](https://github.com/libp2p/js-libp2p-examples) so any changes made to the standalone repository will be lost after the next sync.
6+
7+
Please open a PR against [js-libp2p Examples](https://github.com/libp2p/js-libp2p-examples) instead.
8+
9+
## Contributing
10+
11+
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**.
12+
13+
1. Fork the [js-libp2p Examples Project](https://github.com/libp2p/js-libp2p-examples)
14+
2. Create your Feature Branch (`git checkout -b feature/amazing-example`)
15+
3. Commit your Changes (`git commit -a -m 'feat: add some amazing example'`)
16+
4. Push to the Branch (`git push origin feature/amazing-example`)
17+
5. Open a Pull Request
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: pull
2+
3+
on:
4+
workflow_dispatch
5+
6+
jobs:
7+
sync:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
- name: Pull from another repository
12+
uses: ipfs-examples/actions-pull-directory-from-repo@main
13+
with:
14+
source-repo: libp2p/js-libp2p-examples
15+
source-folder-path: examples/${{ github.event.repository.name }}
16+
source-branch: main
17+
target-branch: main
18+
git-username: github-actions
19+
git-email: [email protected]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
This project is dual licensed under MIT and Apache-2.0.
2+
3+
MIT: https://www.opensource.org/licenses/mit
4+
Apache-2.0: https://www.apache.org/licenses/license-2.0
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
2+
3+
http://www.apache.org/licenses/LICENSE-2.0
4+
5+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
The MIT License (MIT)
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# @libp2p/example-delegated-routing-example <!-- omit in toc -->
2+
3+
[![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
4+
[![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io)
5+
[![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-examples.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-examples)
6+
[![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p-examples/ci.yml?branch=main\&style=flat-square)](https://github.com/libp2p/js-libp2p-examples/actions/workflows/ci.yml?query=branch%3Amain)
7+
8+
> How to configure libp2p delegated routers
9+
10+
## Table of contents <!-- omit in toc -->
11+
12+
- [Running this example](#running-this-example)
13+
- [Finding Content Providers via the Delegate](#finding-content-providers-via-the-delegate)
14+
- [Finding Peers via the Delegate](#finding-peers-via-the-delegate)
15+
- [License](#license)
16+
- [Contribution](#contribution)
17+
18+
Delegated routing allows a libp2p node running in a constrained environment (for example a browser) to offload network operations and queries to a more capable node running elsewhere.
19+
20+
The [libp2p node](./src/libp2p.js) created by this app has no transports, connection encrypters or muxers - it uses only a [Delegated Routing V1 HTTP API client](https://specs.ipfs.tech/routing/http-routing-v1/) to look up CID providers and Peer Info from a more capable libp2p node running in a separate process.
21+
22+
## Running this example
23+
24+
1. Install the example dependencies
25+
```console
26+
$ npm i
27+
```
28+
2. Start the Helia node in `./server.js` - this is the node we will delegate operations to
29+
```console
30+
$ node ./server.js
31+
```
32+
3. Start the lightweight browser libp2p node
33+
```console
34+
$ npm start
35+
```
36+
37+
This should open your browser to <http://localhost:3000>. If it does not, go ahead and do that now.
38+
39+
### Finding Content Providers via the Delegate
40+
41+
1. Enter the CID of the block you wish to find providers for, one is pre-filled for your convenience
42+
2. Click "Find Providers"
43+
3. If any exist, provders will start to appear in the box beneath the input fields
44+
45+
### Finding Peers via the Delegate
46+
47+
1. Enter the PeerId of the peer you wish to find, one is pre-filled for your convenience
48+
2. Click "Find PeerInfo"
49+
3. If found, multiaddrs for the peer will appear in the box beneath the input fields
50+
51+
## License
52+
53+
Licensed under either of
54+
55+
- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
56+
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
57+
58+
## Contribution
59+
60+
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.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"name": "@libp2p/example-delegated-routing-example",
3+
"version": "0.0.0",
4+
"description": "How to use other libp2p nodes to perform delegated routing",
5+
"license": "Apache-2.0 OR MIT",
6+
"homepage": "https://github.com/libp2p/js-libp2p-examples/tree/main/examples/js-libp2p-example-delegated-routing#readme",
7+
"repository": {
8+
"type": "git",
9+
"url": "git+https://github.com/libp2p/js-libp2p-examples.git"
10+
},
11+
"bugs": {
12+
"url": "https://github.com/libp2p/js-libp2p-examples/issues"
13+
},
14+
"type": "module",
15+
"scripts": {
16+
"build": "BUILD_PATH=dist PUBLIC_URL=/ react-scripts build",
17+
"start": "PUBLIC_URL=/ react-scripts start",
18+
"test:firefox": "npm run build && playwright test --browser=firefox test",
19+
"test:chrome": "npm run build && playwright test test",
20+
"test": "npm run build && test-browser-example test"
21+
},
22+
"dependencies": {
23+
"@helia/delegated-routing-v1-http-api-client": "^1.1.0",
24+
"@helia/delegated-routing-v1-http-api-server": "^1.0.3",
25+
"helia": "^2.1.0",
26+
"libp2p": "^1.0.8",
27+
"react": "^18.2.0",
28+
"react-dom": "^18.2.0",
29+
"react-scripts": "^5.0.1"
30+
},
31+
"devDependencies": {
32+
"test-ipfs-example": "^1.0.0",
33+
"eslint-config-ipfs": "^6.0.0"
34+
},
35+
"browserslist": [
36+
">0.2%",
37+
"not dead",
38+
"not ie <= 11",
39+
"not op_mini all"
40+
],
41+
"private": true
42+
}
Binary file not shown.

0 commit comments

Comments
 (0)