Skip to content

Commit

Permalink
add support for priority topic delivery weights
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzo committed Sep 7, 2020
1 parent 40762e1 commit a3445b7
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion peer_gater.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ type PeerGaterParams struct {
IgnoreWeight float64
// weight of rejected messages
RejectWeight float64

// priority topic delivery weights
TopicDeliveryWeights map[string]float64
}

func (p *PeerGaterParams) validate() error {
Expand Down Expand Up @@ -84,6 +87,12 @@ func (p *PeerGaterParams) validate() error {
return nil
}

// WithTopicDeliveryWeights is a fluid setter for the priority topic delivery weights
func (p *PeerGaterParams) WithTopicDeliveryWeights(w map[string]float64) *PeerGaterParams {
p.TopicDeliveryWeights = w
return p
}

// NewPeerGaterParams creates a new PeerGaterParams struct, using the specified threshold and decay
// parameters and default values for all other parameters.
func NewPeerGaterParams(threshold, globalDecay, sourceDecay float64) *PeerGaterParams {
Expand Down Expand Up @@ -386,7 +395,17 @@ func (pg *peerGater) DeliverMessage(msg *Message) {
defer pg.Unlock()

st := pg.getPeerStats(msg.ReceivedFrom)
st.deliver++

weight := 0.0
for _, topic := range msg.GetTopicIDs() {
weight += pg.params.TopicDeliveryWeights[topic]
}

if weight == 0 {
weight = 1
}

st.deliver += weight
}

func (pg *peerGater) RejectMessage(msg *Message, reason string) {
Expand Down

0 comments on commit a3445b7

Please sign in to comment.