Documentation (#716)
This commit is contained in:
parent
0ece5eaf12
commit
d0523fdc9d
File diff suppressed because it is too large
Load Diff
After Width: | Height: | Size: 61 KiB |
|
@ -0,0 +1,96 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:v="https://vecta.io/nano" xmlns:xlink="http://www.w3.org/1999/xlink" width="172.071" height="196.414" viewBox="0 0 45.527 51.968">
|
||||||
|
<g transform="matrix(.2822 0 0 .2822 -212.833275 -150.656248)">
|
||||||
|
<path d="M835.432 533.821l-12.483 9.783c-6.482-.207-19.197 1.251-26.086 3.769-6.346-4.04-11.923-8.5-11.923-8.5l-7.762 13.071c-4.444 2.375-8.906 5.046-12.883 8.58l-10.162-4.17c6.125 12.414 10.243 24.844 21.445 32.316 17.834-28.299 100.705-25.691 118.907-.16 11.764-6.165 16.339-19.429 20.965-31.674-.507.168-6.802 2.285-10.882 3.849-2.436-2.665-8.179-6.763-11.443-8.741-3.096-5.696-7.602-13.391-7.602-13.391s-5.337 3.988-11.523 8.34c-8.357-1.55-18.465-3.433-26.966-2.967-5.787-4.779-11.603-10.104-11.603-10.104z" fill="#f3d400" />
|
||||||
|
<g opacity=".9" transform="matrix(.9375 0 0 .9375 765.1166 550.13225)">
|
||||||
|
<path d="M99.952 106.898l.215-.107 24.755-14.248-24.97-14.535-24.97 14.374z" fill="#cc2a65" />
|
||||||
|
<use xlink:href="#B" fill="#a21d4c" />
|
||||||
|
<path d="M124.922 92.542l-24.755 14.248-.215.107v28.89l24.97-14.356z" fill="#b62454" />
|
||||||
|
<path d="M50.012 106.737l.215-.125 24.755-14.248-24.97-14.517-24.97 14.356z" fill="#c8d92b" />
|
||||||
|
<path d="M50.012 135.609v-28.872l-24.97-14.535v28.89h.018z" fill="#c2d02f" />
|
||||||
|
<path d="M74.982 92.381l-24.755 14.23-.215.125v28.872.018h.018l24.952-14.356v-.018z" fill="#b9be33" />
|
||||||
|
<path d="M74.982 121.253l.215-.107 24.755-14.248-24.97-14.535-24.97 14.374z" fill="#cc2a65" />
|
||||||
|
<use xlink:href="#B" x="-24.97" y="14.356" fill="#a21d4c" />
|
||||||
|
<path d="M99.952 106.898l-24.755 14.248-.215.107v28.89H75l24.952-14.356z" fill="#b62454" />
|
||||||
|
<path d="M124.905 121.415l.215-.125 24.737-14.23-24.952-14.535-24.97 14.356z" fill="#a159a2" />
|
||||||
|
<path d="M124.905 150.305v-28.89l-24.97-14.535v28.89h.018z" fill="#772a86" />
|
||||||
|
<path d="M149.875 107.059l-24.755 14.23-.215.125v28.89l24.97-14.356z" fill="#8e3b95" />
|
||||||
|
<path d="M74.982 92.345l.215-.125 24.737-14.248-24.952-14.517-24.97 14.356z" fill="#bec831" />
|
||||||
|
<path d="M74.982 121.217V92.345L50.012 77.81v28.89h.018z" fill="#a1a938" />
|
||||||
|
<path d="M99.952 77.989l-24.755 14.23-.215.125v28.872.018l24.97-14.356v-.018z" fill="#999b37" />
|
||||||
|
<path d="M75 60.645l.197-.125 24.755-14.23L75 31.755 50.029 46.11l24.952 14.535z" fill="#bec831" />
|
||||||
|
<path d="M74.982 89.535L75 60.645 50.029 46.11 50.012 75h.018z" fill="#a1a938" />
|
||||||
|
<path d="M99.97 46.307L75.197 60.52l-.197.125h-.018v28.89l24.97-14.338v-.018z" fill="#999b37" />
|
||||||
|
<path d="M99.952 75.179l.215-.107 24.755-14.23L99.97 46.306 75 60.644z" fill="#ee539a" />
|
||||||
|
<path d="M99.952 104.069v-28.89L75 60.644l-.018 28.89H75z" fill="#d01b68" />
|
||||||
|
<path d="M124.922 60.841l-24.755 14.23-.215.107v28.89l24.97-14.338.018-28.89z" fill="#ec0f68" />
|
||||||
|
<path d="M124.923 89.731l.215-.125 24.755-14.23-24.952-14.535h-.018l-24.97 14.338z" fill="#a159a2" />
|
||||||
|
<path d="M124.905 118.622l.018-28.89-24.97-14.535v28.872.018z" fill="#772a86" />
|
||||||
|
<path d="M149.893 75.376l-24.755 14.23-.215.125-.018 28.89h.018l24.97-14.356z" fill="#8e3b95" />
|
||||||
|
<path d="M50.03 75l.197-.125 24.755-14.23L50.03 46.109 25.06 60.447l24.952 14.535z" fill="#c8d92b" />
|
||||||
|
<path d="M50.012 103.872L50.03 75 25.06 60.447l-.018 28.89h.018z" fill="#c2d02f" />
|
||||||
|
<path d="M75 60.644l-24.773 14.23-.197.125-.018 28.872 24.97-14.338z" fill="#b9be33" />
|
||||||
|
<path d="M74.982 89.534l.215-.125 24.755-14.23L75 60.644l-24.97 14.338z" fill="#f7af19" />
|
||||||
|
<path d="M74.982 118.425v-.018.018-28.89L50.029 75l-.018 28.872.018.018z" fill="#f2901f" />
|
||||||
|
<path d="M99.952 75.179l-24.755 14.23-.215.125v28.89l24.97-14.356.018-28.89z" fill="#f9a120" />
|
||||||
|
<path d="M99.934 135.769l.215-.125 24.684-14.356-25.042-14.409L74.91 121.36z" fill="#833593" />
|
||||||
|
<path d="M100.077 164.66l-.143-28.89-25.042-14.409.143 28.89h.018z" fill="#652977" />
|
||||||
|
<path d="M124.833 121.288l-24.684 14.356-.215.125.143 28.89 24.899-14.481z" fill="#4d1f5b" />
|
||||||
|
<path d="M99.952 104.069l.215-.107 24.755-14.23L99.97 75.179h-.018l-24.97 14.356z" fill="#a159a2" />
|
||||||
|
<path d="M99.934 132.959l.018-28.89-24.97-14.535v28.89z" fill="#772a86" />
|
||||||
|
<path d="M124.922 89.732l-24.755 14.23-.215.107-.018 28.89h.018l24.97-14.338z" fill="#8e3b95" />
|
||||||
|
<path d="M25.042 121.074l.197-.125 24.755-14.248-24.952-14.517h-.018L.071 106.54l24.952 14.535z" fill="#f6dd03" />
|
||||||
|
<path d="M25.024 149.947h.018v-28.872L.071 106.54v28.89z" fill="#f9bb1d" />
|
||||||
|
<path d="M49.994 106.719l-24.755 14.23-.197.125v28.872.018l24.952-14.356h.018v-.018-28.872z" fill="#e9ae20" />
|
||||||
|
<path d="M25.06 89.338l.197-.125 24.755-14.23L25.06 60.447.089 74.803l24.952 14.535z" fill="#f6dd03" />
|
||||||
|
<path d="M25.042 118.228l.018-28.89L.089 74.803.072 103.675l.018.018z" fill="#f9bb1d" />
|
||||||
|
<path d="M50.03 75L25.257 89.212l-.197.125-.018 28.89 24.97-14.356v.018-.018z" fill="#e9ae20" />
|
||||||
|
<path d="M50.012 135.59l.215-.107 24.737-14.248L50.012 106.7l-24.97 14.374z" fill="#f7af19" />
|
||||||
|
<path d="M50.012 164.481v-28.89l-24.97-14.517v28.872.018z" fill="#f2901f" />
|
||||||
|
<path d="M74.964 121.235l-24.755 14.248-.197.107v28.89l24.97-14.356v-28.89z" fill="#f9a120" />
|
||||||
|
<path d="M50.012 103.872l.215-.107 24.755-14.23L50.03 74.982 25.06 89.338z" fill="#f7af19" />
|
||||||
|
<path d="M50.012 132.763v-28.89L25.06 89.338l-.018 28.89h.018z" fill="#f2901f" />
|
||||||
|
<path d="M74.982 89.535l-24.755 14.23-.215.107v28.89l24.97-14.338.018-28.89z" fill="#f9a120" />
|
||||||
|
<path d="M74.982 150.125l.197-.125 24.755-14.23-24.952-14.535h-.018l-24.952 14.356 24.952 14.535z" fill="#f7af19" />
|
||||||
|
<path d="M74.964 179.015h.018v-28.89l-24.97-14.517v28.872.018z" fill="#f2901f" />
|
||||||
|
<path d="M99.934 135.77L75.179 150l-.197.125v28.89l24.97-14.356v-28.89z" fill="#f9a120" />
|
||||||
|
<path d="M74.982 118.425l.215-.125 24.755-14.23L75 89.535h-.018l-24.97 14.338z" fill="#31838b" />
|
||||||
|
<path d="M74.964 147.297l.018-28.872-24.97-14.535v-.018 28.89.018z" fill="#22626c" />
|
||||||
|
<path d="M99.952 104.069L75.197 118.3l-.215.125-.018 28.872v.018h.018l24.97-14.356z" fill="#1b4b56" />
|
||||||
|
<path d="M74.982 28.962l.215-.125 24.737-14.248L74.982.072l-24.97 14.356 24.97 14.517z" fill="#bec831" />
|
||||||
|
<path d="M74.982 57.834V28.962l-24.97-14.535v28.89h.018z" fill="#a1a938" />
|
||||||
|
<path d="M99.952 14.606l-24.755 14.23-.215.125v28.872l24.97-14.356z" fill="#999b37" />
|
||||||
|
<path d="M74.964 28.944l.215-.125 24.755-14.23L74.982.054h-.018l-24.97 14.338z" fill="#a159a2" />
|
||||||
|
<path d="M74.946 57.835l.018-28.89-24.97-14.535v28.872.018z" fill="#772a86" />
|
||||||
|
<path d="M99.934 14.589l-24.755 14.23-.215.125-.018 28.89h.018l24.97-14.356z" fill="#8e3b95" />
|
||||||
|
<path d="M99.952 43.479l.215-.107 24.755-14.248-24.97-14.535-24.97 14.356z" fill="#ee539a" />
|
||||||
|
<use xlink:href="#B" y="-63.419" fill="#d01b68" />
|
||||||
|
<path d="M124.922 29.123l-24.755 14.248-.215.107v28.89l24.97-14.356z" fill="#ec0f68" />
|
||||||
|
<path d="M50.03 43.317l.215-.125L75 28.961 50.048 14.427h-.018L25.06 28.765z" fill="#31838b" />
|
||||||
|
<path d="M50.012 72.189l.018-28.872-24.97-14.535v-.018 28.89.018z" fill="#22626c" />
|
||||||
|
<path d="M75 28.961l-24.755 14.23-.215.125-.018 28.872v.018h.018L75 57.852z" fill="#1b4b56" />
|
||||||
|
<path d="M124.923 58.013l.215-.125 24.737-14.23-24.952-14.535-24.97 14.356z" fill="#cc2a65" />
|
||||||
|
<use xlink:href="#B" x="24.971" y="-48.884" fill="#a21d4c" />
|
||||||
|
<path d="M149.893 43.658l-24.755 14.23-.215.125v28.89l24.97-14.356z" fill="#b62454" />
|
||||||
|
<path d="M74.982 57.835l.215-.107 24.755-14.248-24.97-14.535L50.012 43.3z" fill="#c8d92b" />
|
||||||
|
<path d="M74.982 86.725v-28.89l-24.97-14.517V72.19l.018.018z" fill="#c2d02f" />
|
||||||
|
<path d="M99.952 43.479L75.197 57.727l-.215.107v28.89H75l24.952-14.356z" fill="#b9be33" />
|
||||||
|
<path d="M99.952 72.369l.215-.125 24.755-14.23-24.97-14.535-24.97 14.356z" fill="#33b4d7" />
|
||||||
|
<use xlink:href="#B" y="-34.529" fill="#209ac5" />
|
||||||
|
<path d="M124.922 58.014l-24.755 14.23-.215.125v28.89h.018l24.952-14.356z" fill="#0f8cae" />
|
||||||
|
<path d="M25.06 57.673l.197-.125L50.012 43.3 25.06 28.783h-.018L.089 43.139l24.952 14.535z" fill="#94d6e3" />
|
||||||
|
<path d="M25.042 86.546h.018V57.673L.089 43.139v28.89z" fill="#73ccdd" />
|
||||||
|
<path d="M50.012 43.318l-24.755 14.23-.197.125v28.872.018l24.952-14.356h.018v-.018-28.872z" fill="#3bafbb" />
|
||||||
|
<path d="M50.03 72.19l.215-.107 24.737-14.248L50.03 43.318 25.06 57.674z" fill="#94d6e3" />
|
||||||
|
<path d="M50.03 101.08V72.208v-.018L25.06 57.674v28.872.018z" fill="#73ccdd" />
|
||||||
|
<path d="M74.982 57.835L50.227 72.083l-.197.107v28.89L75 86.725v-28.89z" fill="#3bafbb" />
|
||||||
|
<path d="M75 86.724l.197-.107 24.755-14.248L75 57.834h-.018L50.029 72.189l24.952 14.535z" fill="#33b4d7" />
|
||||||
|
<path d="M74.982 115.614H75v-28.89l-24.97-14.517v28.872.018z" fill="#209ac5" />
|
||||||
|
<path d="M99.952 72.368L75.197 86.617l-.197.107v28.89l24.97-14.356v-28.89z" fill="#0f8cae" />
|
||||||
|
</g>
|
||||||
|
<path d="M759.126 567.007s10.273 21.02 16.364 35.698c25.549 33.869 90.792 36.224 119.235.656 9.484-17.619 16.733-36.357 16.733-36.357-7.297 10.862-20.094 18.056-27.408 22.095-5.197 2.861-17.189 4.59-17.189 4.59l-31.482-16.393-31.663 16.065s-11.832-1.91-17.189-4.426c-10.811-5.799-19.735-12.549-27.401-21.928z" fill="#ffe953" />
|
||||||
|
</g>
|
||||||
|
<defs>
|
||||||
|
<path id="B" d="M99.952 135.788v-28.89l-24.97-14.517v28.872l.018.018z" />
|
||||||
|
</defs>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 9.4 KiB |
|
@ -0,0 +1,63 @@
|
||||||
|
name: Docgen
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
timeout-minutes: 20
|
||||||
|
|
||||||
|
name: 'Generate & upload documentation'
|
||||||
|
runs-on: 'ubuntu-20.04'
|
||||||
|
continue-on-error: true
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
submodules: true
|
||||||
|
|
||||||
|
- uses: jiro4989/setup-nim-action@v1
|
||||||
|
with:
|
||||||
|
nim-version: 'stable'
|
||||||
|
|
||||||
|
- name: Generate doc
|
||||||
|
run: |
|
||||||
|
nim --version
|
||||||
|
nimble --version
|
||||||
|
nimble install_pinned
|
||||||
|
# nim doc can "fail", but the doc is still generated
|
||||||
|
nim doc --git.url:https://github.com/status-im/nim-libp2p --git.commit:${GITHUB_REF##*/} --outdir:${GITHUB_REF##*/} --project libp2p || true
|
||||||
|
|
||||||
|
# check that the folder exists
|
||||||
|
ls ${GITHUB_REF##*/}
|
||||||
|
|
||||||
|
- name: Clone the gh-pages branch
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
repository: status-im/nim-libp2p
|
||||||
|
ref: gh-pages
|
||||||
|
path: subdoc
|
||||||
|
submodules: true
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Commit & push
|
||||||
|
run: |
|
||||||
|
cd subdoc
|
||||||
|
|
||||||
|
# Delete merged branches doc's
|
||||||
|
for branch in $(git branch -vv | grep ': gone]' | awk '{print $1}'); do rm -rf $branch; done
|
||||||
|
|
||||||
|
# Update / create this branch doc
|
||||||
|
rm -rf ${GITHUB_REF##*/}
|
||||||
|
mv ../${GITHUB_REF##*/} .
|
||||||
|
|
||||||
|
# Remove .idx files
|
||||||
|
# NOTE: git also uses idx files in his
|
||||||
|
# internal folder, hence the `*` instead of `.`
|
||||||
|
find * -name "*.idx" -delete
|
||||||
|
git add .
|
||||||
|
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
|
||||||
|
git config --global user.name = "${{ github.actor }}"
|
||||||
|
git commit -a -m "update docs for ${GITHUB_REF##*/}"
|
||||||
|
git push origin gh-pages
|
186
README.md
186
README.md
|
@ -1,5 +1,5 @@
|
||||||
<h1 align="center">
|
<h1 align="center">
|
||||||
<a href="https://libp2p.io"><img width="250" src="https://github.com/libp2p/libp2p/blob/master/logo/black-bg-2.png?raw=true" alt="libp2p hex logo" /></a>
|
<a href="https://libp2p.io"><img width="250" src="./.assets/full-logo.svg?raw=true" alt="nim-libp2p logo" /></a>
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
<h3 align="center">The Nim implementation of the libp2p Networking Stack.</h3>
|
<h3 align="center">The Nim implementation of the libp2p Networking Stack.</h3>
|
||||||
|
@ -18,28 +18,16 @@
|
||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
|
|
||||||
An implementation of [libp2p](https://libp2p.io/) in Nim.
|
An implementation of [libp2p](https://libp2p.io/) in [Nim](https://nim-lang.org/).
|
||||||
|
|
||||||
## Project Status
|
|
||||||
libp2p is used in production by a few projects at [Status](https://github.com/status-im), including [Nimbus](https://github.com/status-im/nimbus-eth2).
|
|
||||||
|
|
||||||
While far from complete, currently available components are stable.
|
|
||||||
|
|
||||||
Check our [examples folder](/examples) to get started!
|
|
||||||
|
|
||||||
# Table of Contents
|
# Table of Contents
|
||||||
- [Background](#background)
|
- [Background](#background)
|
||||||
- [Install](#install)
|
- [Install](#install)
|
||||||
- [Prerequisite](#prerequisite)
|
- [Getting Started](#getting-started)
|
||||||
- [Usage](#usage)
|
- [Modules](#modules)
|
||||||
- [API](#api)
|
- [Users](#users)
|
||||||
- [Getting Started](#getting-started)
|
|
||||||
- [Tutorials and Examples](#tutorials-and-examples)
|
|
||||||
- [Using the Go Daemon](#using-the-go-daemon)
|
|
||||||
- [Development](#development)
|
- [Development](#development)
|
||||||
- [Tests](#tests)
|
- [Contribute](#contribute)
|
||||||
- [Packages](#packages)
|
|
||||||
- [Contribute](#contribute)
|
|
||||||
- [Core Developers](#core-developers)
|
- [Core Developers](#core-developers)
|
||||||
- [License](#license)
|
- [License](#license)
|
||||||
|
|
||||||
|
@ -54,33 +42,63 @@ libp2p grew out of IPFS, but it is built so that lots of people can use it, for
|
||||||
- [Here](https://github.com/libp2p/libp2p#description) is an overview of libp2p and its implementations in other programming languages.
|
- [Here](https://github.com/libp2p/libp2p#description) is an overview of libp2p and its implementations in other programming languages.
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
**Prerequisite**
|
||||||
|
- [Nim](https://nim-lang.org/install.html)
|
||||||
```
|
```
|
||||||
nimble install libp2p
|
nimble install libp2p
|
||||||
```
|
```
|
||||||
### Prerequisite
|
|
||||||
- [Nim](https://nim-lang.org/install.html)
|
|
||||||
|
|
||||||
## Usage
|
## Getting Started
|
||||||
|
You'll find some tutorials [here](examples/tutorial_1_connect.md), or some examples:
|
||||||
|
- [hello world (ping)](examples/helloworld.nim)
|
||||||
|
- [direct chat](examples/directchat.nim)
|
||||||
|
|
||||||
### API
|
**Go Daemon:**
|
||||||
The specification is available in the [docs/api](docs/api) folder.
|
Please find the installation and usage intructions in [daemonapi.md](examples/go-daemon/daemonapi.md).
|
||||||
|
|
||||||
### Getting Started
|
## Modules
|
||||||
Please read the [GETTING_STARTED.md](docs/GETTING_STARTED.md) guide.
|
|
||||||
|
|
||||||
### Tutorials and Examples
|
List of packages modules implemented in nim-libp2p:
|
||||||
Example code can be found in the [examples folder](/examples).
|
|
||||||
|
|
||||||
#### Direct Chat Tutorial
|
| Name | Description |
|
||||||
- [Part I](https://our.status.im/nim-libp2p-tutorial-a-peer-to-peer-chat-example-1/): Set up the main function and use multi-thread for processing IO.
|
| ---------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
|
||||||
- [Part II](https://our.status.im/nim-libp2p-tutorial-a-peer-to-peer-chat-example-2/): Dial remote peer and allow customized user input commands.
|
| **Libp2p** | |
|
||||||
- [Part III](https://our.status.im/nim-libp2p-tutorial-a-peer-to-peer-chat-example-3/): Configure and establish a libp2p node.
|
| [libp2p](libp2p/switch.nim) | The core of the project |
|
||||||
|
| [connmanager](libp2p/connmanager.nim) | Connection manager |
|
||||||
|
| [identify / push identify](libp2p/protocols/identify.nim) | [Identify](https://docs.libp2p.io/concepts/protocols/#identify) protocol |
|
||||||
|
| [ping](libp2p/protocols/ping.nim) | [Ping](https://docs.libp2p.io/concepts/protocols/#ping) protocol |
|
||||||
|
| [libp2p-daemon-client](libp2p/daemon/daemonapi.nim) | [go-daemon](https://github.com/libp2p/go-libp2p-daemon) nim wrapper |
|
||||||
|
| [interop-libp2p](tests/testinterop.nim) | Interop tests |
|
||||||
|
| **Transports** | |
|
||||||
|
| [libp2p-tcp](libp2p/transports/tcptransport.nim) | TCP transport |
|
||||||
|
| [libp2p-ws](libp2p/transports/wstransport.nim) | WebSocket & WebSocket Secure transport |
|
||||||
|
| **Secure Channels** | |
|
||||||
|
| [libp2p-secio](libp2p/protocols/secure/secio.nim) | [Secio](https://docs.libp2p.io/concepts/protocols/#secio) secure channel |
|
||||||
|
| [libp2p-noise](libp2p/protocols/secure/noise.nim) | [Noise](https://github.com/libp2p/specs/tree/master/noise) secure channel |
|
||||||
|
| [libp2p-plaintext](libp2p/protocols/secure/plaintext.nim) | [Plain Text](https://github.com/libp2p/specs/tree/master/plaintext) for development purposes |
|
||||||
|
| **Stream Multiplexers** | |
|
||||||
|
| [libp2p-mplex](libp2p/muxers/mplex/mplex.nim) | [MPlex](https://github.com/libp2p/specs/tree/master/mplex) multiplexer |
|
||||||
|
| **Data Types** | |
|
||||||
|
| [peer-id](libp2p/peerid.nim) | [Cryptographic identifiers](https://docs.libp2p.io/concepts/peer-id/) |
|
||||||
|
| [peer-store](libp2p/peerstore.nim) | ["Phone book" of known peers](https://docs.libp2p.io/concepts/peer-id/#peerinfo) |
|
||||||
|
| [multiaddress](libp2p/multiaddress.nim) | [Composable network addresses](https://github.com/multiformats/multiaddr) |
|
||||||
|
| [signed envelope](libp2p/signed_envelope.nim) | [Signed generic data container](https://github.com/libp2p/specs/blob/master/RFC/0002-signed-envelopes.md) |
|
||||||
|
| [routing record](libp2p/routing_record.nim) | [Signed peer dialing informations](https://github.com/libp2p/specs/blob/master/RFC/0003-routing-records.md) |
|
||||||
|
| **Utilities** | |
|
||||||
|
| [libp2p-crypto](libp2p/crypto) | Cryptographic backend |
|
||||||
|
| [libp2p-crypto-secp256k1](libp2p/crypto/secp.nim) | |
|
||||||
|
| **Pubsub** | |
|
||||||
|
| [libp2p-pubsub](libp2p/protocols/pubsub/pubsub.nim) | Pub-Sub generic interface |
|
||||||
|
| [libp2p-floodsub](libp2p/protocols/pubsub/floodsub.nim) | FloodSub implementation |
|
||||||
|
| [libp2p-gossipsub](libp2p/protocols/pubsub/gossipsub.nim) | [GossipSub](https://docs.libp2p.io/concepts/publish-subscribe/) implementation |
|
||||||
|
|
||||||
|
## Users
|
||||||
|
|
||||||
### Using the Go Daemon
|
nim-libp2p is used by:
|
||||||
Please find the installation and usage intructions in [daemonapi.md](docs/api/libp2p/daemonapi.md).
|
- [Nimbus](https://github.com/status-im/nimbus-eth2), an Ethereum client
|
||||||
|
- [nwaku](https://github.com/status-im/nwaku), a decentralized messaging application
|
||||||
Examples can be found in the [examples/go-daemon folder](https://github.com/status-im/nim-libp2p/tree/readme/examples/go-daemon);
|
- [nim-codex](https://github.com/status-im/nim-codex), a decentralized storage application
|
||||||
|
- (open a pull request if you want to be included here)
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
**Clone and Install dependencies:**
|
**Clone and Install dependencies:**
|
||||||
|
@ -90,96 +108,47 @@ git clone https://github.com/status-im/nim-libp2p
|
||||||
cd nim-libp2p
|
cd nim-libp2p
|
||||||
nimble install
|
nimble install
|
||||||
```
|
```
|
||||||
#### Run unit tests
|
|
||||||
|
**Run unit tests**
|
||||||
```sh
|
```sh
|
||||||
# run all the unit tests
|
# run all the unit tests
|
||||||
nimble test
|
nimble test
|
||||||
```
|
```
|
||||||
The code follows the [Status Nim Style Guide](https://status-im.github.io/nim-style-guide/).
|
The code follows the [Status Nim Style Guide](https://status-im.github.io/nim-style-guide/).
|
||||||
|
|
||||||
### Packages
|
|
||||||
|
|
||||||
List of packages currently in existence for nim-libp2p:
|
### Contribute
|
||||||
|
|
||||||
#### Libp2p
|
|
||||||
- [libp2p](https://github.com/status-im/nim-libp2p)
|
|
||||||
- [libp2p-daemon-client](https://github.com/status-im/nim-libp2p/blob/master/libp2p/daemon/daemonapi.nim)
|
|
||||||
- [interop-libp2p](https://github.com/status-im/nim-libp2p/blob/master/tests/testinterop.nim)
|
|
||||||
|
|
||||||
#### Transports
|
|
||||||
- [libp2p-tcp](https://github.com/status-im/nim-libp2p/blob/master/libp2p/transports/tcptransport.nim)
|
|
||||||
- [libp2p-ws](https://github.com/status-im/nim-libp2p/blob/master/libp2p/transports/wstransport.nim)
|
|
||||||
|
|
||||||
#### Secure Channels
|
|
||||||
- [libp2p-secio](https://github.com/status-im/nim-libp2p/blob/master/libp2p/protocols/secure/secio.nim)
|
|
||||||
- [libp2p-noise](https://github.com/status-im/nim-libp2p/blob/master/libp2p/protocols/secure/noise.nim)
|
|
||||||
- [libp2p-plaintext](https://github.com/status-im/nim-libp2p/blob/master/libp2p/protocols/secure/plaintext.nim)
|
|
||||||
|
|
||||||
#### Stream Multiplexers
|
|
||||||
- [libp2p-mplex](https://github.com/status-im/nim-libp2p/blob/master/libp2p/muxers/mplex/mplex.nim)
|
|
||||||
|
|
||||||
#### Utilities
|
|
||||||
- [libp2p-crypto](https://github.com/status-im/nim-libp2p/tree/master/libp2p/crypto)
|
|
||||||
- [libp2p-crypto-secp256k1](https://github.com/status-im/nim-libp2p/blob/master/libp2p/crypto/secp.nim)
|
|
||||||
|
|
||||||
#### Data Types
|
|
||||||
- [peer-id](https://github.com/status-im/nim-libp2p/blob/master/libp2p/peer.nim)
|
|
||||||
- [peer-info](https://github.com/status-im/nim-libp2p/blob/master/libp2p/peerinfo.nim)
|
|
||||||
|
|
||||||
#### Pubsub
|
|
||||||
- [libp2p-pubsub](https://github.com/status-im/nim-libp2p/blob/master/libp2p/protocols/pubsub/pubsub.nim)
|
|
||||||
- [libp2p-floodsub](https://github.com/status-im/nim-libp2p/blob/master/libp2p/protocols/pubsub/floodsub.nim)
|
|
||||||
- [libp2p-gossipsub](https://github.com/status-im/nim-libp2p/blob/master/libp2p/protocols/pubsub/gossipsub.nim)
|
|
||||||
|
|
||||||
|
|
||||||
Packages that exist in the original libp2p specs and are under active development:
|
|
||||||
- libp2p-daemon
|
|
||||||
- libp2p-webrtc-direct
|
|
||||||
- libp2p-webrtc-star
|
|
||||||
- libp2p-spdy
|
|
||||||
- libp2p-bootstrap
|
|
||||||
- libp2p-kad-dht
|
|
||||||
- libp2p-mdns
|
|
||||||
- libp2p-webrtc-star
|
|
||||||
- libp2p-delegated-content-routing
|
|
||||||
- libp2p-delegated-peer-routing
|
|
||||||
- libp2p-nat-mgnr
|
|
||||||
- libp2p-utils
|
|
||||||
|
|
||||||
** Note that the current stack reflects the minimal requirements for the upcoming Eth2 implementation.
|
|
||||||
|
|
||||||
### Tips and tricks
|
|
||||||
|
|
||||||
#### enable expensive metrics:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
nim c -d:libp2p_expensive_metrics some_file.nim
|
|
||||||
```
|
|
||||||
|
|
||||||
#### use identify metrics
|
|
||||||
|
|
||||||
```bash
|
|
||||||
nim c -d:libp2p_agents_metrics -d:KnownLibP2PAgents=nimbus,lighthouse,prysm,teku some_file.nim
|
|
||||||
```
|
|
||||||
|
|
||||||
### specify gossipsub specific topics to measure
|
|
||||||
|
|
||||||
```bash
|
|
||||||
nim c -d:KnownLibP2PTopics=topic1,topic2,topic3 some_file.nim
|
|
||||||
```
|
|
||||||
|
|
||||||
## Contribute
|
|
||||||
|
|
||||||
The libp2p implementation in Nim is a work in progress. We welcome contributors to help out! Specifically, you can:
|
The libp2p implementation in Nim is a work in progress. We welcome contributors to help out! Specifically, you can:
|
||||||
- Go through the modules and **check out existing issues**. This would be especially useful for modules in active development. Some knowledge of IPFS/libp2p may be required, as well as the infrastructure behind it.
|
- Go through the modules and **check out existing issues**. This would be especially useful for modules in active development. Some knowledge of IPFS/libp2p may be required, as well as the infrastructure behind it.
|
||||||
- **Perform code reviews**. Feel free to let us know if you found anything that can a) speed up the project development b) ensure better quality and c) reduce possible future bugs.
|
- **Perform code reviews**. Feel free to let us know if you found anything that can a) speed up the project development b) ensure better quality and c) reduce possible future bugs.
|
||||||
- **Add tests**. Help nim-libp2p to be more robust by adding more tests to the [tests folder](https://github.com/status-im/nim-libp2p/tree/master/tests).
|
- **Add tests**. Help nim-libp2p to be more robust by adding more tests to the [tests folder](tests/).
|
||||||
|
|
||||||
The code follows the [Status Nim Style Guide](https://status-im.github.io/nim-style-guide/).
|
The code follows the [Status Nim Style Guide](https://status-im.github.io/nim-style-guide/).
|
||||||
|
|
||||||
### Core Developers
|
### Core Developers
|
||||||
[@cheatfate](https://github.com/cheatfate), [Dmitriy Ryajov](https://github.com/dryajov), [Tanguy](https://github.com/Menduist), [Zahary Karadjov](https://github.com/zah)
|
[@cheatfate](https://github.com/cheatfate), [Dmitriy Ryajov](https://github.com/dryajov), [Tanguy](https://github.com/Menduist), [Zahary Karadjov](https://github.com/zah)
|
||||||
|
|
||||||
|
### Tips and tricks
|
||||||
|
|
||||||
|
**enable expensive metrics:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
nim c -d:libp2p_expensive_metrics some_file.nim
|
||||||
|
```
|
||||||
|
|
||||||
|
**use identify metrics**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
nim c -d:libp2p_agents_metrics -d:KnownLibP2PAgents=nimbus,lighthouse,prysm,teku some_file.nim
|
||||||
|
```
|
||||||
|
|
||||||
|
**specify gossipsub specific topics to measure**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
nim c -d:KnownLibP2PTopics=topic1,topic2,topic3 some_file.nim
|
||||||
|
```
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
Licensed and distributed under either of
|
Licensed and distributed under either of
|
||||||
|
@ -191,4 +160,3 @@ or
|
||||||
* Apache License, Version 2.0, ([LICENSE-APACHEv2](LICENSE-APACHEv2) or http://www.apache.org/licenses/LICENSE-2.0)
|
* Apache License, Version 2.0, ([LICENSE-APACHEv2](LICENSE-APACHEv2) or http://www.apache.org/licenses/LICENSE-2.0)
|
||||||
|
|
||||||
at your option. These files may not be copied, modified, or distributed except according to those terms.
|
at your option. These files may not be copied, modified, or distributed except according to those terms.
|
||||||
|
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
# API
|
|
||||||
|
|
||||||
Coming Soon...
|
|
|
@ -1,7 +0,0 @@
|
||||||
# Getting Started
|
|
||||||
Welcome to nim-libp2p!
|
|
||||||
|
|
||||||
|
|
||||||
To get started, please look at the [tutorials](../examples/tutorial_1_connect.md)
|
|
||||||
|
|
||||||
For more concrete examples, you can look at the [hello world example](../examples/helloworld.nim) or the [direct chat](../examples/directchat.nim)
|
|
|
@ -1,29 +0,0 @@
|
||||||
# Introduction
|
|
||||||
This folder contains the documentation for each nim-libp2p module and the sample code for the tutorials.
|
|
||||||
|
|
||||||
# Table of Contents
|
|
||||||
### [Getting Started](GETTING_STARTED.md)
|
|
||||||
### Tutorials
|
|
||||||
- P2P Chat Example
|
|
||||||
- [part I](tutorial/directchat/start.nim)
|
|
||||||
- [part II](tutorial/directchat/second.nim)
|
|
||||||
### API Specifications
|
|
||||||
- libp2p
|
|
||||||
- [libp2p-daemon-client](api/libp2p/daemonapi.md)
|
|
||||||
- [interop-libp2p](api/libp2p/interop.md)
|
|
||||||
- transports
|
|
||||||
- [libp2p-tcp](api/transports/tcptransport.md)
|
|
||||||
- secure channels
|
|
||||||
- [libp2p-secio](api/secure_channels/secio.md)
|
|
||||||
- stream multiplexers
|
|
||||||
- [libp2p-mplex](api/stream_multiplexers/mplex.md)
|
|
||||||
- utilities
|
|
||||||
- [libp2p-crypto](api/utilities/crypto.md)
|
|
||||||
- [libp2p-crypto-secp256k1](api/utilities/secp256k1.md)
|
|
||||||
- data types
|
|
||||||
- [peer-id](api/data_types/peer.md)
|
|
||||||
- [peer-info](api/data_types/peerinfo.md)
|
|
||||||
- pubsub
|
|
||||||
- [libp2p-pubsub](api/pubsub/pubsub.md)
|
|
||||||
- [libp2p-floodsub](api/pubsub/floodsub.md)
|
|
||||||
- [libp2p-gossipsub](api/pubsub/gossipsub.md)
|
|
|
@ -1,149 +0,0 @@
|
||||||
when not(compileOption("threads")):
|
|
||||||
{.fatal: "Please, compile this program with the --threads:on option!".}
|
|
||||||
|
|
||||||
import tables, strformat, strutils
|
|
||||||
import chronos
|
|
||||||
import ../libp2p/[switch,
|
|
||||||
multistream,
|
|
||||||
crypto/crypto,
|
|
||||||
protocols/identify,
|
|
||||||
connection,
|
|
||||||
transports/transport,
|
|
||||||
transports/tcptransport,
|
|
||||||
multiaddress,
|
|
||||||
peerinfo,
|
|
||||||
peerid,
|
|
||||||
protocols/protocol,
|
|
||||||
protocols/secure/secure,
|
|
||||||
protocols/secure/secio,
|
|
||||||
muxers/muxer,
|
|
||||||
muxers/mplex/mplex]
|
|
||||||
|
|
||||||
const ChatCodec = "/nim-libp2p/chat/1.0.0"
|
|
||||||
const DefaultAddr = "/ip4/127.0.0.1/tcp/55505"
|
|
||||||
|
|
||||||
const Help = """
|
|
||||||
Commands: /[?|hep|connect|disconnect|exit]
|
|
||||||
help: Prints this help
|
|
||||||
connect: dials a remote peer
|
|
||||||
disconnect: ends current session
|
|
||||||
exit: closes the chat
|
|
||||||
"""
|
|
||||||
|
|
||||||
type ChatProto = ref object of LPProtocol
|
|
||||||
switch: Switch # a single entry point for dialing and listening to peer
|
|
||||||
transp: StreamTransport # transport streams between read & write file descriptor
|
|
||||||
conn: Connection # create and close read & write stream
|
|
||||||
connected: bool # if the node is connected to another peer
|
|
||||||
started: bool # if the node has started
|
|
||||||
|
|
||||||
# copied from https://github.com/status-im/nimbus-eth2/blob/0ed657e953740a92458f23033d47483ffa17ccb0/beacon_chain/eth2_network.nim#L109-L115
|
|
||||||
proc initAddress(T: type MultiAddress, str: string): T =
|
|
||||||
let address = MultiAddress.init(str)
|
|
||||||
if IPFS.match(address) and matchPartial(multiaddress.TCP, address):
|
|
||||||
result = address
|
|
||||||
else:
|
|
||||||
raise newException(MultiAddressError,
|
|
||||||
"Invalid bootstrap node multi-address")
|
|
||||||
|
|
||||||
proc dialPeer(p: ChatProto, address: string) {.async.} =
|
|
||||||
let multiAddr = MultiAddress.initAddress(address);
|
|
||||||
let parts = address.split("/")
|
|
||||||
let remotePeer = PeerInfo.init(parts[^1],
|
|
||||||
[multiAddr])
|
|
||||||
|
|
||||||
echo &"dialing peer: {multiAddr}"
|
|
||||||
p.conn = await p.switch.dial(remotePeer, ChatCodec)
|
|
||||||
p.connected = true
|
|
||||||
|
|
||||||
proc readAndPrint(p: ChatProto) {.async.} =
|
|
||||||
while true:
|
|
||||||
while p.connected:
|
|
||||||
echo cast[string](await p.conn.readLp(1024))
|
|
||||||
await sleepAsync(100.millis)
|
|
||||||
|
|
||||||
proc writeAndPrint(p: ChatProto) {.async.} =
|
|
||||||
while true:
|
|
||||||
if not p.connected:
|
|
||||||
echo "type an address or wait for a connection:"
|
|
||||||
echo "type /[help|?] for help"
|
|
||||||
|
|
||||||
let line = await p.transp.readLine()
|
|
||||||
if line.startsWith("/help") or line.startsWith("/?") or not p.started:
|
|
||||||
echo Help
|
|
||||||
continue
|
|
||||||
|
|
||||||
if line.startsWith("/disconnect"):
|
|
||||||
echo "Ending current session"
|
|
||||||
if p.connected and p.conn.closed.not:
|
|
||||||
await p.conn.close()
|
|
||||||
p.connected = false
|
|
||||||
elif line.startsWith("/connect"):
|
|
||||||
if p.connected:
|
|
||||||
var yesno = "N"
|
|
||||||
echo "a session is already in progress, do you want end it [y/N]?"
|
|
||||||
yesno = await p.transp.readLine()
|
|
||||||
if yesno.cmpIgnoreCase("y") == 0:
|
|
||||||
await p.conn.close()
|
|
||||||
p.connected = false
|
|
||||||
elif yesno.cmpIgnoreCase("n") == 0:
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
echo "unrecognized response"
|
|
||||||
continue
|
|
||||||
|
|
||||||
echo "enter address of remote peer"
|
|
||||||
let address = await p.transp.readLine()
|
|
||||||
if address.len > 0:
|
|
||||||
await p.dialPeer(address)
|
|
||||||
|
|
||||||
elif line.startsWith("/exit"):
|
|
||||||
if p.connected and p.conn.closed.not:
|
|
||||||
await p.conn.close()
|
|
||||||
p.connected = false
|
|
||||||
|
|
||||||
await p.switch.stop()
|
|
||||||
echo "quitting..."
|
|
||||||
quit(0)
|
|
||||||
else:
|
|
||||||
if p.connected:
|
|
||||||
await p.conn.writeLp(line)
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
if line.startsWith("/") and "ipfs" in line:
|
|
||||||
await p.dialPeer(line)
|
|
||||||
except:
|
|
||||||
echo &"unable to dial remote peer {line}"
|
|
||||||
echo getCurrentExceptionMsg()
|
|
||||||
|
|
||||||
proc readWriteLoop(p: ChatProto) {.async.} =
|
|
||||||
asyncSpawn p.writeAndPrint() # execute the async function but does not block
|
|
||||||
asyncSpawn p.readAndPrint()
|
|
||||||
|
|
||||||
proc processInput(rfd: AsyncFD) {.async.} =
|
|
||||||
let transp = fromPipe(rfd)
|
|
||||||
while true:
|
|
||||||
let a = await transp.readLine()
|
|
||||||
echo "You just entered: " & a
|
|
||||||
|
|
||||||
proc readInput(wfd: AsyncFD) {.thread.} =
|
|
||||||
## This procedure performs reading from `stdin` and sends data over
|
|
||||||
## pipe to main thread.
|
|
||||||
let transp = fromPipe(wfd)
|
|
||||||
|
|
||||||
while true:
|
|
||||||
let line = stdin.readLine()
|
|
||||||
discard waitFor transp.write(line & "\r\n")
|
|
||||||
|
|
||||||
proc main() {.async.} =
|
|
||||||
let (rfd, wfd) = createAsyncPipe()
|
|
||||||
if rfd == asyncInvalidPipe or wfd == asyncInvalidPipe:
|
|
||||||
raise newException(ValueError, "Could not initialize pipe!")
|
|
||||||
|
|
||||||
var thread: Thread[AsyncFD]
|
|
||||||
thread.createThread(readInput, wfd)
|
|
||||||
|
|
||||||
await processInput(rfd)
|
|
||||||
|
|
||||||
when isMainModule: # isMainModule = true when the module is compiled as the main file
|
|
||||||
waitFor(main())
|
|
|
@ -1,39 +0,0 @@
|
||||||
when not(compileOption("threads")):
|
|
||||||
{.fatal: "Please, compile this program with the --threads:on option!".}
|
|
||||||
|
|
||||||
import chronos # an efficient library for async
|
|
||||||
|
|
||||||
proc processInput(rfd: AsyncFD) {.async.} =
|
|
||||||
echo "Type something below to see if the multithread IO works:\nType 'exit' to exit."
|
|
||||||
|
|
||||||
let transp = fromPipe(rfd)
|
|
||||||
while true:
|
|
||||||
let a = await transp.readLine()
|
|
||||||
|
|
||||||
if a == "exit":
|
|
||||||
quit(0);
|
|
||||||
|
|
||||||
echo "You just entered: " & a
|
|
||||||
|
|
||||||
proc readInput(wfd: AsyncFD) {.thread.} =
|
|
||||||
## This procedure performs reading from `stdin` and sends data over
|
|
||||||
## pipe to main thread.
|
|
||||||
let transp = fromPipe(wfd)
|
|
||||||
|
|
||||||
while true:
|
|
||||||
let line = stdin.readLine()
|
|
||||||
discard waitFor transp.write(line & "\r\n")
|
|
||||||
|
|
||||||
proc main() {.async.} =
|
|
||||||
let (rfd, wfd) = createAsyncPipe()
|
|
||||||
if rfd == asyncInvalidPipe or wfd == asyncInvalidPipe:
|
|
||||||
raise newException(ValueError, "Could not initialize pipe!")
|
|
||||||
|
|
||||||
var thread: Thread[AsyncFD]
|
|
||||||
thread.createThread(readInput, wfd)
|
|
||||||
|
|
||||||
await processInput(rfd)
|
|
||||||
|
|
||||||
when isMainModule: # isMainModule = true when the module is compiled as the main file
|
|
||||||
waitFor(main())
|
|
||||||
|
|
|
@ -1,205 +0,0 @@
|
||||||
when not(compileOption("threads")):
|
|
||||||
{.fatal: "Please, compile this program with the --threads:on option!".}
|
|
||||||
|
|
||||||
import tables, strformat, strutils, bearssl
|
|
||||||
import chronos # an efficient library for async
|
|
||||||
import ../libp2p/[switch, # manage transports, a single entry point for dialing and listening
|
|
||||||
builders, # helper to build the switch object
|
|
||||||
multistream, # tag stream with short header to identify it
|
|
||||||
multicodec, # multicodec utilities
|
|
||||||
crypto/crypto, # cryptographic functions
|
|
||||||
errors, # error handling utilities
|
|
||||||
protocols/identify, # identify the peer info of a peer
|
|
||||||
stream/connection, # create and close stream read / write connections
|
|
||||||
transports/transport, # listen and dial to other peers using p2p protocol
|
|
||||||
transports/tcptransport, # listen and dial to other peers using client-server protocol
|
|
||||||
multiaddress, # encode different addressing schemes. For example, /ip4/7.7.7.7/tcp/6543 means it is using IPv4 protocol and TCP
|
|
||||||
peerinfo, # manage the information of a peer, such as peer ID and public / private key
|
|
||||||
peerid, # Implement how peers interact
|
|
||||||
protocols/protocol, # define the protocol base type
|
|
||||||
protocols/secure/secure, # define the protocol of secure connection
|
|
||||||
protocols/secure/secio, # define the protocol of secure input / output, allows encrypted communication that uses public keys to validate signed messages instead of a certificate authority like in TLS
|
|
||||||
muxers/muxer, # define an interface for stream multiplexing, allowing peers to offer many protocols over a single connection
|
|
||||||
muxers/mplex/mplex] # define some contants and message types for stream multiplexing
|
|
||||||
|
|
||||||
const ChatCodec = "/nim-libp2p/chat/1.0.0"
|
|
||||||
const DefaultAddr = "/ip4/127.0.0.1/tcp/55505"
|
|
||||||
|
|
||||||
const Help = """
|
|
||||||
Commands: /[?|hep|connect|disconnect|exit]
|
|
||||||
help: Prints this help
|
|
||||||
connect: dials a remote peer
|
|
||||||
disconnect: ends current session
|
|
||||||
exit: closes the chat
|
|
||||||
"""
|
|
||||||
|
|
||||||
type ChatProto = ref object of LPProtocol
|
|
||||||
switch: Switch # a single entry point for dialing and listening to peer
|
|
||||||
transp: StreamTransport # transport streams between read & write file descriptor
|
|
||||||
conn: Connection # create and close read & write stream
|
|
||||||
connected: bool # if the node is connected to another peer
|
|
||||||
started: bool # if the node has started
|
|
||||||
|
|
||||||
proc readAndPrint(p: ChatProto) {.async.} =
|
|
||||||
while true:
|
|
||||||
var strData = await p.conn.readLp(1024)
|
|
||||||
strData &= '\0'.uint8
|
|
||||||
var str = cast[cstring](addr strdata[0])
|
|
||||||
echo $p.switch.peerInfo.peerId & ": " & $str
|
|
||||||
await sleepAsync(100.millis)
|
|
||||||
|
|
||||||
proc dialPeer(p: ChatProto, address: string) {.async.} =
|
|
||||||
let
|
|
||||||
multiAddr = MultiAddress.init(address).tryGet()
|
|
||||||
# split the peerId part /p2p/...
|
|
||||||
peerIdBytes = multiAddr[multiCodec("p2p")]
|
|
||||||
.tryGet()
|
|
||||||
.protoAddress()
|
|
||||||
.tryGet()
|
|
||||||
remotePeer = PeerId.init(peerIdBytes).tryGet()
|
|
||||||
# split the wire address
|
|
||||||
ip4Addr = multiAddr[multiCodec("ip4")].tryGet()
|
|
||||||
tcpAddr = multiAddr[multiCodec("tcp")].tryGet()
|
|
||||||
wireAddr = ip4Addr & tcpAddr
|
|
||||||
|
|
||||||
echo &"dialing peer: {multiAddr}"
|
|
||||||
p.conn = await p.switch.dial(remotePeer, @[wireAddr], ChatCodec)
|
|
||||||
p.connected = true
|
|
||||||
asyncSpawn p.readAndPrint()
|
|
||||||
|
|
||||||
proc writeAndPrint(p: ChatProto) {.async.} =
|
|
||||||
while true:
|
|
||||||
if not p.connected:
|
|
||||||
echo "type an address or wait for a connection:"
|
|
||||||
echo "type /[help|?] for help"
|
|
||||||
|
|
||||||
let line = await p.transp.readLine()
|
|
||||||
if line.startsWith("/help") or line.startsWith("/?") or not p.started:
|
|
||||||
echo Help
|
|
||||||
continue
|
|
||||||
|
|
||||||
if line.startsWith("/disconnect"):
|
|
||||||
echo "Ending current session"
|
|
||||||
if p.connected and p.conn.closed.not:
|
|
||||||
await p.conn.close()
|
|
||||||
p.connected = false
|
|
||||||
elif line.startsWith("/connect"):
|
|
||||||
if p.connected:
|
|
||||||
var yesno = "N"
|
|
||||||
echo "a session is already in progress, do you want end it [y/N]?"
|
|
||||||
yesno = await p.transp.readLine()
|
|
||||||
if yesno.cmpIgnoreCase("y") == 0:
|
|
||||||
await p.conn.close()
|
|
||||||
p.connected = false
|
|
||||||
elif yesno.cmpIgnoreCase("n") == 0:
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
echo "unrecognized response"
|
|
||||||
continue
|
|
||||||
|
|
||||||
echo "enter address of remote peer"
|
|
||||||
let address = await p.transp.readLine()
|
|
||||||
if address.len > 0:
|
|
||||||
await p.dialPeer(address)
|
|
||||||
|
|
||||||
elif line.startsWith("/exit"):
|
|
||||||
if p.connected and p.conn.closed.not:
|
|
||||||
await p.conn.close()
|
|
||||||
p.connected = false
|
|
||||||
|
|
||||||
await p.switch.stop()
|
|
||||||
echo "quitting..."
|
|
||||||
quit(0)
|
|
||||||
else:
|
|
||||||
if p.connected:
|
|
||||||
await p.conn.writeLp(line)
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
if line.startsWith("/") and "p2p" in line:
|
|
||||||
await p.dialPeer(line)
|
|
||||||
except:
|
|
||||||
echo &"unable to dial remote peer {line}"
|
|
||||||
echo getCurrentExceptionMsg()
|
|
||||||
|
|
||||||
proc readWriteLoop(p: ChatProto) {.async.} =
|
|
||||||
await p.writeAndPrint()
|
|
||||||
|
|
||||||
proc newChatProto(switch: Switch, transp: StreamTransport): ChatProto =
|
|
||||||
var chatproto = ChatProto(switch: switch, transp: transp, codecs: @[ChatCodec])
|
|
||||||
|
|
||||||
# create handler for incoming connection
|
|
||||||
proc handle(stream: Connection, proto: string) {.async.} =
|
|
||||||
if chatproto.connected and not chatproto.conn.closed:
|
|
||||||
echo "a chat session is already in progress - disconnecting!"
|
|
||||||
await stream.close()
|
|
||||||
else:
|
|
||||||
chatproto.conn = stream
|
|
||||||
chatproto.connected = true
|
|
||||||
await chatproto.readAndPrint()
|
|
||||||
|
|
||||||
# assign the new handler
|
|
||||||
chatproto.handler = handle
|
|
||||||
return chatproto
|
|
||||||
|
|
||||||
proc readInput(wfd: AsyncFD) {.thread.} =
|
|
||||||
## This procedure performs reading from `stdin` and sends data over
|
|
||||||
## pipe to main thread.
|
|
||||||
let transp = fromPipe(wfd)
|
|
||||||
|
|
||||||
while true:
|
|
||||||
let line = stdin.readLine()
|
|
||||||
discard waitFor transp.write(line & "\r\n")
|
|
||||||
|
|
||||||
proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} =
|
|
||||||
let transp = fromPipe(rfd)
|
|
||||||
|
|
||||||
let seckey = PrivateKey.random(RSA, rng[]).get()
|
|
||||||
var localAddress = DefaultAddr
|
|
||||||
while true:
|
|
||||||
echo &"Type an address to bind to or Enter to use the default {DefaultAddr}"
|
|
||||||
let a = await transp.readLine()
|
|
||||||
try:
|
|
||||||
if a.len > 0:
|
|
||||||
localAddress = a
|
|
||||||
break
|
|
||||||
# uise default
|
|
||||||
break
|
|
||||||
except:
|
|
||||||
echo "invalid address"
|
|
||||||
localAddress = DefaultAddr
|
|
||||||
continue
|
|
||||||
|
|
||||||
var switch = SwitchBuilder
|
|
||||||
.init()
|
|
||||||
.withRng(rng)
|
|
||||||
.withPrivateKey(seckey)
|
|
||||||
.withAddress(MultiAddress.init(localAddress).tryGet())
|
|
||||||
.build()
|
|
||||||
|
|
||||||
let chatProto = newChatProto(switch, transp)
|
|
||||||
switch.mount(chatProto)
|
|
||||||
let libp2pFuts = await switch.start()
|
|
||||||
chatProto.started = true
|
|
||||||
|
|
||||||
let id = $switch.peerInfo.peerId
|
|
||||||
echo "PeerId: " & id
|
|
||||||
echo "listening on: "
|
|
||||||
for a in switch.peerInfo.addrs:
|
|
||||||
echo &"{a}/p2p/{id}"
|
|
||||||
|
|
||||||
await chatProto.readWriteLoop()
|
|
||||||
await allFuturesThrowing(libp2pFuts)
|
|
||||||
|
|
||||||
proc main() {.async.} =
|
|
||||||
let rng = newRng() # Singe random number source for the whole application
|
|
||||||
let (rfd, wfd) = createAsyncPipe()
|
|
||||||
if rfd == asyncInvalidPipe or wfd == asyncInvalidPipe:
|
|
||||||
raise newException(ValueError, "Could not initialize pipe!")
|
|
||||||
|
|
||||||
var thread: Thread[AsyncFD]
|
|
||||||
thread.createThread(readInput, wfd)
|
|
||||||
|
|
||||||
await processInput(rfd, rng)
|
|
||||||
|
|
||||||
when isMainModule: # isMainModule = true when the module is compiled as the main file
|
|
||||||
waitFor(main())
|
|
|
@ -1,39 +0,0 @@
|
||||||
when not(compileOption("threads")):
|
|
||||||
{.fatal: "Please, compile this program with the --threads:on option!".}
|
|
||||||
|
|
||||||
import chronos # an efficient library for async
|
|
||||||
|
|
||||||
proc processInput(rfd: AsyncFD) {.async.} =
|
|
||||||
echo "Type something below to see if the multithread IO works:\nType 'exit' to exit."
|
|
||||||
|
|
||||||
let transp = fromPipe(rfd)
|
|
||||||
while true:
|
|
||||||
let a = await transp.readLine()
|
|
||||||
|
|
||||||
if a == "exit":
|
|
||||||
quit(0);
|
|
||||||
|
|
||||||
echo "You just entered: " & a
|
|
||||||
|
|
||||||
proc readInput(wfd: AsyncFD) {.thread.} =
|
|
||||||
## This procedure performs reading from `stdin` and sends data over
|
|
||||||
## pipe to main thread.
|
|
||||||
let transp = fromPipe(wfd)
|
|
||||||
|
|
||||||
while true:
|
|
||||||
let line = stdin.readLine()
|
|
||||||
discard waitFor transp.write(line & "\r\n")
|
|
||||||
|
|
||||||
proc main() {.async.} =
|
|
||||||
let (rfd, wfd) = createAsyncPipe()
|
|
||||||
if rfd == asyncInvalidPipe or wfd == asyncInvalidPipe:
|
|
||||||
raise newException(ValueError, "Could not initialize pipe!")
|
|
||||||
|
|
||||||
var thread: Thread[AsyncFD]
|
|
||||||
thread.createThread(readInput, wfd)
|
|
||||||
|
|
||||||
await processInput(rfd)
|
|
||||||
|
|
||||||
when isMainModule: # isMainModule = true when the module is compiled as the main file
|
|
||||||
waitFor(main())
|
|
||||||
|
|
106
libp2p.nim
106
libp2p.nim
|
@ -1,38 +1,72 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2018 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
import
|
when defined(nimdoc):
|
||||||
libp2p/[protobuf/minprotobuf,
|
## Welcome to the nim-libp2p documentation!
|
||||||
muxers/muxer,
|
##
|
||||||
muxers/mplex/mplex,
|
## On the left, you'll find a switch that allows you to see private
|
||||||
stream/lpstream,
|
## procedures. By default, you'll only see the public one (marked with `{.public.}`)
|
||||||
stream/bufferstream,
|
##
|
||||||
stream/connection,
|
## The difference between public and private procedures is that public procedure
|
||||||
transports/transport,
|
## stay backward compatible during the Major version, whereas private ones can
|
||||||
transports/tcptransport,
|
## change at each new Minor version.
|
||||||
protocols/secure/noise,
|
##
|
||||||
cid,
|
## If you're new to nim-libp2p, you can find a tutorial `here<https://github.com/status-im/nim-libp2p/blob/master/examples/tutorial_1_connect.md>`_
|
||||||
multihash,
|
## that can help you get started.
|
||||||
multibase,
|
|
||||||
multicodec,
|
|
||||||
errors,
|
|
||||||
switch,
|
|
||||||
peerid,
|
|
||||||
peerinfo,
|
|
||||||
multiaddress,
|
|
||||||
builders,
|
|
||||||
crypto/crypto,
|
|
||||||
protocols/pubsub]
|
|
||||||
|
|
||||||
export
|
# Import stuff for doc
|
||||||
minprotobuf, switch, peerid, peerinfo,
|
import libp2p/[
|
||||||
connection, multiaddress, crypto, lpstream,
|
protobuf/minprotobuf,
|
||||||
bufferstream, muxer, mplex, transport,
|
switch,
|
||||||
tcptransport, noise, errors, cid, multihash,
|
stream/lpstream,
|
||||||
multicodec, builders, pubsub
|
builders,
|
||||||
|
transports/tcptransport,
|
||||||
|
transports/wstransport,
|
||||||
|
protocols/ping,
|
||||||
|
protocols/pubsub,
|
||||||
|
peerid,
|
||||||
|
peerinfo,
|
||||||
|
peerstore,
|
||||||
|
multiaddress]
|
||||||
|
|
||||||
|
proc dummyPrivateProc*() =
|
||||||
|
## A private proc example
|
||||||
|
discard
|
||||||
|
else:
|
||||||
|
import
|
||||||
|
libp2p/[protobuf/minprotobuf,
|
||||||
|
muxers/muxer,
|
||||||
|
muxers/mplex/mplex,
|
||||||
|
stream/lpstream,
|
||||||
|
stream/bufferstream,
|
||||||
|
stream/connection,
|
||||||
|
transports/transport,
|
||||||
|
transports/tcptransport,
|
||||||
|
transports/wstransport,
|
||||||
|
protocols/secure/noise,
|
||||||
|
protocols/ping,
|
||||||
|
cid,
|
||||||
|
multihash,
|
||||||
|
multibase,
|
||||||
|
multicodec,
|
||||||
|
errors,
|
||||||
|
switch,
|
||||||
|
peerid,
|
||||||
|
peerinfo,
|
||||||
|
multiaddress,
|
||||||
|
builders,
|
||||||
|
crypto/crypto,
|
||||||
|
protocols/pubsub]
|
||||||
|
|
||||||
|
export
|
||||||
|
minprotobuf, switch, peerid, peerinfo,
|
||||||
|
connection, multiaddress, crypto, lpstream,
|
||||||
|
bufferstream, muxer, mplex, transport,
|
||||||
|
tcptransport, noise, errors, cid, multihash,
|
||||||
|
multicodec, builders, pubsub
|
||||||
|
|
|
@ -102,6 +102,23 @@ task examples_build, "Build the samples":
|
||||||
buildTutorial("examples/tutorial_1_connect.md")
|
buildTutorial("examples/tutorial_1_connect.md")
|
||||||
buildTutorial("examples/tutorial_2_customproto.md")
|
buildTutorial("examples/tutorial_2_customproto.md")
|
||||||
|
|
||||||
|
proc tutorialToHtml(source, output: string) =
|
||||||
|
var html = gorge("./nimbledeps/bin/markdown < " & source)
|
||||||
|
html &= """
|
||||||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css">
|
||||||
|
<link rel="stylesheet" href="https://unpkg.com/@highlightjs/cdn-assets@11.5.1/styles/default.min.css">
|
||||||
|
<script src="https://unpkg.com/@highlightjs/cdn-assets@11.5.1/highlight.min.js"></script>
|
||||||
|
<script src="https://unpkg.com/@highlightjs/cdn-assets@11.5.1/languages/nim.min.js"></script>
|
||||||
|
<script>hljs.highlightAll();</script>
|
||||||
|
"""
|
||||||
|
writeFile(output, html)
|
||||||
|
|
||||||
|
|
||||||
|
task markdown_to_html, "Build the tutorials HTML":
|
||||||
|
exec "nimble install -y markdown"
|
||||||
|
tutorialToHtml("examples/tutorial_1_connect.md", "tuto1.html")
|
||||||
|
tutorialToHtml("examples/tutorial_2_customproto.md", "tuto2.html")
|
||||||
|
|
||||||
# pin system
|
# pin system
|
||||||
# while nimble lockfile
|
# while nimble lockfile
|
||||||
# isn't available
|
# isn't available
|
||||||
|
|
|
@ -1,11 +1,20 @@
|
||||||
## Nim-Libp2p
|
# Nim-Libp2p
|
||||||
## Copyright (c) 2020 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
|
## This module contains a Switch Building helper.
|
||||||
|
runnableExamples:
|
||||||
|
let switch =
|
||||||
|
SwitchBuilder.new()
|
||||||
|
.withRng(rng)
|
||||||
|
.withAddresses(multiaddress)
|
||||||
|
# etc
|
||||||
|
.build()
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
@ -17,13 +26,13 @@ import
|
||||||
protocols/[identify, secure/secure, secure/noise, relay],
|
protocols/[identify, secure/secure, secure/noise, relay],
|
||||||
connmanager, upgrademngrs/muxedupgrade,
|
connmanager, upgrademngrs/muxedupgrade,
|
||||||
nameresolving/nameresolver,
|
nameresolving/nameresolver,
|
||||||
errors
|
errors, utility
|
||||||
|
|
||||||
export
|
export
|
||||||
switch, peerid, peerinfo, connection, multiaddress, crypto, errors
|
switch, peerid, peerinfo, connection, multiaddress, crypto, errors
|
||||||
|
|
||||||
type
|
type
|
||||||
TransportProvider* = proc(upgr: Upgrade): Transport {.gcsafe, raises: [Defect].}
|
TransportProvider* {.public.} = proc(upgr: Upgrade): Transport {.gcsafe, raises: [Defect].}
|
||||||
|
|
||||||
SecureProtocol* {.pure.} = enum
|
SecureProtocol* {.pure.} = enum
|
||||||
Noise,
|
Noise,
|
||||||
|
@ -52,7 +61,8 @@ type
|
||||||
isCircuitRelay: bool
|
isCircuitRelay: bool
|
||||||
circuitRelayCanHop: bool
|
circuitRelayCanHop: bool
|
||||||
|
|
||||||
proc new*(T: type[SwitchBuilder]): T =
|
proc new*(T: type[SwitchBuilder]): T {.public.} =
|
||||||
|
## Creates a SwitchBuilder
|
||||||
|
|
||||||
let address = MultiAddress
|
let address = MultiAddress
|
||||||
.init("/ip4/127.0.0.1/tcp/0")
|
.init("/ip4/127.0.0.1/tcp/0")
|
||||||
|
@ -70,19 +80,28 @@ proc new*(T: type[SwitchBuilder]): T =
|
||||||
agentVersion: AgentVersion,
|
agentVersion: AgentVersion,
|
||||||
isCircuitRelay: false)
|
isCircuitRelay: false)
|
||||||
|
|
||||||
proc withPrivateKey*(b: SwitchBuilder, privateKey: PrivateKey): SwitchBuilder =
|
proc withPrivateKey*(b: SwitchBuilder, privateKey: PrivateKey): SwitchBuilder {.public.} =
|
||||||
|
## Set the private key of the switch. Will be used to
|
||||||
|
## generate a PeerId
|
||||||
|
|
||||||
b.privKey = some(privateKey)
|
b.privKey = some(privateKey)
|
||||||
b
|
b
|
||||||
|
|
||||||
proc withAddress*(b: SwitchBuilder, address: MultiAddress): SwitchBuilder =
|
proc withAddress*(b: SwitchBuilder, address: MultiAddress): SwitchBuilder {.public.} =
|
||||||
|
## | Set the listening address of the switch
|
||||||
|
## | Calling it multiple time will override the value
|
||||||
|
|
||||||
b.addresses = @[address]
|
b.addresses = @[address]
|
||||||
b
|
b
|
||||||
|
|
||||||
proc withAddresses*(b: SwitchBuilder, addresses: seq[MultiAddress]): SwitchBuilder =
|
proc withAddresses*(b: SwitchBuilder, addresses: seq[MultiAddress]): SwitchBuilder {.public.} =
|
||||||
|
## | Set the listening addresses of the switch
|
||||||
|
## | Calling it multiple time will override the value
|
||||||
|
|
||||||
b.addresses = addresses
|
b.addresses = addresses
|
||||||
b
|
b
|
||||||
|
|
||||||
proc withSignedPeerRecord*(b: SwitchBuilder, sendIt = true): SwitchBuilder =
|
proc withSignedPeerRecord*(b: SwitchBuilder, sendIt = true): SwitchBuilder {.public.} =
|
||||||
b.sendSignedPeerRecord = sendIt
|
b.sendSignedPeerRecord = sendIt
|
||||||
b
|
b
|
||||||
|
|
||||||
|
@ -90,7 +109,9 @@ proc withMplex*(
|
||||||
b: SwitchBuilder,
|
b: SwitchBuilder,
|
||||||
inTimeout = 5.minutes,
|
inTimeout = 5.minutes,
|
||||||
outTimeout = 5.minutes,
|
outTimeout = 5.minutes,
|
||||||
maxChannCount = 200): SwitchBuilder =
|
maxChannCount = 200): SwitchBuilder {.public.} =
|
||||||
|
## | Uses `Mplex <https://docs.libp2p.io/concepts/stream-multiplexing/#mplex>`_ as a multiplexer
|
||||||
|
## | `Timeout` is the duration after which a inactive connection will be closed
|
||||||
proc newMuxer(conn: Connection): Muxer =
|
proc newMuxer(conn: Connection): Muxer =
|
||||||
Mplex.new(
|
Mplex.new(
|
||||||
conn,
|
conn,
|
||||||
|
@ -105,50 +126,60 @@ proc withMplex*(
|
||||||
|
|
||||||
b
|
b
|
||||||
|
|
||||||
proc withNoise*(b: SwitchBuilder): SwitchBuilder =
|
proc withNoise*(b: SwitchBuilder): SwitchBuilder {.public.} =
|
||||||
b.secureManagers.add(SecureProtocol.Noise)
|
b.secureManagers.add(SecureProtocol.Noise)
|
||||||
b
|
b
|
||||||
|
|
||||||
proc withTransport*(b: SwitchBuilder, prov: TransportProvider): SwitchBuilder =
|
proc withTransport*(b: SwitchBuilder, prov: TransportProvider): SwitchBuilder {.public.} =
|
||||||
|
## Use a custom transport
|
||||||
|
runnableExamples:
|
||||||
|
let switch =
|
||||||
|
SwitchBuilder.new()
|
||||||
|
.withTransport(proc(upgr: Upgrade): Transport = TcpTransport.new(flags, upgr))
|
||||||
|
.build()
|
||||||
b.transports.add(prov)
|
b.transports.add(prov)
|
||||||
b
|
b
|
||||||
|
|
||||||
proc withTcpTransport*(b: SwitchBuilder, flags: set[ServerFlags] = {}): SwitchBuilder =
|
proc withTcpTransport*(b: SwitchBuilder, flags: set[ServerFlags] = {}): SwitchBuilder {.public.} =
|
||||||
b.withTransport(proc(upgr: Upgrade): Transport = TcpTransport.new(flags, upgr))
|
b.withTransport(proc(upgr: Upgrade): Transport = TcpTransport.new(flags, upgr))
|
||||||
|
|
||||||
proc withRng*(b: SwitchBuilder, rng: ref HmacDrbgContext): SwitchBuilder =
|
proc withRng*(b: SwitchBuilder, rng: ref HmacDrbgContext): SwitchBuilder {.public.} =
|
||||||
b.rng = rng
|
b.rng = rng
|
||||||
b
|
b
|
||||||
|
|
||||||
proc withMaxConnections*(b: SwitchBuilder, maxConnections: int): SwitchBuilder =
|
proc withMaxConnections*(b: SwitchBuilder, maxConnections: int): SwitchBuilder {.public.} =
|
||||||
|
## Maximum concurrent connections of the switch. You should either use this, or
|
||||||
|
## `withMaxIn <#withMaxIn,SwitchBuilder,int>`_ & `withMaxOut<#withMaxOut,SwitchBuilder,int>`_
|
||||||
b.maxConnections = maxConnections
|
b.maxConnections = maxConnections
|
||||||
b
|
b
|
||||||
|
|
||||||
proc withMaxIn*(b: SwitchBuilder, maxIn: int): SwitchBuilder =
|
proc withMaxIn*(b: SwitchBuilder, maxIn: int): SwitchBuilder {.public.} =
|
||||||
|
## Maximum concurrent incoming connections. Should be used with `withMaxOut<#withMaxOut,SwitchBuilder,int>`_
|
||||||
b.maxIn = maxIn
|
b.maxIn = maxIn
|
||||||
b
|
b
|
||||||
|
|
||||||
proc withMaxOut*(b: SwitchBuilder, maxOut: int): SwitchBuilder =
|
proc withMaxOut*(b: SwitchBuilder, maxOut: int): SwitchBuilder {.public.} =
|
||||||
|
## Maximum concurrent outgoing connections. Should be used with `withMaxIn<#withMaxIn,SwitchBuilder,int>`_
|
||||||
b.maxOut = maxOut
|
b.maxOut = maxOut
|
||||||
b
|
b
|
||||||
|
|
||||||
proc withMaxConnsPerPeer*(b: SwitchBuilder, maxConnsPerPeer: int): SwitchBuilder =
|
proc withMaxConnsPerPeer*(b: SwitchBuilder, maxConnsPerPeer: int): SwitchBuilder {.public.} =
|
||||||
b.maxConnsPerPeer = maxConnsPerPeer
|
b.maxConnsPerPeer = maxConnsPerPeer
|
||||||
b
|
b
|
||||||
|
|
||||||
proc withPeerStore*(b: SwitchBuilder, capacity: int): SwitchBuilder =
|
proc withPeerStore*(b: SwitchBuilder, capacity: int): SwitchBuilder {.public.} =
|
||||||
b.peerStoreCapacity = some(capacity)
|
b.peerStoreCapacity = some(capacity)
|
||||||
b
|
b
|
||||||
|
|
||||||
proc withProtoVersion*(b: SwitchBuilder, protoVersion: string): SwitchBuilder =
|
proc withProtoVersion*(b: SwitchBuilder, protoVersion: string): SwitchBuilder {.public.} =
|
||||||
b.protoVersion = protoVersion
|
b.protoVersion = protoVersion
|
||||||
b
|
b
|
||||||
|
|
||||||
proc withAgentVersion*(b: SwitchBuilder, agentVersion: string): SwitchBuilder =
|
proc withAgentVersion*(b: SwitchBuilder, agentVersion: string): SwitchBuilder {.public.} =
|
||||||
b.agentVersion = agentVersion
|
b.agentVersion = agentVersion
|
||||||
b
|
b
|
||||||
|
|
||||||
proc withNameResolver*(b: SwitchBuilder, nameResolver: NameResolver): SwitchBuilder =
|
proc withNameResolver*(b: SwitchBuilder, nameResolver: NameResolver): SwitchBuilder {.public.} =
|
||||||
b.nameResolver = nameResolver
|
b.nameResolver = nameResolver
|
||||||
b
|
b
|
||||||
|
|
||||||
|
@ -158,7 +189,7 @@ proc withRelayTransport*(b: SwitchBuilder, canHop: bool): SwitchBuilder =
|
||||||
b
|
b
|
||||||
|
|
||||||
proc build*(b: SwitchBuilder): Switch
|
proc build*(b: SwitchBuilder): Switch
|
||||||
{.raises: [Defect, LPError].} =
|
{.raises: [Defect, LPError], public.} =
|
||||||
|
|
||||||
if b.rng == nil: # newRng could fail
|
if b.rng == nil: # newRng could fail
|
||||||
raise newException(Defect, "Cannot initialize RNG")
|
raise newException(Defect, "Cannot initialize RNG")
|
||||||
|
@ -246,7 +277,9 @@ proc newStandardSwitch*(
|
||||||
nameResolver: NameResolver = nil,
|
nameResolver: NameResolver = nil,
|
||||||
sendSignedPeerRecord = false,
|
sendSignedPeerRecord = false,
|
||||||
peerStoreCapacity = 1000): Switch
|
peerStoreCapacity = 1000): Switch
|
||||||
{.raises: [Defect, LPError].} =
|
{.raises: [Defect, LPError], public.} =
|
||||||
|
## Helper for common switch configurations.
|
||||||
|
|
||||||
if SecureProtocol.Secio in secureManagers:
|
if SecureProtocol.Secio in secureManagers:
|
||||||
quit("Secio is deprecated!") # use of secio is unsafe
|
quit("Secio is deprecated!") # use of secio is unsafe
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2018 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
## This module implementes CID (Content IDentifier).
|
## This module implementes CID (Content IDentifier).
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2020 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-Libp2p
|
# Nim-Libp2p
|
||||||
## Copyright (c) 2020-2022 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
## This module integrates BearSSL ChaCha20+Poly1305
|
## This module integrates BearSSL ChaCha20+Poly1305
|
||||||
##
|
##
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-Libp2p
|
# Nim-Libp2p
|
||||||
## Copyright (c) 2018 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
## This module implements Public Key and Private Key interface for libp2p.
|
## This module implements Public Key and Private Key interface for libp2p.
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
@ -76,7 +76,7 @@ import nimcrypto/[rijndael, twofish, sha2, hash, hmac]
|
||||||
import nimcrypto/utils as ncrutils
|
import nimcrypto/utils as ncrutils
|
||||||
import ../utility
|
import ../utility
|
||||||
import stew/results
|
import stew/results
|
||||||
export results
|
export results, utility
|
||||||
|
|
||||||
# This is workaround for Nim's `import` bug
|
# This is workaround for Nim's `import` bug
|
||||||
export rijndael, twofish, sha2, hash, hmac, ncrutils, rand
|
export rijndael, twofish, sha2, hash, hmac, ncrutils, rand
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-Libp2p
|
# Nim-Libp2p
|
||||||
## Copyright (c) 2020-2022 Status Research & Development GmbH
|
# Copyright (c) 2022-2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
## This module integrates BearSSL Cyrve25519 mul and mulgen
|
## This module integrates BearSSL Cyrve25519 mul and mulgen
|
||||||
##
|
##
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-Libp2p
|
# Nim-Libp2p
|
||||||
## Copyright (c) 2018 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
## This module implements constant-time ECDSA and ECDHE for NIST elliptic
|
## This module implements constant-time ECDSA and ECDHE for NIST elliptic
|
||||||
## curves secp256r1, secp384r1 and secp521r1.
|
## curves secp256r1, secp384r1 and secp521r1.
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-Libp2p
|
# Nim-Libp2p
|
||||||
## Copyright (c) 2018 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
## This module implements ED25519.
|
## This module implements ED25519.
|
||||||
## This is pure nim implementation of ED25519 ref10.
|
## This is pure nim implementation of ED25519 ref10.
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-Libp2p
|
# Nim-Libp2p
|
||||||
## Copyright (c) 2018 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
## This module implements ED25519.
|
## This module implements ED25519.
|
||||||
## This code is a port of the public domain, "ref10" implementation of ed25519
|
## This code is a port of the public domain, "ref10" implementation of ed25519
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2020 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
# https://tools.ietf.org/html/rfc5869
|
# https://tools.ietf.org/html/rfc5869
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-Libp2p
|
# Nim-Libp2p
|
||||||
## Copyright (c) 2018 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
## This module implements minimal ASN.1 encoding/decoding primitives.
|
## This module implements minimal ASN.1 encoding/decoding primitives.
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-Libp2p
|
# Nim-Libp2p
|
||||||
## Copyright (c) 2018 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
## This module implements constant-time RSA PKCS#1.5 DSA.
|
## This module implements constant-time RSA PKCS#1.5 DSA.
|
||||||
##
|
##
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-Libp2p
|
# Nim-Libp2p
|
||||||
## Copyright (c) 2018 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2018 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-Libp2p
|
# Nim-Libp2p
|
||||||
## Copyright (c) 2018 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2018 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
## To enable dump of all incoming and outgoing unencrypted messages you need
|
## To enable dump of all incoming and outgoing unencrypted messages you need
|
||||||
## to compile project with ``-d:libp2p_dump`` compile-time option. When this
|
## to compile project with ``-d:libp2p_dump`` compile-time option. When this
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2021 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2021 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
import std/[sugar, tables]
|
import std/[sugar, tables]
|
||||||
|
|
||||||
|
|
|
@ -1,23 +1,24 @@
|
||||||
## Nim-Libp2p
|
# Nim-Libp2p
|
||||||
## Copyright (c) 2018 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
## This module implements MultiAddress.
|
## This module implements MultiAddress.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
{.push public.}
|
||||||
|
|
||||||
import pkg/chronos
|
import pkg/chronos
|
||||||
import std/[nativesockets, hashes]
|
import std/[nativesockets, hashes]
|
||||||
import tables, strutils, sets, stew/shims/net
|
import tables, strutils, sets, stew/shims/net
|
||||||
import multicodec, multihash, multibase, transcoder, vbuffer, peerid,
|
import multicodec, multihash, multibase, transcoder, vbuffer, peerid,
|
||||||
protobuf/minprotobuf, errors
|
protobuf/minprotobuf, errors, utility
|
||||||
import stew/[base58, base32, endians2, results]
|
import stew/[base58, base32, endians2, results]
|
||||||
export results, minprotobuf, vbuffer
|
export results, minprotobuf, vbuffer, utility
|
||||||
|
|
||||||
type
|
type
|
||||||
MAKind* = enum
|
MAKind* = enum
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-Libp2p
|
# Nim-Libp2p
|
||||||
## Copyright (c) 2018 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
## This module implements MultiBase.
|
## This module implements MultiBase.
|
||||||
##
|
##
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-Libp2p
|
# Nim-Libp2p
|
||||||
## Copyright (c) 2018 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not BE copied, modified, or distributed except according to
|
# This file may not BE copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
## This module implements MultiCodec.
|
## This module implements MultiCodec.
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-Libp2p
|
# Nim-Libp2p
|
||||||
## Copyright (c) 2018 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
## This module implements MultiHash.
|
## This module implements MultiHash.
|
||||||
## Supported hashes are:
|
## Supported hashes are:
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2019 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2019 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2019 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2019 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2019 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2021 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2021 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2021 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
|
|
@ -1,25 +1,27 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2018 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
## This module implementes API for libp2p peer.
|
## This module implementes API for libp2p peer.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
{.push public.}
|
||||||
|
|
||||||
import
|
import
|
||||||
std/[hashes, strutils],
|
std/[hashes, strutils],
|
||||||
stew/[base58, results],
|
stew/[base58, results],
|
||||||
chronicles,
|
chronicles,
|
||||||
nimcrypto/utils,
|
nimcrypto/utils,
|
||||||
|
utility,
|
||||||
./crypto/crypto, ./multicodec, ./multihash, ./vbuffer,
|
./crypto/crypto, ./multicodec, ./multihash, ./vbuffer,
|
||||||
./protobuf/minprotobuf
|
./protobuf/minprotobuf
|
||||||
|
|
||||||
export results
|
export results, utility
|
||||||
|
|
||||||
const
|
const
|
||||||
maxInlineKeyLength* = 42
|
maxInlineKeyLength* = 42
|
||||||
|
|
|
@ -1,17 +1,18 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2019 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
{.push public.}
|
||||||
|
|
||||||
import std/[options, sequtils]
|
import std/[options, sequtils]
|
||||||
import pkg/[chronos, chronicles, stew/results]
|
import pkg/[chronos, chronicles, stew/results]
|
||||||
import peerid, multiaddress, crypto/crypto, routing_record, errors
|
import peerid, multiaddress, crypto/crypto, routing_record, errors, utility
|
||||||
|
|
||||||
export peerid, multiaddress, crypto, routing_record, errors, results
|
export peerid, multiaddress, crypto, routing_record, errors, results
|
||||||
|
|
||||||
|
@ -20,7 +21,7 @@ export peerid, multiaddress, crypto, routing_record, errors, results
|
||||||
type
|
type
|
||||||
PeerInfoError* = LPError
|
PeerInfoError* = LPError
|
||||||
|
|
||||||
PeerInfo* = ref object
|
PeerInfo* {.public.} = ref object
|
||||||
peerId*: PeerId
|
peerId*: PeerId
|
||||||
addrs*: seq[MultiAddress]
|
addrs*: seq[MultiAddress]
|
||||||
protocols*: seq[string]
|
protocols*: seq[string]
|
||||||
|
|
|
@ -1,11 +1,26 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2021 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
|
## Stores generic informations about peers.
|
||||||
|
runnableExamples:
|
||||||
|
# Will keep info of all connected peers +
|
||||||
|
# last 50 disconnected peers
|
||||||
|
let peerStore = PeerStore.new(capacity = 50)
|
||||||
|
|
||||||
|
# Create a custom book type
|
||||||
|
type MoodBook = ref object of PeerBook[string]
|
||||||
|
|
||||||
|
var somePeerId: PeerId
|
||||||
|
discard somePeerId.init("")
|
||||||
|
|
||||||
|
peerStore[MoodBook][somePeerId] = "Happy"
|
||||||
|
doAssert peerStore[MoodBook][somePeerId] == "Happy"
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
@ -15,7 +30,8 @@ import
|
||||||
./protocols/identify,
|
./protocols/identify,
|
||||||
./peerid, ./peerinfo,
|
./peerid, ./peerinfo,
|
||||||
./routing_record,
|
./routing_record,
|
||||||
./multiaddress
|
./multiaddress,
|
||||||
|
utility
|
||||||
|
|
||||||
type
|
type
|
||||||
#################
|
#################
|
||||||
|
@ -23,7 +39,7 @@ type
|
||||||
#################
|
#################
|
||||||
|
|
||||||
PeerBookChangeHandler* = proc(peerId: PeerId) {.gcsafe, raises: [Defect].}
|
PeerBookChangeHandler* = proc(peerId: PeerId) {.gcsafe, raises: [Defect].}
|
||||||
|
|
||||||
#########
|
#########
|
||||||
# Books #
|
# Books #
|
||||||
#########
|
#########
|
||||||
|
@ -33,29 +49,29 @@ type
|
||||||
changeHandlers: seq[PeerBookChangeHandler]
|
changeHandlers: seq[PeerBookChangeHandler]
|
||||||
deletor: PeerBookChangeHandler
|
deletor: PeerBookChangeHandler
|
||||||
|
|
||||||
PeerBook*[T] = ref object of BasePeerBook
|
PeerBook*[T] {.public.} = ref object of BasePeerBook
|
||||||
book*: Table[PeerId, T]
|
book*: Table[PeerId, T]
|
||||||
|
|
||||||
SeqPeerBook*[T] = ref object of PeerBook[seq[T]]
|
SeqPeerBook*[T] = ref object of PeerBook[seq[T]]
|
||||||
|
|
||||||
AddressBook* = ref object of SeqPeerBook[MultiAddress]
|
|
||||||
ProtoBook* = ref object of SeqPeerBook[string]
|
|
||||||
KeyBook* = ref object of PeerBook[PublicKey]
|
|
||||||
|
|
||||||
AgentBook* = ref object of PeerBook[string]
|
AddressBook* {.public.} = ref object of SeqPeerBook[MultiAddress]
|
||||||
ProtoVersionBook* = ref object of PeerBook[string]
|
ProtoBook* {.public.} = ref object of SeqPeerBook[string]
|
||||||
SPRBook* = ref object of PeerBook[Envelope]
|
KeyBook* {.public.} = ref object of PeerBook[PublicKey]
|
||||||
|
|
||||||
|
AgentBook* {.public.} = ref object of PeerBook[string]
|
||||||
|
ProtoVersionBook* {.public.} = ref object of PeerBook[string]
|
||||||
|
SPRBook* {.public.} = ref object of PeerBook[Envelope]
|
||||||
|
|
||||||
####################
|
####################
|
||||||
# Peer store types #
|
# Peer store types #
|
||||||
####################
|
####################
|
||||||
|
|
||||||
PeerStore* = ref object
|
PeerStore* {.public.} = ref object
|
||||||
books: Table[string, BasePeerBook]
|
books: Table[string, BasePeerBook]
|
||||||
capacity*: int
|
capacity*: int
|
||||||
toClean*: seq[PeerId]
|
toClean*: seq[PeerId]
|
||||||
|
|
||||||
proc new*(T: type PeerStore, capacity = 1000): PeerStore =
|
proc new*(T: type PeerStore, capacity = 1000): PeerStore {.public.} =
|
||||||
T(capacity: capacity)
|
T(capacity: capacity)
|
||||||
|
|
||||||
#########################
|
#########################
|
||||||
|
@ -63,16 +79,15 @@ proc new*(T: type PeerStore, capacity = 1000): PeerStore =
|
||||||
#########################
|
#########################
|
||||||
|
|
||||||
proc `[]`*[T](peerBook: PeerBook[T],
|
proc `[]`*[T](peerBook: PeerBook[T],
|
||||||
peerId: PeerId): T =
|
peerId: PeerId): T {.public.} =
|
||||||
## Get all the known metadata of a provided peer.
|
## Get all known metadata of a provided peer, or default(T) if missing
|
||||||
peerBook.book.getOrDefault(peerId)
|
peerBook.book.getOrDefault(peerId)
|
||||||
|
|
||||||
proc `[]=`*[T](peerBook: PeerBook[T],
|
proc `[]=`*[T](peerBook: PeerBook[T],
|
||||||
peerId: PeerId,
|
peerId: PeerId,
|
||||||
entry: T) =
|
entry: T) {.public.} =
|
||||||
## Set metadata for a given peerId. This will replace any
|
## Set metadata for a given peerId.
|
||||||
## previously stored metadata.
|
|
||||||
|
|
||||||
peerBook.book[peerId] = entry
|
peerBook.book[peerId] = entry
|
||||||
|
|
||||||
# Notify clients
|
# Notify clients
|
||||||
|
@ -80,9 +95,9 @@ proc `[]=`*[T](peerBook: PeerBook[T],
|
||||||
handler(peerId)
|
handler(peerId)
|
||||||
|
|
||||||
proc del*[T](peerBook: PeerBook[T],
|
proc del*[T](peerBook: PeerBook[T],
|
||||||
peerId: PeerId): bool =
|
peerId: PeerId): bool {.public.} =
|
||||||
## Delete the provided peer from the book.
|
## Delete the provided peer from the book. Returns whether the peer was in the book
|
||||||
|
|
||||||
if peerId notin peerBook.book:
|
if peerId notin peerBook.book:
|
||||||
return false
|
return false
|
||||||
else:
|
else:
|
||||||
|
@ -92,15 +107,16 @@ proc del*[T](peerBook: PeerBook[T],
|
||||||
handler(peerId)
|
handler(peerId)
|
||||||
return true
|
return true
|
||||||
|
|
||||||
proc contains*[T](peerBook: PeerBook[T], peerId: PeerId): bool =
|
proc contains*[T](peerBook: PeerBook[T], peerId: PeerId): bool {.public.} =
|
||||||
peerId in peerBook.book
|
peerId in peerBook.book
|
||||||
|
|
||||||
proc addHandler*[T](peerBook: PeerBook[T], handler: PeerBookChangeHandler) =
|
proc addHandler*[T](peerBook: PeerBook[T], handler: PeerBookChangeHandler) {.public.} =
|
||||||
|
## Adds a callback that will be called everytime the book changes
|
||||||
peerBook.changeHandlers.add(handler)
|
peerBook.changeHandlers.add(handler)
|
||||||
|
|
||||||
proc len*[T](peerBook: PeerBook[T]): int = peerBook.book.len
|
proc len*[T](peerBook: PeerBook[T]): int {.public.} = peerBook.book.len
|
||||||
|
|
||||||
##################
|
##################
|
||||||
# Peer Store API #
|
# Peer Store API #
|
||||||
##################
|
##################
|
||||||
macro getTypeName(t: type): untyped =
|
macro getTypeName(t: type): untyped =
|
||||||
|
@ -108,7 +124,8 @@ macro getTypeName(t: type): untyped =
|
||||||
let typ = getTypeImpl(t)[1]
|
let typ = getTypeImpl(t)[1]
|
||||||
newLit(repr(typ.owner()) & "." & repr(typ))
|
newLit(repr(typ.owner()) & "." & repr(typ))
|
||||||
|
|
||||||
proc `[]`*[T](p: PeerStore, typ: type[T]): T =
|
proc `[]`*[T](p: PeerStore, typ: type[T]): T {.public.} =
|
||||||
|
## Get a book from the PeerStore (ex: peerStore[AddressBook])
|
||||||
let name = getTypeName(T)
|
let name = getTypeName(T)
|
||||||
result = T(p.books.getOrDefault(name))
|
result = T(p.books.getOrDefault(name))
|
||||||
if result.isNil:
|
if result.isNil:
|
||||||
|
@ -121,7 +138,7 @@ proc `[]`*[T](p: PeerStore, typ: type[T]): T =
|
||||||
return result
|
return result
|
||||||
|
|
||||||
proc del*(peerStore: PeerStore,
|
proc del*(peerStore: PeerStore,
|
||||||
peerId: PeerId) =
|
peerId: PeerId) {.public.} =
|
||||||
## Delete the provided peer from every book.
|
## Delete the provided peer from every book.
|
||||||
for _, book in peerStore.books:
|
for _, book in peerStore.books:
|
||||||
book.deletor(peerId)
|
book.deletor(peerId)
|
||||||
|
|
|
@ -1,18 +1,20 @@
|
||||||
## Nim-Libp2p
|
# Nim-Libp2p
|
||||||
## Copyright (c) 2018 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
## This module implements minimal Google's ProtoBuf primitives.
|
## This module implements minimal Google's ProtoBuf primitives.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
import ../varint, stew/[endians2, results]
|
import ../varint, ../utility, stew/[endians2, results]
|
||||||
export results
|
export results, utility
|
||||||
|
|
||||||
|
{.push public.}
|
||||||
|
|
||||||
const
|
const
|
||||||
MaxMessageSize* = 1'u shl 22
|
MaxMessageSize* = 1'u shl 22
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2019 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
|
## `Identify <https://docs.libp2p.io/concepts/protocols/#identify>`_ and
|
||||||
|
## `Push Identify <https://docs.libp2p.io/concepts/protocols/#identify-push>`_ implementation
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
@ -36,7 +39,7 @@ type
|
||||||
IdentityInvalidMsgError* = object of IdentifyError
|
IdentityInvalidMsgError* = object of IdentifyError
|
||||||
IdentifyNoPubKeyError* = object of IdentifyError
|
IdentifyNoPubKeyError* = object of IdentifyError
|
||||||
|
|
||||||
IdentifyInfo* = object
|
IdentifyInfo* {.public.} = object
|
||||||
pubkey*: Option[PublicKey]
|
pubkey*: Option[PublicKey]
|
||||||
peerId*: PeerId
|
peerId*: PeerId
|
||||||
addrs*: seq[MultiAddress]
|
addrs*: seq[MultiAddress]
|
||||||
|
@ -54,7 +57,7 @@ type
|
||||||
peer: PeerId,
|
peer: PeerId,
|
||||||
newInfo: IdentifyInfo):
|
newInfo: IdentifyInfo):
|
||||||
Future[void]
|
Future[void]
|
||||||
{.gcsafe, raises: [Defect].}
|
{.gcsafe, raises: [Defect], public.}
|
||||||
|
|
||||||
IdentifyPush* = ref object of LPProtocol
|
IdentifyPush* = ref object of LPProtocol
|
||||||
identifyHandler: IdentifyPushHandler
|
identifyHandler: IdentifyPushHandler
|
||||||
|
@ -203,7 +206,9 @@ proc identify*(p: Identify,
|
||||||
else:
|
else:
|
||||||
raise newException(IdentityInvalidMsgError, "No pubkey in identify")
|
raise newException(IdentityInvalidMsgError, "No pubkey in identify")
|
||||||
|
|
||||||
proc new*(T: typedesc[IdentifyPush], handler: IdentifyPushHandler = nil): T =
|
proc new*(T: typedesc[IdentifyPush], handler: IdentifyPushHandler = nil): T {.public.} =
|
||||||
|
## Create a IdentifyPush protocol. `handler` will be called every time
|
||||||
|
## a peer sends us new `PeerInfo`
|
||||||
let identifypush = T(identifyHandler: handler)
|
let identifypush = T(identifyHandler: handler)
|
||||||
identifypush.init()
|
identifypush.init()
|
||||||
identifypush
|
identifypush
|
||||||
|
@ -240,6 +245,7 @@ proc init*(p: IdentifyPush) =
|
||||||
p.handler = handle
|
p.handler = handle
|
||||||
p.codec = IdentifyPushCodec
|
p.codec = IdentifyPushCodec
|
||||||
|
|
||||||
proc push*(p: IdentifyPush, peerInfo: PeerInfo, conn: Connection) {.async.} =
|
proc push*(p: IdentifyPush, peerInfo: PeerInfo, conn: Connection) {.async, public.} =
|
||||||
|
## Send new `peerInfo`s to a connection
|
||||||
var pb = encodeMsg(peerInfo, conn.observedAddr, true)
|
var pb = encodeMsg(peerInfo, conn.observedAddr, true)
|
||||||
await conn.writeLp(pb.buffer)
|
await conn.writeLp(pb.buffer)
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2021 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
|
## `Ping <https://docs.libp2p.io/concepts/protocols/#ping>`_ protocol implementation
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
@ -18,6 +20,7 @@ import ../protobuf/minprotobuf,
|
||||||
../crypto/crypto,
|
../crypto/crypto,
|
||||||
../multiaddress,
|
../multiaddress,
|
||||||
../protocols/protocol,
|
../protocols/protocol,
|
||||||
|
../utility,
|
||||||
../errors
|
../errors
|
||||||
|
|
||||||
export chronicles, rand, connection
|
export chronicles, rand, connection
|
||||||
|
@ -31,9 +34,9 @@ const
|
||||||
|
|
||||||
type
|
type
|
||||||
PingError* = object of LPError
|
PingError* = object of LPError
|
||||||
WrongPingAckError* = object of LPError
|
WrongPingAckError* = object of PingError
|
||||||
|
|
||||||
PingHandler* = proc (
|
PingHandler* {.public.} = proc (
|
||||||
peer: PeerId):
|
peer: PeerId):
|
||||||
Future[void]
|
Future[void]
|
||||||
{.gcsafe, raises: [Defect].}
|
{.gcsafe, raises: [Defect].}
|
||||||
|
@ -42,7 +45,7 @@ type
|
||||||
pingHandler*: PingHandler
|
pingHandler*: PingHandler
|
||||||
rng: ref HmacDrbgContext
|
rng: ref HmacDrbgContext
|
||||||
|
|
||||||
proc new*(T: typedesc[Ping], handler: PingHandler = nil, rng: ref HmacDrbgContext = newRng()): T =
|
proc new*(T: typedesc[Ping], handler: PingHandler = nil, rng: ref HmacDrbgContext = newRng()): T {.public.} =
|
||||||
let ping = Ping(pinghandler: handler, rng: rng)
|
let ping = Ping(pinghandler: handler, rng: rng)
|
||||||
ping.init()
|
ping.init()
|
||||||
ping
|
ping
|
||||||
|
@ -68,10 +71,8 @@ method init*(p: Ping) =
|
||||||
proc ping*(
|
proc ping*(
|
||||||
p: Ping,
|
p: Ping,
|
||||||
conn: Connection,
|
conn: Connection,
|
||||||
): Future[Duration] {.async, gcsafe.} =
|
): Future[Duration] {.async, gcsafe, public.} =
|
||||||
## Sends ping to `conn`
|
## Sends ping to `conn`, returns the delay
|
||||||
## Returns the delay
|
|
||||||
##
|
|
||||||
|
|
||||||
trace "initiating ping", conn
|
trace "initiating ping", conn
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2019 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
import ./pubsub/[pubsub, floodsub, gossipsub]
|
import ./pubsub/[pubsub, floodsub, gossipsub]
|
||||||
|
|
||||||
|
## Home of PubSub & it's implementations:
|
||||||
|
## | **pubsub**: base interface for pubsub implementations
|
||||||
|
## | **floodsub**: simple flood-based publishing
|
||||||
|
## | **gossipsub**: more sophisticated gossip based publishing
|
||||||
|
|
||||||
export pubsub, floodsub, gossipsub
|
export pubsub, floodsub, gossipsub
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
# this module will be further extended in PR
|
# this module will be further extended in PR
|
||||||
# https://github.com/status-im/nim-libp2p/pull/107/
|
# https://github.com/status-im/nim-libp2p/pull/107/
|
||||||
|
|
||||||
|
import ../../utility
|
||||||
|
|
||||||
type
|
type
|
||||||
ValidationResult* {.pure.} = enum
|
ValidationResult* {.pure, public.} = enum
|
||||||
Accept, Reject, Ignore
|
Accept, Reject, Ignore
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2019 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
@ -22,13 +22,15 @@ import ./pubsub,
|
||||||
../../peerinfo,
|
../../peerinfo,
|
||||||
../../utility
|
../../utility
|
||||||
|
|
||||||
|
## Simple flood-based publishing.
|
||||||
|
|
||||||
logScope:
|
logScope:
|
||||||
topics = "libp2p floodsub"
|
topics = "libp2p floodsub"
|
||||||
|
|
||||||
const FloodSubCodec* = "/floodsub/1.0.0"
|
const FloodSubCodec* = "/floodsub/1.0.0"
|
||||||
|
|
||||||
type
|
type
|
||||||
FloodSub* = ref object of PubSub
|
FloodSub* {.public.} = ref object of PubSub
|
||||||
floodsub*: PeerTable # topic to remote peer map
|
floodsub*: PeerTable # topic to remote peer map
|
||||||
seen*: TimedCache[MessageID] # message id:s already seen on the network
|
seen*: TimedCache[MessageID] # message id:s already seen on the network
|
||||||
seenSalt*: seq[byte]
|
seenSalt*: seq[byte]
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2019 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
|
## Gossip based publishing
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2021 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2021 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2021 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2019 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2019 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,17 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2019 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
|
## Base interface for pubsub protocols
|
||||||
|
##
|
||||||
|
## You can `subscribe<#subscribe%2CPubSub%2Cstring%2CTopicHandler>`_ to a topic,
|
||||||
|
## `publish<#publish.e%2CPubSub%2Cstring%2Cseq%5Bbyte%5D>`_ something on it,
|
||||||
|
## and eventually `unsubscribe<#unsubscribe%2CPubSub%2Cstring%2CTopicHandler>`_ from it.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
@ -75,37 +81,40 @@ declarePublicCounter(libp2p_pubsub_received_prune, "pubsub broadcast prune", lab
|
||||||
type
|
type
|
||||||
InitializationError* = object of LPError
|
InitializationError* = object of LPError
|
||||||
|
|
||||||
TopicHandler* = proc(topic: string,
|
TopicHandler* {.public.} = proc(topic: string,
|
||||||
data: seq[byte]): Future[void] {.gcsafe, raises: [Defect].}
|
data: seq[byte]): Future[void] {.gcsafe, raises: [Defect].}
|
||||||
|
|
||||||
ValidatorHandler* = proc(topic: string,
|
ValidatorHandler* {.public.} = proc(topic: string,
|
||||||
message: Message): Future[ValidationResult] {.gcsafe, raises: [Defect].}
|
message: Message): Future[ValidationResult] {.gcsafe, raises: [Defect].}
|
||||||
|
|
||||||
TopicPair* = tuple[topic: string, handler: TopicHandler]
|
TopicPair* = tuple[topic: string, handler: TopicHandler]
|
||||||
|
|
||||||
MsgIdProvider* =
|
MsgIdProvider* {.public.} =
|
||||||
proc(m: Message): Result[MessageID, ValidationResult] {.noSideEffect, raises: [Defect], gcsafe.}
|
proc(m: Message): Result[MessageID, ValidationResult] {.noSideEffect, raises: [Defect], gcsafe.}
|
||||||
|
|
||||||
SubscriptionValidator* =
|
SubscriptionValidator* {.public.} =
|
||||||
proc(topic: string): bool {.raises: [Defect], gcsafe.}
|
proc(topic: string): bool {.raises: [Defect], gcsafe.}
|
||||||
|
## Every time a peer send us a subscription (even to an unknown topic),
|
||||||
|
## we have to store it, which may be an attack vector.
|
||||||
|
## This callback can be used to reject topic we're not interested in
|
||||||
|
|
||||||
PubSub* = ref object of LPProtocol
|
PubSub* {.public.} = ref object of LPProtocol
|
||||||
switch*: Switch # the switch used to dial/connect to peers
|
switch*: Switch # the switch used to dial/connect to peers
|
||||||
peerInfo*: PeerInfo # this peer's info
|
peerInfo*: PeerInfo # this peer's info
|
||||||
topics*: Table[string, seq[TopicHandler]] # the topics that _we_ are interested in
|
topics*: Table[string, seq[TopicHandler]] # the topics that _we_ are interested in
|
||||||
peers*: Table[PeerId, PubSubPeer] ##\
|
peers*: Table[PeerId, PubSubPeer] #\
|
||||||
## Peers that we are interested to gossip with (but not necessarily
|
# Peers that we are interested to gossip with (but not necessarily
|
||||||
## yet connected to)
|
# yet connected to)
|
||||||
triggerSelf*: bool # trigger own local handler on publish
|
triggerSelf*: bool ## trigger own local handler on publish
|
||||||
verifySignature*: bool # enable signature verification
|
verifySignature*: bool ## enable signature verification
|
||||||
sign*: bool # enable message signing
|
sign*: bool ## enable message signing
|
||||||
validators*: Table[string, HashSet[ValidatorHandler]]
|
validators*: Table[string, HashSet[ValidatorHandler]]
|
||||||
observers: ref seq[PubSubObserver] # ref as in smart_ptr
|
observers: ref seq[PubSubObserver] # ref as in smart_ptr
|
||||||
msgIdProvider*: MsgIdProvider # Turn message into message id (not nil)
|
msgIdProvider*: MsgIdProvider ## Turn message into message id (not nil)
|
||||||
msgSeqno*: uint64
|
msgSeqno*: uint64
|
||||||
anonymize*: bool # if we omit fromPeer and seqno from RPC messages we send
|
anonymize*: bool ## if we omit fromPeer and seqno from RPC messages we send
|
||||||
subscriptionValidator*: SubscriptionValidator # callback used to validate subscriptions
|
subscriptionValidator*: SubscriptionValidator # callback used to validate subscriptions
|
||||||
topicsHigh*: int # the maximum number of topics a peer is allowed to subscribe to
|
topicsHigh*: int ## the maximum number of topics a peer is allowed to subscribe to
|
||||||
maxMessageSize*: int ##\
|
maxMessageSize*: int ##\
|
||||||
## the maximum raw message size we'll globally allow
|
## the maximum raw message size we'll globally allow
|
||||||
## for finer tuning, check message size on topic validator
|
## for finer tuning, check message size on topic validator
|
||||||
|
@ -411,7 +420,7 @@ method onTopicSubscription*(p: PubSub, topic: string, subscribed: bool) {.base.}
|
||||||
|
|
||||||
proc unsubscribe*(p: PubSub,
|
proc unsubscribe*(p: PubSub,
|
||||||
topic: string,
|
topic: string,
|
||||||
handler: TopicHandler) =
|
handler: TopicHandler) {.public.} =
|
||||||
## unsubscribe from a ``topic`` string
|
## unsubscribe from a ``topic`` string
|
||||||
##
|
##
|
||||||
p.topics.withValue(topic, handlers):
|
p.topics.withValue(topic, handlers):
|
||||||
|
@ -424,12 +433,13 @@ proc unsubscribe*(p: PubSub,
|
||||||
|
|
||||||
p.updateTopicMetrics(topic)
|
p.updateTopicMetrics(topic)
|
||||||
|
|
||||||
proc unsubscribe*(p: PubSub, topics: openArray[TopicPair]) =
|
proc unsubscribe*(p: PubSub, topics: openArray[TopicPair]) {.public.} =
|
||||||
## unsubscribe from a list of ``topic`` handlers
|
## unsubscribe from a list of ``topic`` handlers
|
||||||
for t in topics:
|
for t in topics:
|
||||||
p.unsubscribe(t.topic, t.handler)
|
p.unsubscribe(t.topic, t.handler)
|
||||||
|
|
||||||
proc unsubscribeAll*(p: PubSub, topic: string) =
|
proc unsubscribeAll*(p: PubSub, topic: string) {.public.} =
|
||||||
|
## unsubscribe every `handler` from `topic`
|
||||||
if topic notin p.topics:
|
if topic notin p.topics:
|
||||||
debug "unsubscribeAll called for an unknown topic", topic
|
debug "unsubscribeAll called for an unknown topic", topic
|
||||||
else:
|
else:
|
||||||
|
@ -441,15 +451,14 @@ proc unsubscribeAll*(p: PubSub, topic: string) =
|
||||||
|
|
||||||
proc subscribe*(p: PubSub,
|
proc subscribe*(p: PubSub,
|
||||||
topic: string,
|
topic: string,
|
||||||
handler: TopicHandler) =
|
handler: TopicHandler) {.public.} =
|
||||||
## subscribe to a topic
|
## subscribe to a topic
|
||||||
##
|
##
|
||||||
## ``topic`` - a string topic to subscribe to
|
## ``topic`` - a string topic to subscribe to
|
||||||
##
|
##
|
||||||
## ``handler`` - is a user provided proc
|
## ``handler`` - user provided proc that
|
||||||
## that will be triggered
|
## will be triggered on every
|
||||||
## on every received message
|
## received message
|
||||||
##
|
|
||||||
|
|
||||||
# Check that this is an allowed topic
|
# Check that this is an allowed topic
|
||||||
if p.subscriptionValidator != nil and p.subscriptionValidator(topic) == false:
|
if p.subscriptionValidator != nil and p.subscriptionValidator(topic) == false:
|
||||||
|
@ -470,8 +479,9 @@ proc subscribe*(p: PubSub,
|
||||||
|
|
||||||
method publish*(p: PubSub,
|
method publish*(p: PubSub,
|
||||||
topic: string,
|
topic: string,
|
||||||
data: seq[byte]): Future[int] {.base, async.} =
|
data: seq[byte]): Future[int] {.base, async, public.} =
|
||||||
## publish to a ``topic``
|
## publish to a ``topic``
|
||||||
|
##
|
||||||
## The return value is the number of neighbours that we attempted to send the
|
## The return value is the number of neighbours that we attempted to send the
|
||||||
## message to, excluding self. Note that this is an optimistic number of
|
## message to, excluding self. Note that this is an optimistic number of
|
||||||
## attempts - the number of peers that actually receive the message might
|
## attempts - the number of peers that actually receive the message might
|
||||||
|
@ -490,14 +500,17 @@ method initPubSub*(p: PubSub)
|
||||||
|
|
||||||
method addValidator*(p: PubSub,
|
method addValidator*(p: PubSub,
|
||||||
topic: varargs[string],
|
topic: varargs[string],
|
||||||
hook: ValidatorHandler) {.base.} =
|
hook: ValidatorHandler) {.base, public.} =
|
||||||
|
## Add a validator to a `topic`. Each new message received in this
|
||||||
|
## will be sent to `hook`. `hook` can return either `Accept`,
|
||||||
|
## `Ignore` or `Reject` (which can descore the peer)
|
||||||
for t in topic:
|
for t in topic:
|
||||||
trace "adding validator for topic", topicId = t
|
trace "adding validator for topic", topicId = t
|
||||||
p.validators.mgetOrPut(t, HashSet[ValidatorHandler]()).incl(hook)
|
p.validators.mgetOrPut(t, HashSet[ValidatorHandler]()).incl(hook)
|
||||||
|
|
||||||
method removeValidator*(p: PubSub,
|
method removeValidator*(p: PubSub,
|
||||||
topic: varargs[string],
|
topic: varargs[string],
|
||||||
hook: ValidatorHandler) {.base.} =
|
hook: ValidatorHandler) {.base, public.} =
|
||||||
for t in topic:
|
for t in topic:
|
||||||
p.validators.withValue(t, validators):
|
p.validators.withValue(t, validators):
|
||||||
validators[].excl(hook)
|
validators[].excl(hook)
|
||||||
|
@ -547,7 +560,7 @@ proc init*[PubParams: object | bool](
|
||||||
maxMessageSize: int = 1024 * 1024,
|
maxMessageSize: int = 1024 * 1024,
|
||||||
rng: ref HmacDrbgContext = newRng(),
|
rng: ref HmacDrbgContext = newRng(),
|
||||||
parameters: PubParams = false): P
|
parameters: PubParams = false): P
|
||||||
{.raises: [Defect, InitializationError].} =
|
{.raises: [Defect, InitializationError], public.} =
|
||||||
let pubsub =
|
let pubsub =
|
||||||
when PubParams is bool:
|
when PubParams is bool:
|
||||||
P(switch: switch,
|
P(switch: switch,
|
||||||
|
@ -590,9 +603,9 @@ proc init*[PubParams: object | bool](
|
||||||
|
|
||||||
return pubsub
|
return pubsub
|
||||||
|
|
||||||
proc addObserver*(p: PubSub; observer: PubSubObserver) = p.observers[] &= observer
|
proc addObserver*(p: PubSub; observer: PubSubObserver) {.public.} = p.observers[] &= observer
|
||||||
|
|
||||||
proc removeObserver*(p: PubSub; observer: PubSubObserver) =
|
proc removeObserver*(p: PubSub; observer: PubSubObserver) {.public.} =
|
||||||
let idx = p.observers[].find(observer)
|
let idx = p.observers[].find(observer)
|
||||||
if idx != -1:
|
if idx != -1:
|
||||||
p.observers[].del(idx)
|
p.observers[].del(idx)
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2019 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2019 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2019 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2019 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2019 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2022 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2020 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2019 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2019 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2019 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-Libp2p
|
# Nim-Libp2p
|
||||||
## Copyright (c) 2021 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
## This module implements Routing Records.
|
## This module implements Routing Records.
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-Libp2p
|
# Nim-Libp2p
|
||||||
## Copyright (c) 2021 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
## This module implements Signed Envelope.
|
## This module implements Signed Envelope.
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2019 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2019 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2020 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2019 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
|
## Length Prefixed stream implementation
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
@ -15,6 +17,7 @@ import chronicles, chronos, metrics
|
||||||
import ../varint,
|
import ../varint,
|
||||||
../peerinfo,
|
../peerinfo,
|
||||||
../multiaddress,
|
../multiaddress,
|
||||||
|
../utility,
|
||||||
../errors
|
../errors
|
||||||
|
|
||||||
export errors
|
export errors
|
||||||
|
@ -132,26 +135,32 @@ method initStream*(s: LPStream) {.base.} =
|
||||||
inc getStreamTracker(s.objName).opened
|
inc getStreamTracker(s.objName).opened
|
||||||
trace "Stream created", s, objName = s.objName, dir = $s.dir
|
trace "Stream created", s, objName = s.objName, dir = $s.dir
|
||||||
|
|
||||||
proc join*(s: LPStream): Future[void] =
|
proc join*(s: LPStream): Future[void] {.public.} =
|
||||||
|
## Wait for the stream to be closed
|
||||||
s.closeEvent.wait()
|
s.closeEvent.wait()
|
||||||
|
|
||||||
method closed*(s: LPStream): bool {.base.} =
|
method closed*(s: LPStream): bool {.base, public.} =
|
||||||
s.isClosed
|
s.isClosed
|
||||||
|
|
||||||
method atEof*(s: LPStream): bool {.base.} =
|
method atEof*(s: LPStream): bool {.base, public.} =
|
||||||
s.isEof
|
s.isEof
|
||||||
|
|
||||||
method readOnce*(
|
method readOnce*(
|
||||||
s: LPStream,
|
s: LPStream,
|
||||||
pbytes: pointer,
|
pbytes: pointer,
|
||||||
nbytes: int):
|
nbytes: int):
|
||||||
Future[int] {.base, async.} =
|
Future[int] {.base, async, public.} =
|
||||||
|
## Reads whatever is available in the stream,
|
||||||
|
## up to `nbytes`. Will block if nothing is
|
||||||
|
## available
|
||||||
doAssert(false, "not implemented!")
|
doAssert(false, "not implemented!")
|
||||||
|
|
||||||
proc readExactly*(s: LPStream,
|
proc readExactly*(s: LPStream,
|
||||||
pbytes: pointer,
|
pbytes: pointer,
|
||||||
nbytes: int):
|
nbytes: int):
|
||||||
Future[void] {.async.} =
|
Future[void] {.async, public.} =
|
||||||
|
## Waits for `nbytes` to be available, then read
|
||||||
|
## them and return them
|
||||||
if s.atEof:
|
if s.atEof:
|
||||||
raise newLPStreamEOFError()
|
raise newLPStreamEOFError()
|
||||||
|
|
||||||
|
@ -180,7 +189,8 @@ proc readExactly*(s: LPStream,
|
||||||
proc readLine*(s: LPStream,
|
proc readLine*(s: LPStream,
|
||||||
limit = 0,
|
limit = 0,
|
||||||
sep = "\r\n"): Future[string]
|
sep = "\r\n"): Future[string]
|
||||||
{.async.} =
|
{.async, public.} =
|
||||||
|
## Reads up to `limit` bytes are read, or a `sep` is found
|
||||||
# TODO replace with something that exploits buffering better
|
# TODO replace with something that exploits buffering better
|
||||||
var lim = if limit <= 0: -1 else: limit
|
var lim = if limit <= 0: -1 else: limit
|
||||||
var state = 0
|
var state = 0
|
||||||
|
@ -206,7 +216,7 @@ proc readLine*(s: LPStream,
|
||||||
if len(result) == lim:
|
if len(result) == lim:
|
||||||
break
|
break
|
||||||
|
|
||||||
proc readVarint*(conn: LPStream): Future[uint64] {.async, gcsafe.} =
|
proc readVarint*(conn: LPStream): Future[uint64] {.async, gcsafe, public.} =
|
||||||
var
|
var
|
||||||
buffer: array[10, byte]
|
buffer: array[10, byte]
|
||||||
|
|
||||||
|
@ -225,7 +235,7 @@ proc readVarint*(conn: LPStream): Future[uint64] {.async, gcsafe.} =
|
||||||
if true: # can't end with a raise apparently
|
if true: # can't end with a raise apparently
|
||||||
raise (ref InvalidVarintError)(msg: "Cannot parse varint")
|
raise (ref InvalidVarintError)(msg: "Cannot parse varint")
|
||||||
|
|
||||||
proc readLp*(s: LPStream, maxSize: int): Future[seq[byte]] {.async, gcsafe.} =
|
proc readLp*(s: LPStream, maxSize: int): Future[seq[byte]] {.async, gcsafe, public.} =
|
||||||
## read length prefixed msg, with the length encoded as a varint
|
## read length prefixed msg, with the length encoded as a varint
|
||||||
let
|
let
|
||||||
length = await s.readVarint()
|
length = await s.readVarint()
|
||||||
|
@ -241,10 +251,11 @@ proc readLp*(s: LPStream, maxSize: int): Future[seq[byte]] {.async, gcsafe.} =
|
||||||
await s.readExactly(addr res[0], res.len)
|
await s.readExactly(addr res[0], res.len)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
method write*(s: LPStream, msg: seq[byte]): Future[void] {.base.} =
|
method write*(s: LPStream, msg: seq[byte]): Future[void] {.base, public.} =
|
||||||
|
# Write `msg` to stream, waiting for the write to be finished
|
||||||
doAssert(false, "not implemented!")
|
doAssert(false, "not implemented!")
|
||||||
|
|
||||||
proc writeLp*(s: LPStream, msg: openArray[byte]): Future[void] =
|
proc writeLp*(s: LPStream, msg: openArray[byte]): Future[void] {.public.} =
|
||||||
## Write `msg` with a varint-encoded length prefix
|
## Write `msg` with a varint-encoded length prefix
|
||||||
let vbytes = PB.toBytes(msg.len().uint64)
|
let vbytes = PB.toBytes(msg.len().uint64)
|
||||||
var buf = newSeqUninitialized[byte](msg.len() + vbytes.len)
|
var buf = newSeqUninitialized[byte](msg.len() + vbytes.len)
|
||||||
|
@ -252,10 +263,10 @@ proc writeLp*(s: LPStream, msg: openArray[byte]): Future[void] =
|
||||||
buf[vbytes.len..<buf.len] = msg
|
buf[vbytes.len..<buf.len] = msg
|
||||||
s.write(buf)
|
s.write(buf)
|
||||||
|
|
||||||
proc writeLp*(s: LPStream, msg: string): Future[void] =
|
proc writeLp*(s: LPStream, msg: string): Future[void] {.public.} =
|
||||||
writeLp(s, msg.toOpenArrayByte(0, msg.high))
|
writeLp(s, msg.toOpenArrayByte(0, msg.high))
|
||||||
|
|
||||||
proc write*(s: LPStream, msg: string): Future[void] =
|
proc write*(s: LPStream, msg: string): Future[void] {.public.} =
|
||||||
s.write(msg.toBytes())
|
s.write(msg.toBytes())
|
||||||
|
|
||||||
method closeImpl*(s: LPStream): Future[void] {.async, base.} =
|
method closeImpl*(s: LPStream): Future[void] {.async, base.} =
|
||||||
|
@ -266,7 +277,7 @@ method closeImpl*(s: LPStream): Future[void] {.async, base.} =
|
||||||
s.closeEvent.fire()
|
s.closeEvent.fire()
|
||||||
trace "Closed stream", s, objName = s.objName, dir = $s.dir
|
trace "Closed stream", s, objName = s.objName, dir = $s.dir
|
||||||
|
|
||||||
method close*(s: LPStream): Future[void] {.base, async.} = # {.raises [Defect].}
|
method close*(s: LPStream): Future[void] {.base, async, public.} = # {.raises [Defect].}
|
||||||
## close the stream - this may block, but will not raise exceptions
|
## close the stream - this may block, but will not raise exceptions
|
||||||
##
|
##
|
||||||
if s.isClosed:
|
if s.isClosed:
|
||||||
|
@ -280,7 +291,7 @@ method close*(s: LPStream): Future[void] {.base, async.} = # {.raises [Defect].}
|
||||||
# itself must implement this - once-only check as well, with their own field
|
# itself must implement this - once-only check as well, with their own field
|
||||||
await closeImpl(s)
|
await closeImpl(s)
|
||||||
|
|
||||||
proc closeWithEOF*(s: LPStream): Future[void] {.async.} =
|
proc closeWithEOF*(s: LPStream): Future[void] {.async, public.} =
|
||||||
## Close the stream and wait for EOF - use this with half-closed streams where
|
## Close the stream and wait for EOF - use this with half-closed streams where
|
||||||
## an EOF is expected to arrive from the other end.
|
## an EOF is expected to arrive from the other end.
|
||||||
##
|
##
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2019 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
|
## The switch is the core of libp2p, which brings together the
|
||||||
|
## transports, the connection manager, the upgrader and other
|
||||||
|
## parts to allow programs to use libp2p
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
@ -37,6 +41,7 @@ import stream/connection,
|
||||||
peerid,
|
peerid,
|
||||||
peerstore,
|
peerstore,
|
||||||
errors,
|
errors,
|
||||||
|
utility,
|
||||||
dialer
|
dialer
|
||||||
|
|
||||||
export connmanager, upgrade, dialer, peerstore
|
export connmanager, upgrade, dialer, peerstore
|
||||||
|
@ -56,7 +61,7 @@ const
|
||||||
ConcurrentUpgrades* = 4
|
ConcurrentUpgrades* = 4
|
||||||
|
|
||||||
type
|
type
|
||||||
Switch* = ref object of Dial
|
Switch* {.public.} = ref object of Dial
|
||||||
peerInfo*: PeerInfo
|
peerInfo*: PeerInfo
|
||||||
connManager*: ConnManager
|
connManager*: ConnManager
|
||||||
transports*: seq[Transport]
|
transports*: seq[Transport]
|
||||||
|
@ -69,22 +74,31 @@ type
|
||||||
|
|
||||||
proc addConnEventHandler*(s: Switch,
|
proc addConnEventHandler*(s: Switch,
|
||||||
handler: ConnEventHandler,
|
handler: ConnEventHandler,
|
||||||
kind: ConnEventKind) =
|
kind: ConnEventKind) {.public.} =
|
||||||
|
## Adds a ConnEventHandler, which will be triggered when
|
||||||
|
## a connection to a peer is created or dropped.
|
||||||
|
## There may be multiple connections per peer.
|
||||||
|
##
|
||||||
|
## The handler should not raise.
|
||||||
s.connManager.addConnEventHandler(handler, kind)
|
s.connManager.addConnEventHandler(handler, kind)
|
||||||
|
|
||||||
proc removeConnEventHandler*(s: Switch,
|
proc removeConnEventHandler*(s: Switch,
|
||||||
handler: ConnEventHandler,
|
handler: ConnEventHandler,
|
||||||
kind: ConnEventKind) =
|
kind: ConnEventKind) {.public.} =
|
||||||
s.connManager.removeConnEventHandler(handler, kind)
|
s.connManager.removeConnEventHandler(handler, kind)
|
||||||
|
|
||||||
proc addPeerEventHandler*(s: Switch,
|
proc addPeerEventHandler*(s: Switch,
|
||||||
handler: PeerEventHandler,
|
handler: PeerEventHandler,
|
||||||
kind: PeerEventKind) =
|
kind: PeerEventKind) {.public.} =
|
||||||
|
## Adds a PeerEventHandler, which will be triggered when
|
||||||
|
## a peer connects or disconnects from us.
|
||||||
|
##
|
||||||
|
## The handler should not raise.
|
||||||
s.connManager.addPeerEventHandler(handler, kind)
|
s.connManager.addPeerEventHandler(handler, kind)
|
||||||
|
|
||||||
proc removePeerEventHandler*(s: Switch,
|
proc removePeerEventHandler*(s: Switch,
|
||||||
handler: PeerEventHandler,
|
handler: PeerEventHandler,
|
||||||
kind: PeerEventKind) =
|
kind: PeerEventKind) {.public.} =
|
||||||
s.connManager.removePeerEventHandler(handler, kind)
|
s.connManager.removePeerEventHandler(handler, kind)
|
||||||
|
|
||||||
method addTransport*(s: Switch,
|
method addTransport*(s: Switch,
|
||||||
|
@ -92,32 +106,39 @@ method addTransport*(s: Switch,
|
||||||
s.transports &= t
|
s.transports &= t
|
||||||
s.dialer.addTransport(t)
|
s.dialer.addTransport(t)
|
||||||
|
|
||||||
proc isConnected*(s: Switch, peerId: PeerId): bool =
|
proc isConnected*(s: Switch, peerId: PeerId): bool {.public.} =
|
||||||
## returns true if the peer has one or more
|
## returns true if the peer has one or more
|
||||||
## associated connections (sockets)
|
## associated connections
|
||||||
##
|
##
|
||||||
|
|
||||||
peerId in s.connManager
|
peerId in s.connManager
|
||||||
|
|
||||||
proc disconnect*(s: Switch, peerId: PeerId): Future[void] {.gcsafe.} =
|
proc disconnect*(s: Switch, peerId: PeerId): Future[void] {.gcsafe, public.} =
|
||||||
|
## Disconnect from a peer, waiting for the connection(s) to be dropped
|
||||||
s.connManager.dropPeer(peerId)
|
s.connManager.dropPeer(peerId)
|
||||||
|
|
||||||
method connect*(
|
method connect*(
|
||||||
s: Switch,
|
s: Switch,
|
||||||
peerId: PeerId,
|
peerId: PeerId,
|
||||||
addrs: seq[MultiAddress],
|
addrs: seq[MultiAddress],
|
||||||
forceDial = false): Future[void] =
|
forceDial = false): Future[void] {.public.} =
|
||||||
|
## Connects to a peer without opening a stream to it
|
||||||
|
|
||||||
s.dialer.connect(peerId, addrs, forceDial)
|
s.dialer.connect(peerId, addrs, forceDial)
|
||||||
|
|
||||||
method dial*(
|
method dial*(
|
||||||
s: Switch,
|
s: Switch,
|
||||||
peerId: PeerId,
|
peerId: PeerId,
|
||||||
protos: seq[string]): Future[Connection] =
|
protos: seq[string]): Future[Connection] {.public.} =
|
||||||
|
## Open a stream to a connected peer with the specified `protos`
|
||||||
|
|
||||||
s.dialer.dial(peerId, protos)
|
s.dialer.dial(peerId, protos)
|
||||||
|
|
||||||
proc dial*(s: Switch,
|
proc dial*(s: Switch,
|
||||||
peerId: PeerId,
|
peerId: PeerId,
|
||||||
proto: string): Future[Connection] =
|
proto: string): Future[Connection] {.public.} =
|
||||||
|
## Open a stream to a connected peer with the specified `proto`
|
||||||
|
|
||||||
dial(s, peerId, @[proto])
|
dial(s, peerId, @[proto])
|
||||||
|
|
||||||
method dial*(
|
method dial*(
|
||||||
|
@ -125,18 +146,26 @@ method dial*(
|
||||||
peerId: PeerId,
|
peerId: PeerId,
|
||||||
addrs: seq[MultiAddress],
|
addrs: seq[MultiAddress],
|
||||||
protos: seq[string],
|
protos: seq[string],
|
||||||
forceDial = false): Future[Connection] =
|
forceDial = false): Future[Connection] {.public.} =
|
||||||
|
## Connected to a peer and open a stream
|
||||||
|
## with the specified `protos`
|
||||||
|
|
||||||
s.dialer.dial(peerId, addrs, protos, forceDial)
|
s.dialer.dial(peerId, addrs, protos, forceDial)
|
||||||
|
|
||||||
proc dial*(
|
proc dial*(
|
||||||
s: Switch,
|
s: Switch,
|
||||||
peerId: PeerId,
|
peerId: PeerId,
|
||||||
addrs: seq[MultiAddress],
|
addrs: seq[MultiAddress],
|
||||||
proto: string): Future[Connection] =
|
proto: string): Future[Connection] {.public.} =
|
||||||
|
## Connected to a peer and open a stream
|
||||||
|
## with the specified `proto`
|
||||||
|
|
||||||
dial(s, peerId, addrs, @[proto])
|
dial(s, peerId, addrs, @[proto])
|
||||||
|
|
||||||
proc mount*[T: LPProtocol](s: Switch, proto: T, matcher: Matcher = nil)
|
proc mount*[T: LPProtocol](s: Switch, proto: T, matcher: Matcher = nil)
|
||||||
{.gcsafe, raises: [Defect, LPError].} =
|
{.gcsafe, raises: [Defect, LPError], public.} =
|
||||||
|
## mount a protocol to the switch
|
||||||
|
|
||||||
if isNil(proto.handler):
|
if isNil(proto.handler):
|
||||||
raise newException(LPError,
|
raise newException(LPError,
|
||||||
"Protocol has to define a handle method or proc")
|
"Protocol has to define a handle method or proc")
|
||||||
|
@ -217,7 +246,10 @@ proc accept(s: Switch, transport: Transport) {.async.} = # noraises
|
||||||
await conn.close()
|
await conn.close()
|
||||||
return
|
return
|
||||||
|
|
||||||
proc stop*(s: Switch) {.async.} =
|
proc stop*(s: Switch) {.async, public.} =
|
||||||
|
## Stop listening on every transport, and
|
||||||
|
## close every active connections
|
||||||
|
|
||||||
trace "Stopping switch"
|
trace "Stopping switch"
|
||||||
|
|
||||||
s.started = false
|
s.started = false
|
||||||
|
@ -248,7 +280,9 @@ proc stop*(s: Switch) {.async.} =
|
||||||
|
|
||||||
trace "Switch stopped"
|
trace "Switch stopped"
|
||||||
|
|
||||||
proc start*(s: Switch) {.async, gcsafe.} =
|
proc start*(s: Switch) {.async, gcsafe, public.} =
|
||||||
|
## Start listening on every transport
|
||||||
|
|
||||||
trace "starting switch for peer", peerInfo = s.peerInfo
|
trace "starting switch for peer", peerInfo = s.peerInfo
|
||||||
var startFuts: seq[Future[void]]
|
var startFuts: seq[Future[void]]
|
||||||
for t in s.transports:
|
for t in s.transports:
|
||||||
|
@ -294,7 +328,7 @@ proc newSwitch*(peerInfo: PeerInfo,
|
||||||
ms: MultistreamSelect,
|
ms: MultistreamSelect,
|
||||||
nameResolver: NameResolver = nil,
|
nameResolver: NameResolver = nil,
|
||||||
peerStore = PeerStore.new()): Switch
|
peerStore = PeerStore.new()): Switch
|
||||||
{.raises: [Defect, LPError].} =
|
{.raises: [Defect, LPError], public.} =
|
||||||
if secureManagers.len == 0:
|
if secureManagers.len == 0:
|
||||||
raise newException(LPError, "Provide at least one secure manager")
|
raise newException(LPError, "Provide at least one secure manager")
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-Libp2p
|
# Nim-Libp2p
|
||||||
## Copyright (c) 2018 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
## This module implements transcoder interface.
|
## This module implements transcoder interface.
|
||||||
import vbuffer
|
import vbuffer
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2019 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
|
## TCP transport implementation
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
@ -20,7 +22,8 @@ import transport,
|
||||||
../multiaddress,
|
../multiaddress,
|
||||||
../stream/connection,
|
../stream/connection,
|
||||||
../stream/chronosstream,
|
../stream/chronosstream,
|
||||||
../upgrademngrs/upgrade
|
../upgrademngrs/upgrade,
|
||||||
|
../utility
|
||||||
|
|
||||||
logScope:
|
logScope:
|
||||||
topics = "libp2p tcptransport"
|
topics = "libp2p tcptransport"
|
||||||
|
@ -118,7 +121,7 @@ proc connHandler*(self: TcpTransport,
|
||||||
proc new*(
|
proc new*(
|
||||||
T: typedesc[TcpTransport],
|
T: typedesc[TcpTransport],
|
||||||
flags: set[ServerFlags] = {},
|
flags: set[ServerFlags] = {},
|
||||||
upgrade: Upgrade): T =
|
upgrade: Upgrade): T {.public.} =
|
||||||
|
|
||||||
let transport = T(
|
let transport = T(
|
||||||
flags: flags,
|
flags: flags,
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2019 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
##
|
##
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2021 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
|
## WebSocket & WebSocket Secure transport implementation
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
@ -18,6 +20,7 @@ import transport,
|
||||||
../multistream,
|
../multistream,
|
||||||
../connmanager,
|
../connmanager,
|
||||||
../multiaddress,
|
../multiaddress,
|
||||||
|
../utility,
|
||||||
../stream/connection,
|
../stream/connection,
|
||||||
../upgrademngrs/upgrade,
|
../upgrademngrs/upgrade,
|
||||||
websock/websock
|
websock/websock
|
||||||
|
@ -313,7 +316,8 @@ proc new*(
|
||||||
flags: set[ServerFlags] = {},
|
flags: set[ServerFlags] = {},
|
||||||
factories: openArray[ExtFactory] = [],
|
factories: openArray[ExtFactory] = [],
|
||||||
rng: Rng = nil,
|
rng: Rng = nil,
|
||||||
handshakeTimeout = DefaultHeadersTimeout): T =
|
handshakeTimeout = DefaultHeadersTimeout): T {.public.} =
|
||||||
|
## Creates a secure WebSocket transport
|
||||||
|
|
||||||
T(
|
T(
|
||||||
upgrader: upgrade,
|
upgrader: upgrade,
|
||||||
|
@ -331,7 +335,8 @@ proc new*(
|
||||||
flags: set[ServerFlags] = {},
|
flags: set[ServerFlags] = {},
|
||||||
factories: openArray[ExtFactory] = [],
|
factories: openArray[ExtFactory] = [],
|
||||||
rng: Rng = nil,
|
rng: Rng = nil,
|
||||||
handshakeTimeout = DefaultHeadersTimeout): T =
|
handshakeTimeout = DefaultHeadersTimeout): T {.public.} =
|
||||||
|
## Creates a clear-text WebSocket transport
|
||||||
|
|
||||||
T.new(
|
T.new(
|
||||||
upgrade = upgrade,
|
upgrade = upgrade,
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2021 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2021 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,18 @@
|
||||||
## Nim-LibP2P
|
# Nim-LibP2P
|
||||||
## Copyright (c) 2020 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
import stew/byteutils
|
import stew/byteutils
|
||||||
|
|
||||||
|
template public* {.pragma.}
|
||||||
|
|
||||||
const
|
const
|
||||||
ShortDumpMax = 12
|
ShortDumpMax = 12
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-Libp2p
|
# Nim-Libp2p
|
||||||
## Copyright (c) 2020 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-Libp2p
|
# Nim-Libp2p
|
||||||
## Copyright (c) 2018 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
## This module implements Variable Integer `VARINT`.
|
## This module implements Variable Integer `VARINT`.
|
||||||
## This module supports two variants of variable integer
|
## This module supports two variants of variable integer
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-Libp2p
|
# Nim-Libp2p
|
||||||
## Copyright (c) 2018 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
## This module implements variable buffer.
|
## This module implements variable buffer.
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
## Nim-Libp2p
|
# Nim-Libp2p
|
||||||
## Copyright (c) 2018 Status Research & Development GmbH
|
# Copyright (c) 2022 Status Research & Development GmbH
|
||||||
## Licensed under either of
|
# Licensed under either of
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
## at your option.
|
# at your option.
|
||||||
## This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
# those terms.
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue