Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge unstable into master #1003

Merged
merged 46 commits into from
Dec 18, 2023
Merged
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
c76d1e1
Remove nim 1.2 support (#907)
Menduist Jun 7, 2023
32085ca
Allow to override TCP connection timeouts (#903)
Menduist Jun 7, 2023
3640b4d
Autonat and HP changes (#899)
diegomrsantos Jun 7, 2023
3725f6a
chore: add basic metrics for rendezvous (#905)
vpavlin Jun 7, 2023
eb78292
Bump deps (#896)
Menduist Jun 7, 2023
c28d8bb
WS Transport: handle 'tls/ws' (#914)
Menduist Jun 12, 2023
6771147
Consider dns as public address (#913)
diegomrsantos Jun 13, 2023
a65b7b0
GossipSub: remove peer if we can't establish sendConn (#886)
Menduist Jun 14, 2023
49dfa84
Transports: handle TransportAbortedError properly (#916)
Menduist Jun 14, 2023
9d4c430
Bumper: fix case where target is up to date (#917)
Menduist Jun 15, 2023
5efa089
TCP transport: handle getObservedAddr errors (#918)
Menduist Jun 20, 2023
224f92e
Fix #916 regression causing accept loop lockup (#919)
Menduist Jun 20, 2023
1c4d083
Add GossipSub ping (#912)
Menduist Jun 21, 2023
66f9dc9
Remove all `Result.get()`s & `Option` -> `Opt` (#902)
Menduist Jun 28, 2023
f85d0f7
Handling Opt[PeerId] in logging (#923)
diegomrsantos Jun 28, 2023
43359dd
standard nimble env vars (#921)
arnetheduck Jun 28, 2023
81b861b
avoid `ProveField` warning in `crypto.init` (#915)
etan-status Jun 29, 2023
c45f970
Gossipsub scoring improvements (#909)
diegomrsantos Jul 3, 2023
74c402e
wstransport.nim: avoid re-raising 'TransportOsError' to avoid stoppin…
Ivansete-status Jul 7, 2023
1721f07
Fix crash on empty write (#930)
Menduist Jul 10, 2023
fab1340
avoid a few zeroMem (#932)
arnetheduck Jul 11, 2023
440461b
GS: improve handleIHave (#922)
Menduist Jul 11, 2023
b784167
GossipSub: IDontWant (#934)
Menduist Jul 28, 2023
7a369dd
GossipSub: Limit flood publishing (#911)
Menduist Jul 31, 2023
56c23a2
Add specs crypto tests (#938)
Menduist Aug 1, 2023
d6263bf
nim-websock new version compatibility (#939)
Menduist Aug 2, 2023
f80ce31
Bandwidth estimate as a parameter (#941)
diegomrsantos Aug 14, 2023
e03547e
Perf protocol (#925)
lchenut Aug 14, 2023
c6aa085
Prevent concurrent IWANT of the same message (#943)
diegomrsantos Aug 21, 2023
b76bac7
avoid importing `ecnist` when not needed (#942)
arnetheduck Aug 30, 2023
545a31d
Bump dependencies (#947)
Menduist Sep 6, 2023
ff77d52
IDontWant metrics (#946)
Menduist Sep 6, 2023
20b0e40
Fix doc generation CI (#948)
Menduist Sep 8, 2023
b2eac7e
GS: Relay messages to direct peers (#949)
Menduist Sep 15, 2023
56599f5
GossipSub Traffic scoring (#920)
diegomrsantos Sep 22, 2023
61929ae
Improve rdv advertise (#951)
diegomrsantos Sep 27, 2023
7587181
Split msgs in iwant response if bigger than limit (#944)
diegomrsantos Oct 2, 2023
575344e
Update interop CI name (#956)
Menduist Oct 5, 2023
459f685
Add a flag if a peer should be disconnected when above rate limit (#954)
diegomrsantos Oct 5, 2023
18b0f72
Rate Limit tests (#953)
diegomrsantos Oct 5, 2023
60f9536
Remove ConnManager from Upgrade (#959)
Menduist Oct 13, 2023
fc4e9a8
Fix WS transport when the connection aborts (#967)
lchenut Oct 23, 2023
3fc1236
Revert "Prevent concurrent IWANT of the same message (#943)" (#977)
diegomrsantos Nov 3, 2023
ebef85c
Rate limit fixes (#965)
diegomrsantos Nov 9, 2023
5f7a3ab
fix: doc workflow (#985)
diegomrsantos Nov 16, 2023
4e7eaba
fix chronos v4 compat (#982)
arnetheduck Nov 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/bumper.yml
Original file line number Diff line number Diff line change
@@ -24,21 +24,22 @@ jobs:
repository: ${{ matrix.target.repo }}
ref: ${{ matrix.target.branch }}
path: nbc
submodules: true
fetch-depth: 0
token: ${{ secrets.ACTIONS_GITHUB_TOKEN }}

- name: Checkout this ref
run: |
cd nbc/vendor/nim-libp2p
cd nbc
git submodule update --init vendor/nim-libp2p
cd vendor/nim-libp2p
git checkout $GITHUB_SHA

- name: Commit this bump
run: |
cd nbc
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
git config --global user.name = "${{ github.actor }}"
git commit -a -m "auto-bump nim-libp2p"
git commit --allow-empty -a -m "auto-bump nim-libp2p"
git branch -D nim-libp2p-auto-bump-${GITHUB_REF##*/} || true
git switch -c nim-libp2p-auto-bump-${GITHUB_REF##*/}
git push -f origin nim-libp2p-auto-bump-${GITHUB_REF##*/}
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ jobs:
cpu: amd64
#- os: windows
#cpu: i386
branch: [version-1-2, version-1-6]
branch: [version-1-6]
include:
- target:
os: linux
2 changes: 1 addition & 1 deletion .github/workflows/doc.yml
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ jobs:

- uses: jiro4989/setup-nim-action@v1
with:
nim-version: 'stable'
nim-version: '1.6.x'

- name: Generate doc
run: |
6 changes: 3 additions & 3 deletions .github/workflows/interop.yml
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ jobs:

- name: Build image
run: >
cd multidim-interop/impl/nim/v1.0 &&
cd transport-interop/impl/nim/v1.0 &&
make commitSha=$GITHUB_SHA image_name=nim-libp2p-head

- name: Create ping-version.json
@@ -45,10 +45,10 @@ jobs:
]
}
EOF

) > ${{ github.workspace }}/test_head.json

- uses: libp2p/test-plans/.github/actions/run-interop-ping-test@master
- uses: libp2p/test-plans/.github/actions/run-transport-interop-test@master
with:
test-filter: nim-libp2p-head
extra-versions: ${{ github.workspace }}/test_head.json
4 changes: 2 additions & 2 deletions .github/workflows/multi_nim.yml
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ jobs:
cpu: amd64
#- os: windows
#cpu: i386
branch: [version-1-2, version-1-6, devel]
branch: [version-1-6, version-2-0, devel]
include:
- target:
os: linux
@@ -48,7 +48,7 @@ jobs:

name: '${{ matrix.target.os }}-${{ matrix.target.cpu }} (Nim ${{ matrix.branch }})'
runs-on: ${{ matrix.builder }}
continue-on-error: ${{ matrix.branch == 'devel' }}
continue-on-error: ${{ matrix.branch == 'devel' || matrix.branch == 'version-2-0' }}
steps:
- name: Checkout
uses: actions/checkout@v2
31 changes: 16 additions & 15 deletions .pinned
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
bearssl;https://github.com/status-im/nim-bearssl@#acf9645e328bdcab481cfda1c158e07ecd46bd7b
chronicles;https://github.com/status-im/nim-chronicles@#1e6350870855541b381d77d4659688bc0d2c4227
chronos;https://github.com/status-im/nim-chronos@#ab5a8c2e0f6941fe3debd61dff0293790079d1b0
dnsclient;https://github.com/ba0f3/dnsclient.nim@#fcd7443634b950eaea574e5eaa00a628ae029823
faststreams;https://github.com/status-im/nim-faststreams@#814f8927e1f356f39219f37f069b83066bcc893a
httputils;https://github.com/status-im/nim-http-utils@#a85bd52ae0a956983ca6b3267c72961d2ec0245f
json_serialization;https://github.com/status-im/nim-json-serialization@#a7d815ed92f200f490c95d3cfd722089cc923ce6
metrics;https://github.com/status-im/nim-metrics@#abf3acc7f06cee9ee2c287d2f31413dc3df4c04e
nimcrypto;https://github.com/cheatfate/nimcrypto@#4014ef939b51e02053c2e16dd3481d47bc9267dd
secp256k1;https://github.com/status-im/nim-secp256k1@#fd173fdff863ce2e211cf64c9a03bc7539fe40b0
serialization;https://github.com/status-im/nim-serialization@#5b7cea55efeb074daa8abd8146a03a34adb4521a
stew;https://github.com/status-im/nim-stew@#003fe9f0c83c2b0b2ccbd37087e6d1ccd30a3234
bearssl;https://github.com/status-im/nim-bearssl@#e4157639db180e52727712a47deaefcbbac6ec86
chronicles;https://github.com/status-im/nim-chronicles@#32ac8679680ea699f7dbc046e8e0131cac97d41a
chronos;https://github.com/status-im/nim-chronos@#ba143e029f35fd9b4cd3d89d007cc834d0d5ba3c
dnsclient;https://github.com/ba0f3/dnsclient.nim@#23214235d4784d24aceed99bbfe153379ea557c8
faststreams;https://github.com/status-im/nim-faststreams@#720fc5e5c8e428d9d0af618e1e27c44b42350309
httputils;https://github.com/status-im/nim-http-utils@#3b491a40c60aad9e8d3407443f46f62511e63b18
json_serialization;https://github.com/status-im/nim-json-serialization@#85b7ea093cb85ee4f433a617b97571bd709d30df
metrics;https://github.com/status-im/nim-metrics@#6142e433fc8ea9b73379770a788017ac528d46ff
nimcrypto;https://github.com/cheatfate/nimcrypto@#1c8d6e3caf3abc572136ae9a1da81730c4eb4288
results;https://github.com/arnetheduck/nim-results@#f3c666a272c69d70cb41e7245e7f6844797303ad
secp256k1;https://github.com/status-im/nim-secp256k1@#7246d91c667f4cc3759fdd50339caa45a2ecd8be
serialization;https://github.com/status-im/nim-serialization@#4bdbc29e54fe54049950e352bb969aab97173b35
stew;https://github.com/status-im/nim-stew@#3159137d9a3110edb4024145ce0ba778975de40e
testutils;https://github.com/status-im/nim-testutils@#dfc4c1b39f9ded9baf6365014de2b4bfb4dafc34
unittest2;https://github.com/status-im/nim-unittest2@#883c7a50ad3b82158e64d074c5578fe33ab3c452
websock;https://github.com/status-im/nim-websock@#fea05cde8b123b38d1a0a8524b77efbc84daa848
zlib;https://github.com/status-im/nim-zlib@#826e2fc013f55b4478802d4f2e39f187c50d520a
unittest2;https://github.com/status-im/nim-unittest2@#2300fa9924a76e6c96bc4ea79d043e3a0f27120c
websock;https://github.com/status-im/nim-websock@#f8ed9b40a5ff27ad02a3c237c4905b0924e3f982
zlib;https://github.com/status-im/nim-zlib@#38b72eda9d70067df4a953f56b5ed59630f2a17b
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -105,7 +105,7 @@ The versioning follows [semver](https://semver.org/), with some additions:
- Some of libp2p procedures are marked as `.public.`, they will remain compatible during each `MAJOR` version
- The rest of the procedures are considered internal, and can change at any `MINOR` version (but remain compatible for each new `PATCH`)

We aim to be compatible at all time with at least 2 Nim `MINOR` versions, currently `1.2 & 1.6`
We aim to be compatible at all time with at least 2 Nim `MINOR` versions, currently `1.6 & 2.0`

## Development
Clone and Install dependencies:
7 changes: 2 additions & 5 deletions config.nims
Original file line number Diff line number Diff line change
@@ -9,11 +9,8 @@ switch("warning", "ObservableStores:off")
switch("warning", "LockLevel:off")
--define:chronosStrictException
--styleCheck:usages
if (NimMajor, NimMinor) < (1, 6):
--styleCheck:hint
else:
switch("warningAsError", "UseBase:on")
--styleCheck:error
switch("warningAsError", "UseBase:on")
--styleCheck:error

# Avoid some rare stack corruption while using exceptions with a SEH-enabled
# toolchain: https://github.com/status-im/nimbus-eth2/issues/3121
43 changes: 25 additions & 18 deletions libp2p.nimble
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ description = "LibP2P implementation"
license = "MIT"
skipDirs = @["tests", "examples", "Nim", "tools", "scripts", "docs"]

requires "nim >= 1.2.0",
requires "nim >= 1.6.0",
"nimcrypto >= 0.4.1",
"dnsclient >= 0.3.0 & < 0.4.0",
"bearssl >= 0.1.4",
@@ -17,14 +17,24 @@ requires "nim >= 1.2.0",
"secp256k1",
"stew#head",
"websock",
"unittest2 >= 0.0.5 & < 0.1.0"
"unittest2 >= 0.0.5 & <= 0.1.0"

let nimc = getEnv("NIMC", "nim") # Which nim compiler to use
let lang = getEnv("NIMLANG", "c") # Which backend (c/cpp/js)
let flags = getEnv("NIMFLAGS", "") # Extra flags for the compiler
let verbose = getEnv("V", "") notin ["", "0"]

let cfg =
" --styleCheck:usages --styleCheck:error" &
(if verbose: "" else: " --verbosity:0 --hints:off") &
" --skipParentCfg --skipUserCfg -f" &
" --threads:on --opt:speed"

import hashes, strutils

import hashes
proc runTest(filename: string, verify: bool = true, sign: bool = true,
moreoptions: string = "") =
var excstr = "nim c --skipParentCfg --opt:speed -d:debug "
excstr.add(" " & getEnv("NIMFLAGS") & " ")
excstr.add(" --verbosity:0 --hints:off ")
var excstr = nimc & " " & lang & " -d:debug " & cfg & " " & flags
excstr.add(" -d:libp2p_pubsub_sign=" & $sign)
excstr.add(" -d:libp2p_pubsub_verify=" & $verify)
excstr.add(" " & moreoptions & " ")
@@ -34,15 +44,15 @@ proc runTest(filename: string, verify: bool = true, sign: bool = true,
rmFile "tests/" & filename.toExe

proc buildSample(filename: string, run = false, extraFlags = "") =
var excstr = "nim c --opt:speed --threads:on -d:debug --verbosity:0 --hints:off -p:. " & extraFlags
var excstr = nimc & " " & lang & " " & cfg & " " & flags & " -p:. " & extraFlags
excstr.add(" examples/" & filename)
exec excstr
if run:
exec "./examples/" & filename.toExe
rmFile "examples/" & filename.toExe

proc tutorialToMd(filename: string) =
let markdown = gorge "cat " & filename & " | nim c -r --verbosity:0 --hints:off tools/markdown_builder.nim "
let markdown = gorge "cat " & filename & " | " & nimc & " " & lang & " -r --verbosity:0 --hints:off tools/markdown_builder.nim "
writeFile(filename.replace(".nim", ".md"), markdown)

task testnative, "Runs libp2p native tests":
@@ -104,15 +114,12 @@ task examples_build, "Build the samples":
buildSample("circuitrelay", true)
buildSample("tutorial_1_connect", true)
buildSample("tutorial_2_customproto", true)
if (NimMajor, NimMinor) > (1, 2):
# These tutorials relies on post 1.4 exception tracking
buildSample("tutorial_3_protobuf", true)
buildSample("tutorial_4_gossipsub", true)
buildSample("tutorial_5_discovery", true)
# Nico doesn't work in 1.2
exec "nimble install -y nimpng@#HEAD" # this is to fix broken build on 1.7.3, remove it when nimpng version 0.3.2 or later is released
exec "nimble install -y nico"
buildSample("tutorial_6_game", false, "--styleCheck:off")
buildSample("tutorial_3_protobuf", true)
buildSample("tutorial_4_gossipsub", true)
buildSample("tutorial_5_discovery", true)
exec "nimble install -y nimpng@#HEAD" # this is to fix broken build on 1.7.3, remove it when nimpng version 0.3.2 or later is released
exec "nimble install -y nico"
buildSample("tutorial_6_game", false, "--styleCheck:off")

# pin system
# while nimble lockfile
@@ -123,7 +130,7 @@ task pin, "Create a lockfile":
# pinner.nim was originally here
# but you can't read output from
# a command in a nimscript
exec "nim c -r tools/pinner.nim"
exec nimc & " c -r tools/pinner.nim"

import sequtils
import os
27 changes: 12 additions & 15 deletions libp2p/builders.nim
Original file line number Diff line number Diff line change
@@ -16,10 +16,7 @@ runnableExamples:
# etc
.build()

when (NimMajor, NimMinor) < (1, 4):
{.push raises: [Defect].}
else:
{.push raises: [].}
{.push raises: [].}

import
options, tables, chronos, chronicles, sequtils,
@@ -36,7 +33,7 @@ export
switch, peerid, peerinfo, connection, multiaddress, crypto, errors

type
TransportProvider* {.public.} = proc(upgr: Upgrade): Transport {.gcsafe, raises: [Defect].}
TransportProvider* {.public.} = proc(upgr: Upgrade): Transport {.gcsafe, raises: [].}

SecureProtocol* {.pure.} = enum
Noise,
@@ -57,7 +54,7 @@ type
protoVersion: string
agentVersion: string
nameResolver: NameResolver
peerStoreCapacity: Option[int]
peerStoreCapacity: Opt[int]
autonat: bool
circuitRelay: Relay
rdv: RendezVous
@@ -173,7 +170,7 @@ proc withMaxConnsPerPeer*(b: SwitchBuilder, maxConnsPerPeer: int): SwitchBuilder
b

proc withPeerStore*(b: SwitchBuilder, capacity: int): SwitchBuilder {.public.} =
b.peerStoreCapacity = some(capacity)
b.peerStoreCapacity = Opt.some(capacity)
b

proc withProtoVersion*(b: SwitchBuilder, protoVersion: string): SwitchBuilder {.public.} =
@@ -205,7 +202,7 @@ proc withServices*(b: SwitchBuilder, services: seq[Service]): SwitchBuilder =
b

proc build*(b: SwitchBuilder): Switch
{.raises: [Defect, LPError], public.} =
{.raises: [LPError], public.} =

if b.rng == nil: # newRng could fail
raise newException(Defect, "Cannot initialize RNG")
@@ -230,7 +227,7 @@ proc build*(b: SwitchBuilder): Switch
identify = Identify.new(peerInfo, b.sendSignedPeerRecord)
connManager = ConnManager.new(b.maxConnsPerPeer, b.maxConnections, b.maxIn, b.maxOut)
ms = MultistreamSelect.new()
muxedUpgrade = MuxedUpgrade.new(b.muxers, secureManagerInstances, connManager, ms)
muxedUpgrade = MuxedUpgrade.new(b.muxers, secureManagerInstances, ms)

let
transports = block:
@@ -245,9 +242,9 @@ proc build*(b: SwitchBuilder): Switch
if isNil(b.rng):
b.rng = newRng()

let peerStore =
if isSome(b.peerStoreCapacity):
PeerStore.new(identify, b.peerStoreCapacity.get())
let peerStore = block:
b.peerStoreCapacity.withValue(capacity):
PeerStore.new(identify, capacity)
else:
PeerStore.new(identify)

@@ -296,7 +293,7 @@ proc newStandardSwitch*(
nameResolver: NameResolver = nil,
sendSignedPeerRecord = false,
peerStoreCapacity = 1000): Switch
{.raises: [Defect, LPError], public.} =
{.raises: [LPError], public.} =
## Helper for common switch configurations.
{.push warning[Deprecated]:off.}
if SecureProtocol.Secio in secureManagers:
@@ -319,7 +316,7 @@ proc newStandardSwitch*(
.withNameResolver(nameResolver)
.withNoise()

if privKey.isSome():
b = b.withPrivateKey(privKey.get())
privKey.withValue(pkey):
b = b.withPrivateKey(pkey)

b.build()
10 changes: 2 additions & 8 deletions libp2p/cid.nim
Original file line number Diff line number Diff line change
@@ -9,10 +9,7 @@

## This module implementes CID (Content IDentifier).

when (NimMajor, NimMinor) < (1, 4):
{.push raises: [Defect].}
else:
{.push raises: [].}
{.push raises: [].}

import tables, hashes
import multibase, multicodec, multihash, vbuffer, varint
@@ -279,9 +276,6 @@ proc `$`*(cid: Cid): string =
BTCBase58.encode(cid.data.buffer)
elif cid.cidver == CIDv1:
let res = MultiBase.encode("base58btc", cid.data.buffer)
if res.isOk():
res.get()
else:
""
res.get("")
else:
""
15 changes: 6 additions & 9 deletions libp2p/connmanager.nim
Original file line number Diff line number Diff line change
@@ -7,12 +7,9 @@
# This file may not be copied, modified, or distributed except according to
# those terms.

when (NimMajor, NimMinor) < (1, 4):
{.push raises: [Defect].}
else:
{.push raises: [].}
{.push raises: [].}

import std/[options, tables, sequtils, sets]
import std/[tables, sequtils, sets]
import pkg/[chronos, chronicles, metrics]
import peerinfo,
peerstore,
@@ -51,7 +48,7 @@ type

ConnEventHandler* =
proc(peerId: PeerId, event: ConnEvent): Future[void]
{.gcsafe, raises: [Defect].}
{.gcsafe, raises: [].}

PeerEventKind* {.pure.} = enum
Left,
@@ -65,7 +62,7 @@ type
discard

PeerEventHandler* =
proc(peerId: PeerId, event: PeerEvent): Future[void] {.gcsafe, raises: [Defect].}
proc(peerId: PeerId, event: PeerEvent): Future[void] {.gcsafe, raises: [].}

ConnManager* = ref object of RootObj
maxConnsPerPeer: int
@@ -285,7 +282,7 @@ proc selectMuxer*(c: ConnManager, peerId: PeerId): Muxer =

proc storeMuxer*(c: ConnManager,
muxer: Muxer)
{.raises: [Defect, CatchableError].} =
{.raises: [CatchableError].} =
## store the connection and muxer
##

@@ -338,7 +335,7 @@ proc getIncomingSlot*(c: ConnManager): Future[ConnectionSlot] {.async.} =
await c.inSema.acquire()
return ConnectionSlot(connManager: c, direction: In)

proc getOutgoingSlot*(c: ConnManager, forceDial = false): ConnectionSlot {.raises: [Defect, TooManyConnectionsError].} =
proc getOutgoingSlot*(c: ConnManager, forceDial = false): ConnectionSlot {.raises: [TooManyConnectionsError].} =
if forceDial:
c.outSema.forceAcquire()
elif not c.outSema.tryAcquire():
Loading