78 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
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
vyzo
d6c20b59fc remove multi-topic message support 2020-10-08 20:18:21 +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
Steven Allen
df9592859d
fix: call the correct tracer function in FloodSubRouter.Leave (#373)
fixes #372
2020-08-10 01:31:21 -07:00
vyzo
2ddc4b999f allow gossipsub to graylist peers based on score 2020-04-18 11:09:06 +03:00
vyzo
87bbe69a8b router.Publish doesn't need the source, it takes the whole message now 2020-04-18 11:09:06 +03:00
vyzo
69e4102a6d correctly implement flood publishing
Only applies to messages that have been published by our own peer!
2020-04-18 11:09:06 +03:00
vyzo
958e09a5b3 remove useless nil check when initializing subsystem tracers 2019-11-15 20:42:04 +02:00
vyzo
fd73973145 add tracing to floodsub/randomsub 2019-11-15 20:42:04 +02:00
Adin Schmahmann
f9c26c2e68 Added libp2p discovery capabilities to PubSub.
When the WithDiscovery option is passed to PubSub then PubSub will be able to search for more peers that are interested in our topics.

This includes the ability for Publishes (via Topic.Publish()) to block until the router is ready to publish. When a router is ready is currently defined by a combination of a user defined MinTopicSize function (passed into topic.Publish via the WithReadiness publish option) and the properties of the pubsub router used. The discovery tests show example usage.
2019-10-31 16:39:18 -04:00
Raúl Kripalani
49274b0e8a
migrate to consolidated types. (#185) 2019-05-26 17:19:03 +01:00
vyzo
96c5b40934 godoc cosmetics 2019-01-04 13:14:04 +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
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
8680a79d3a add Join/Leave to PubSubRouter interface
advanced routers will want to know when they are subscribed to a topic as
they may want to send control messages.
2018-06-12 08:00:17 -07:00
Erin Swenson-Healey
75fcbf0c2c New -> NewFloodsubWithProtocols 2018-06-07 09:21:08 -07:00
Erin Swenson-Healey
6840b190db allow FloodSubRouter to be configured with protocols 2018-06-07 09:21:08 -07:00
vyzo
327e72d4fd demote erros per #62 2018-01-27 09:54:57 +02:00
vyzo
e7b1fe6e75 modularized pubsub; Flooding is just a routing method. 2018-01-27 09:54:57 +02: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
c82e67dcd3
Merge pull request #55 from libp2p/feat/validators
Message Validators
2018-01-24 06:03:20 +00:00
vyzo
3f4fc21228 fix comment, subscriptions don't have validators any more. 2018-01-18 20:09:09 +02:00
vyzo
bbdec3fda2 implement per topic validators 2018-01-18 19:12:36 +02:00
Raghav Gulati
99a4f9e5ed Increase timeout in TestSubscribeMultipleTimes
Increase delay to 10ms; makes go test -race happy.
2018-01-16 11:46:33 +02:00
vyzo
fceb00d234 improved comment about global validation throttle 2018-01-14 02:24:13 +02:00
vyzo
145a84a33b use a single channel for all validation results 2018-01-13 22:02:28 +02:00
vyzo
f6081fb061 pushMsg should just call maybePublishMessage when it doesn't need validation 2018-01-13 21:56:57 +02:00
vyzo
473a5d2873 sendMsg should have a buffer 2018-01-13 21:39:35 +02:00
vyzo
edcb251ad1 install global validation throttle, use reasonable defaults. 2018-01-13 21:15:40 +02:00
vyzo
856a25c8eb WithMaxConcurrency is WithValidatorConcurrency
and defaultMaxConcurrency is defaultValidateConcurrency.
2018-01-13 20:56:03 +02:00
vyzo
bf2151ba5f the sendMsg channel should yield pointers for consistency 2018-01-13 20:47:28 +02:00
vyzo
5ef13c764e don't always spawn a goroutine for sending a new message 2018-01-13 20:11:32 +02:00
vyzo
c95ed28496 add validation context for cancelation on aborts 2018-01-13 18:34:00 +02:00
vyzo
fba445bc6d code cosmetics
reword pushMsg for less indentation nesting.
2018-01-13 14:44:33 +02:00
vyzo
982c4de960 per subscription validation throttle and more efficient dispatch logic 2018-01-13 14:31:34 +02:00
vyzo
d2f6a0050f WithValidator and WithValidatorTimeout are subscription options 2018-01-13 12:33:03 +02:00
vyzo
4241241031 fix dangling maxConcurrency reference 2018-01-13 12:24:31 +02:00
keks
88274db0bb make maximum concurrency configurable, split loop 2018-01-13 12:15:27 +02:00
keks
fe09d1eea3 make validator timeout configurable 2018-01-13 12:13:54 +02:00
keks
6e8b9f2d5c fix timeout 2018-01-13 12:13:54 +02:00
keks
02877cda71 complete validator functions
- make validators time out after 100ms
  - add context param to validator functions
  - add type Validator func(context.Context, *Message) bool
- drop message if more than 10 messages are already being validated
2018-01-13 12:13:54 +02:00
keks
197a5982a4 ungxify 2018-01-13 12:12:21 +02:00
keks
7dd4e0bfeb vet
used for range variable inside goroutine, now passed as argument
2018-01-13 12:12:21 +02:00
keks
1945f895a2 log when validator discards message 2018-01-13 12:12:21 +02:00
keks
930f264a27 typedef subscription options and fix typo 2018-01-13 12:12:21 +02:00
keks
647bb98655 optionally allow caller to validate messages 2018-01-13 12:12:21 +02:00
vyzo
95dce910ba narrow the message seqno to 64bit again
Uses the atomic counter initialized at instantiation time, which saves
a few bytes and a syscall per message.
2018-01-03 20:30:28 +02:00
vyzo
8a31b41b4c use atomic counter for message seqnos; timestamp is insufficient 2018-01-03 11:25:20 +02:00