go-libp2p-pubsub/pb/trace.proto
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

156 lines
3.1 KiB
Protocol Buffer

syntax = "proto2";
package pubsub.pb;
message TraceEvent {
optional Type type = 1;
optional bytes peerID = 2;
optional int64 timestamp = 3;
optional PublishMessage publishMessage = 4;
optional RejectMessage rejectMessage = 5;
optional DuplicateMessage duplicateMessage = 6;
optional DeliverMessage deliverMessage = 7;
optional AddPeer addPeer = 8;
optional RemovePeer removePeer = 9;
optional RecvRPC recvRPC = 10;
optional SendRPC sendRPC = 11;
optional DropRPC dropRPC = 12;
optional Join join = 13;
optional Leave leave = 14;
optional Graft graft = 15;
optional Prune prune = 16;
enum Type {
PUBLISH_MESSAGE = 0;
REJECT_MESSAGE = 1;
DUPLICATE_MESSAGE = 2;
DELIVER_MESSAGE = 3;
ADD_PEER = 4;
REMOVE_PEER = 5;
RECV_RPC = 6;
SEND_RPC = 7;
DROP_RPC = 8;
JOIN = 9;
LEAVE = 10;
GRAFT = 11;
PRUNE = 12;
}
message PublishMessage {
optional bytes messageID = 1;
optional string topic = 2;
}
message RejectMessage {
optional bytes messageID = 1;
optional bytes receivedFrom = 2;
optional string reason = 3;
optional string topic = 4;
}
message DuplicateMessage {
optional bytes messageID = 1;
optional bytes receivedFrom = 2;
optional string topic = 3;
}
message DeliverMessage {
optional bytes messageID = 1;
optional string topic = 2;
optional bytes receivedFrom = 3;
}
message AddPeer {
optional bytes peerID = 1;
optional string proto = 2;
}
message RemovePeer {
optional bytes peerID = 1;
}
message RecvRPC {
optional bytes receivedFrom = 1;
optional RPCMeta meta = 2;
}
message SendRPC {
optional bytes sendTo = 1;
optional RPCMeta meta = 2;
}
message DropRPC {
optional bytes sendTo = 1;
optional RPCMeta meta = 2;
}
message Join {
optional string topic = 1;
}
message Leave {
optional string topic = 2;
}
message Graft {
optional bytes peerID = 1;
optional string topic = 2;
}
message Prune {
optional bytes peerID = 1;
optional string topic = 2;
}
message RPCMeta {
repeated MessageMeta messages = 1;
repeated SubMeta subscription = 2;
optional ControlMeta control = 3;
}
message MessageMeta {
optional bytes messageID = 1;
optional string topic = 2;
}
message SubMeta {
optional bool subscribe = 1;
optional string topic = 2;
}
message ControlMeta {
repeated ControlIHaveMeta ihave = 1;
repeated ControlIWantMeta iwant = 2;
repeated ControlGraftMeta graft = 3;
repeated ControlPruneMeta prune = 4;
repeated ControlIDontWantMeta idontwant = 5;
}
message ControlIHaveMeta {
optional string topic = 1;
repeated bytes messageIDs = 2;
}
message ControlIWantMeta {
repeated bytes messageIDs = 1;
}
message ControlGraftMeta {
optional string topic = 1;
}
message ControlPruneMeta {
optional string topic = 1;
repeated bytes peers = 2;
}
message ControlIDontWantMeta {
repeated bytes messageIDs = 1;
}
}
message TraceEventBatch {
repeated TraceEvent batch = 1;
}