40 Commits

Author SHA1 Message Date
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
Marco Munizaga
3aa9d671ae
fix: Don't bother parsing an empty slice (#556) 2024-05-02 09:41:05 -07:00
Hlib Kanunnikov
76124145d0
improve handling of dead peers (#508) 2022-11-20 13:38:53 +02:00
Hlib Kanunnikov
aed7fc42c1
perf: use pooled buffers for message writes (#507) 2022-11-19 16:59:45 +02:00
Hlib Kanunnikov
9c56b2deca
perf: use msgio pooled buffers for received msgs (#500) 2022-11-19 15:19:10 +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
Yahya Hassanzadeh
06b5ba4763
Adds exponential backoff to re-spawing new streams for supposedly dead peers (#483)
* updates gitignore

* implements draft solution

* consolidates update and get

* extends test

* adds cleaner logic

* removes a redundant else case

* refactors cleanup in a goroutine

* adds a jitter to backoff

* stretches the sleep for cleanup

* reduces jitter time

* fixes a test

* adds maximum backoff attempts

* returns error for closing channel

* refactors peer status exceed backoff threshold

* converts if-else to switch

* nit

* consolidates update and maximum backoff check

* bug fix

* nit

* refactors cleanup with a ticker object
2022-05-30 19:47:08 +03:00
vyzo
e9e5a9913f don't respawn writer if we fail to open a stream; declare it a peer error 2021-07-14 00:43:52 +03:00
vyzo
b289ec5017 batch process dead peer notifications 2021-07-14 00:43:52 +03:00
vyzo
9e129db766 defer stream removal instead of doing it inline. 2021-01-12 17:18:00 +02:00
vyzo
8676a0e25b deduplicate inbound streams 2021-01-12 17:18:00 +02:00
Steven Allen
08c17398fb feat: update to go-libp2p-core 0.7.0
Updates to the new stream interfaces. See
https://github.com/libp2p/go-libp2p-core/releases/tag/v0.7.0.
2020-11-12 09:02:55 +02:00
vyzo
06a12f17b7 reduce log verbosity; debug mostly 2020-09-01 20:42:50 +03:00
Raúl Kripalani
ae55bf9603 upgrade deps + interoperable uvarint delimited writer/reader. 2020-07-30 14:00:54 +03:00
Jeromy
e18b4edd9a drop warning about failure to open stream to a debug log 2020-06-12 23:47:16 +03:00
vyzo
ce9a0b7edf use log.Warn instead of Warning 2020-05-05 21:10:14 +03:00
Lukasz Zimnoch
0d884f3e90 Topic relay discovery
Incorporated relays to
exiting discovery logic
and added them to topic
before-remove guard.
2020-05-01 12:22:22 +03:00
Raúl Kripalani
1f147c2457
make wire protocol message size configurable. (#261) 2020-02-25 18:07:16 -08:00
Adin Schmahmann
5ef7439d71 interface: New Topic + TopicEventHandlers objects.
Added PubSub.Join(topic) that returns a Topic object. This object can be Subscribed and Published to as well as to get a TopicEventHandler for topic events. This means that the Subscription object will no longer handle PeerEvents and that PubSub's Publish and Subscribe functions are deprecated.
2019-10-31 15:37:44 -04:00
Raúl Kripalani
49274b0e8a
migrate to consolidated types. (#185) 2019-05-26 17:19:03 +01:00
vyzo
6d2f8e649c discriminate stream errors from unsupported protocols 2018-12-14 00:33:30 +02:00
vyzo
fc7795c38f simplify peer disconnect detection logic to ensure a single outgoing stream 2018-12-13 22:52:59 +02:00
vyzo
2621f893e6 rework peer tracking logic to handle multiple connections 2018-12-13 19:53:12 +02:00
Steven Allen
bd1a4630b9 move to go-libp2p-pubsub
Updates for move from go-floodsub to go-libp2p-pubsub.

fixes https://github.com/libp2p/go-libp2p-pubsub/issues/4
2018-10-18 21:10:16 +01:00
vyzo
71d32b2f3d fix missing reset on write errors 2018-10-12 12:22:26 +03:00
Kevin Atkinson
0827f5e955 gx publish 0.9.31 2018-10-04 19:23:53 -04:00
Kevin Atkinson
1abb0209ce gx publish 0.9.30 2018-10-04 18:41:48 -04:00
vyzo
a3003697f6 more idiomatic copyRPC 2018-08-28 21:35:00 +03:00
vyzo
73b338aa6d fix nil pointer dereference in copyRPC 2018-08-28 21:17:00 +03:00
vyzo
de4adefafb fix data race in ownership of RPC when piggybacking control messages. 2018-08-28 21:07:18 +03:00
vyzo
6a177a7396 handle gossipsub control messages 2018-06-12 08:00:17 -07:00
Steven Allen
f6afd637b8 make sure to *fully* close streams
We need to wait for the EOF from the other side when closing from the sending
side (unless we've already seen an EOF).
2018-06-05 15:53:25 -07:00
Steven Allen
098f1d5819 demote errors/warnings to info
* dropped/killed connections are not errors.
* handleIncomingRPC/publishMessage do not return errors.
2018-01-26 15:00:47 -08:00
Steven Allen
56ea7752e8 better worker cleanup
1. Don't hang marking a peer as dead if we're shutting down.
2. No need to "drain" the outgoing channel anymore. This may have been necessary
to prevent a deadlock where the main loop blocked on sending on sending a
message while we waited to tell the main loop that the peer was dead. However,
this is no longer an issue (we never block on sending).
2017-10-14 11:19:21 -07:00
Steven Allen
3e0c53e2a7 mark the peer as dead if the inbound stream closes
fixes #38
2017-10-14 09:24:44 -07:00
Steven Allen
238bd82a7f use reset where appropriate
(especially when walking away from read-only streams)
2017-09-15 16:28:46 -07:00
Jeromy
90657d5d53 update dependencies 2016-10-05 12:47:20 -07:00
Jeromy
a16546a7ee move code to libp2p repo 2016-09-12 20:10:48 -07:00
Jeromy
dd331f38c6 more code cleanup, remove debug statements, add support for multiple
messages and topics
2016-09-12 13:22:16 -07:00
Jeromy
ab2fef7c1b refactor publish messaging 2016-09-11 13:56:07 -07:00