188 Commits

Author SHA1 Message Date
Richard Ramos
3408a4ce1a
refactor: create MeshPeer function in Pubsub 2025-08-22 11:36:37 +01:00
richΛrd
ab817a0cb1
feat: expose router and mesh peers (#1) 2025-08-22 11:36:37 +01:00
Pop Chunhapanya
bf5b583843
Allow cancelling IWANT using IDONTWANT (#591)
As specified in the Gossipsub v1.2 spec, we should allow cancelling
IWANT by IDONTWANT.

That is if IDONTWANT already arrived, we should not process IWANT.

However due to the code structure, we can cancel IWANT only in
handleIWant.


https://github.com/libp2p/specs/blob/master/pubsub/gossipsub/gossipsub-v1.2.md#cancelling-iwant
2024-12-30 22:25:26 +02:00
Nishant Das
0936035d5f
Improve IDONTWANT Flood Protection (#590)
In this PR we add in a new config parameter called `MaxIDontWantLength`
which would be very similarly used as `MaxIHaveLength` has been used of
`IHAVE` messgaes . This parameter has been set as the value of `10` now.

The main purpose is to bring how IDONTWANT messages are handled in line
with how IHAVE have been handled. We add the relevant changes to the
`handleIDontWant` method along with adding in a new regression test for
this check.
2024-12-28 13:49:13 +02:00
Nishant Das
3536508a9d
Fix the Router's Ability to Prune the Mesh Periodically (#589)
When a new peer wants to graft us into their mesh, we check our current
mesh size to determine whether we can add any more new peers to it. This
is done to prevent our mesh size from being greater than `Dhi` and
prevent mesh takeover attacks here:


c06df2f9a3/gossipsub.go (L943)

During every heartbeat we check our mesh size and if it is **greater**
than `Dhi` then we will prune our mesh back down to `D`.

c06df2f9a3/gossipsub.go (L1608)

However if you look closely at both lines there is a problematic end
result. Since we only stop grafting new peers into our mesh if our
current mesh size is **greater than or equal to** `Dhi` and we only
prune peers if the current mesh size is greater than `Dhi`.

This would result in the mesh being in a state of stasis at `Dhi`.
Rather than float between `D` and `Dhi` , the mesh stagnates at `Dhi` .
This would end up increasing the target degree of the node to `Dhi` from
`D`. This had been observed in ethereum mainnet by recording mesh
interactions and message fulfillment from those peers.

This PR fixes it by adding an equality check to the conditional so that
it can be periodically pruned. The PR also adds a regression test for
this particular case.
2024-12-26 20:02:14 +02:00
Yahya Hassanzadeh, Ph.D.
c06df2f9a3
Add Function to Enable Application Layer to Send Direct Control Messages (#562)
### PR Description

This PR addresses https://github.com/libp2p/go-libp2p-pubsub/issues/561;
i.e., adding a new `SendControl` function to the `GossipSubRouter`. This
will allow the application layer to send direct control messages to
peers, facilitating finer-grained testing.
2024-10-18 23:28:24 +03:00
Pavel Zbitskiy
f71345c1ec
Do not format expensive debug messages in non-debug levels in doDropRPC (#580)
In high load scenarios when consumer is slow, `doDropRPC` is called
often and makes extra unnecessary allocations formatting `log.Debug`
message.

Fixed by checking log level before running expensive formatting.

Before:
```
BenchmarkAllocDoDropRPC-10    	13684732	        76.28 ns/op	     144 B/op	       3 allocs/op
```

After:
```
BenchmarkAllocDoDropRPC-10    	28140273	        42.88 ns/op	     112 B/op	       1 allocs/op
```
2024-09-25 09:33:35 +03:00
Pop Chunhapanya
b421b3ab05
GossipSub v1.2: IDONTWANT control message and priority queue. (#553)
## GossipSub v1.2 implementation

Specification: libp2p/specs#548

### Work Summary
Sending IDONTWANT

Implement a smart queue
Add priorities to the smart queue

    Put IDONTWANT packets into the smart priority queue as soon as the node gets the packets

Handling IDONTWANT

Use a map to remember the message ids whose IDONTWANT packets have been received
Implement max_idontwant_messages (ignore the IDONWANT packets if the max is reached)
Clear the message IDs from the cache after 3 heartbeats

    Hash the message IDs before putting them into the cache.

More requested features

    Add a feature test to not send IDONTWANT if the other side doesnt support it

### Commit Summary

* Replace sending channel with the smart rpcQueue

Since we want to implement a priority queue later, we need to replace
the normal sending channels with the new smart structures first.

* Implement UrgentPush in the smart rpcQueue

UrgentPush allows you to push an rpc packet to the front of the queue so
that it will be popped out fast.

* Add IDONTWANT to rpc.proto and trace.proto

* Send IDONTWANT right before validation step

Most importantly, this commit adds a new method called PreValidation to
the interface PubSubRouter, which will be called right before validating
the gossipsub message.

In GossipSubRouter, PreValidation will send the IDONTWANT controll
messages to all the mesh peers of the topics of the received messages.

* Test GossipSub IDONWANT sending

* Send IDONWANT only for large messages

* Handle IDONTWANT control messages

When receiving IDONTWANTs, the host should remember the message ids
contained in IDONTWANTs using a hash map.

When receiving messages with those ids, it shouldn't forward them to the
peers who already sent the IDONTWANTs.

When the maximum number of IDONTWANTs is reached for any particular
peer, the host should ignore any excessive IDONTWANTs from that peer.

* Clear expired message IDs from the IDONTWANT cache

If the messages IDs received from IDONTWANTs are older than 3
heartbeats, they should be removed from the IDONTWANT cache.

* Keep the hashes of IDONTWANT message ids instead

Rather than keeping the raw message ids, keep their hashes instead to
save memory and protect again memory DoS attacks.

* Increase GossipSubMaxIHaveMessages to 1000

* fixup! Clear expired message IDs from the IDONTWANT cache

* Not send IDONTWANT if the receiver doesn't support

* fixup! Replace sending channel with the smart rpcQueue

* Not use pointers in rpcQueue

* Simply rcpQueue by using only one mutex

* Check ctx error in rpc sending worker

Co-authored-by: Steven Allen <steven@stebalien.com>

* fixup! Simply rcpQueue by using only one mutex

* fixup! Keep the hashes of IDONTWANT message ids instead

* Use AfterFunc instead implementing our own

* Fix misc lint errors

* fixup! Fix misc lint errors

* Revert "Increase GossipSubMaxIHaveMessages to 1000"

This reverts commit 6fabcdd068a5f5238c5280a3460af9c3998418ec.

* Increase GossipSubMaxIDontWantMessages to 1000

* fixup! Handle IDONTWANT control messages

* Skip TestGossipsubConnTagMessageDeliveries

* Skip FuzzAppendOrMergeRPC

* Revert "Skip FuzzAppendOrMergeRPC"

This reverts commit f141e13234de0960d139339acb636a1afea9e219.

* fixup! Send IDONWANT only for large messages

* fixup! fixup! Keep the hashes of IDONTWANT message ids instead

* fixup! Implement UrgentPush in the smart rpcQueue

* fixup! Use AfterFunc instead implementing our own

---------

Co-authored-by: Steven Allen <steven@stebalien.com>
2024-08-16 18:16:35 +03:00
Sorin Stanculeanu
e508d8643d
added missing Close call on the AddrBook member of GossipSubRouter (#568) 2024-07-11 18:25:52 +03:00
Mikel Cortes
8e498e9e96
Missing flood protection check for number of message IDs when handling Ihave messages (#560)
* check msgIDs in Ihave per topic

* remove coments as suggested
2024-06-27 12:00:36 +03:00
Marco Munizaga
dbd1c9eade
Fix: Own our CertifiedAddrBook (#555)
* Subscribe to libp2p events to maintain our own Certified Address Book

* Update go version

* Use TestGossipsubStarTopology test instead of new test

* Don't return an error in manageAddrBook

* Return on error while subscribing

* Use null resource manager so that the new IP limit doesn't break tests

* Mod tidy
2024-05-20 17:13:30 -07:00
Hlib Kanunnikov
7038c82c21
chores: bump go-libp2p (#558) 2024-05-20 16:20:16 -07:00
Marco Munizaga
c0a528ee7b
Replace fragmentRPC with appendOrMergeRPC (#557)
This will allow us to add more logic around when we split/merge
messages. It will also allow us to build the outgoing rpcs as we go
rather than building one giant rpc and then splitting it.
2024-05-02 09:40:54 -07:00
Sukun
d13e24ddc9
remove usage of deprecated peerid.Pretty method (#542) 2023-09-14 11:11:11 +03:00
Yahya Hassanzadeh
1e161006c4
Enables injectable GossipSub router (#503)
* adds with gossipsub tracker

* renames and add godoc
2022-11-02 06:53:50 +02:00
Marten Seemann
4f56e8f0a7
update go-libp2p to v0.22.0 (#498)
* update go-libp2p to v0.22.0

* skip TestGossipsubConnTagMessageDeliveries
2022-08-26 02:45:41 -07:00
Marco Munizaga
68cdae031b
Gossipsub: Unsubscribe backoff (#488)
* Implement Unsusbcribe backoff

* Add test to check that prune backoff time is used

* Update which backoff to use in TestGossibSubJoinTopic test

* Fix race in TestGossipSubLeaveTopic

* Wait for all the backoff checks, and check that we aren't missing too many

* Remove open question
2022-06-03 06:46:56 +03:00
protolambda
566fdfa6fc fix unused GossipSubHistoryGossip, make seenMessages ttl configurable, make score params SeenMsgTTL configurable 2022-05-24 22:20:42 +03:00
nisdas
aeb30a2ac1 Add in Backoff Check 2022-02-08 09:20:54 +02:00
nisdas
e02b3472aa Modify comment 2022-02-07 14:09:18 +02:00
nisdas
3d93f5f991 Add Backoff For Pruned Peers 2022-02-07 14:09:18 +02:00
Wondertan
0e687f24a6 feat: integrate msgIdGenerator 2022-01-23 09:29:32 +02:00
Simon Zhu
628353661b Create peer filter option 2021-09-21 13:50:09 +03:00
vyzo
0c7092d1f5 make slowness a warning, with a user configurable threshold 2021-07-30 23:10:03 +03:00
vyzo
257d133a07 reduce log spam from empty heartbeat messages 2021-07-30 23:10:03 +03:00
Ian Davis
2efd313b83
cleanup: fix vet and staticcheck failures (#435)
* cleanup: fix vet failures and most staticcheck failures

* Fix remaining staticcheck failures

* Give test goroutines chance to exit early when context is canceled
2021-07-22 15:27:32 -07:00
Steven Allen
0094708cc4
Refactor Gossipsub Parameters To Make Them More Configurable (#421)
Co-authored-by: nisdas <nishdas93@gmail.com>
2021-05-03 08:59:15 -07:00
vyzo
0e387d79fb add support for custom gossipsub protocols and feature tests 2021-04-02 21:55:10 +03:00
vyzo
e6eff445d4
Ignore transient connections (#412) 2021-04-01 21:45:09 +01:00
vyzo
5457a2845b expose internalTracer as RawTracer 2021-03-16 08:28:02 +02:00
vyzo
d6c20b59fc remove multi-topic message support 2020-10-08 20:18:21 +03:00
nisdas
309d45acef copy string topic 2020-09-10 12:39:04 +03:00
vyzo
2bc51e0cf2 peer gater scaffolding 2020-09-07 13:38:02 +03:00
vyzo
3b92bdc1e9 rich router acceptance semantics
Allows us to ignore payload messages when the validation queue is under strain
2020-09-07 13:38:02 +03:00
vyzo
06a12f17b7 reduce log verbosity; debug mostly 2020-09-01 20:42:50 +03:00
vyzo
3a81c24073 don't add direct peers to fanout 2020-08-10 21:00:00 +03:00
Raúl Kripalani
a86ae585a6 reference spec change in comment. 2020-08-10 15:18:25 +03:00
vyzo
46536eccc4 fix backoff slack time 2020-08-10 15:18:25 +03:00
vyzo
8c08ebaecb use the heartbeat interval for slack time 2020-08-10 15:18:25 +03:00
vyzo
f2c25c2228 add slack time to prune backoff clearance 2020-08-10 15:18:25 +03:00
vyzo
8945f91465 only do PX on leave if PX was enabled in the node 2020-06-15 10:30:58 +03:00
Alan Shaw
c0712c6e92 feat: add direct connect ticks option
In [drand](https://github.com/drand/drand) we have a gossipsub relay to allow users to subscribe to getting random values over pubsub. We want to support pure gossip relays who relay from a relay. For this we need direct peering agreements and want to mitigate the possibility of "missing" randomness messages by ensuring the direct connect ticks period is less than the period between updates.

This PR simply adds a new functional option allowing us to set the direct connect ticks value without modifying the global variable.
2020-05-27 16:26:41 +03:00
vyzo
9a1171a0ef fix outbound constraint satisfaction in oversubscription pruning 2020-05-26 20:41:53 +03:00
Yusef Napora
bac68a1ba3 add doc comment for GossipSubDout 2020-05-20 18:48:28 +03:00
Yusef Napora
c041642546 add note about opp. graft threshold 2020-05-20 18:48:28 +03:00
Yusef Napora
22403baadd stop using term "gossip mesh" 2020-05-20 18:48:28 +03:00
Yusef Napora
3dab80fdd5 add doc comments to gossipsub constants 2020-05-20 18:48:28 +03:00
Yusef Napora
9c730661bc add delivery tags for "near-first" msg deliveries 2020-05-19 19:26:53 +03:00
Yusef Napora
28d17a4cab add tagTracer to apply connmgr tags 2020-05-19 19:26:53 +03:00
vyzo
31c9b219f4 use the proto we already have in AddPeer to determine whether the connection houses the stream 2020-05-18 23:20:38 +03:00