protect direct and mesh peers in the connection manager

This commit is contained in:
vyzo 2020-06-03 21:45:17 +03:00
parent c0712c6e92
commit df04b05234
1 changed files with 3 additions and 13 deletions

View File

@ -11,16 +11,6 @@ import (
)
var (
// GossipSubConnTagValueDirectPeer is the connection manager tag value to
// apply to direct peers. This should be high, as we want to prioritize these
// connections above all others.
GossipSubConnTagValueDirectPeer = 1000
// GossipSubConnTagValueMeshPeer is the connection manager tag value to apply to
// peers in a topic mesh. If a peer is in the mesh for multiple topics, their
// connection will be tagged separately for each.
GossipSubConnTagValueMeshPeer = 20
// GossipSubConnTagBumpMessageDelivery is the amount to add to the connection manager
// tag that tracks message deliveries. Each time a peer is the first to deliver a
// message within a topic, we "bump" a tag by this amount, up to a maximum
@ -96,18 +86,18 @@ func (t *tagTracer) tagPeerIfDirect(p peer.ID) {
// tag peer if it is a direct peer
_, direct := t.direct[p]
if direct {
t.cmgr.TagPeer(p, "pubsub:direct", GossipSubConnTagValueDirectPeer)
t.cmgr.Protect(p, "pubsub:<direct>")
}
}
func (t *tagTracer) tagMeshPeer(p peer.ID, topic string) {
tag := topicTag(topic)
t.cmgr.TagPeer(p, tag, GossipSubConnTagValueMeshPeer)
t.cmgr.Protect(p, tag)
}
func (t *tagTracer) untagMeshPeer(p peer.ID, topic string) {
tag := topicTag(topic)
t.cmgr.UntagPeer(p, tag)
t.cmgr.Unprotect(p, tag)
}
func topicTag(topic string) string {