Commit 29aa7547 authored by Jeromy's avatar Jeromy

same block cant be sent twice to a peer within a certain time period

parent 13ab516c
......@@ -16,7 +16,7 @@ func newLedger(p peer.Peer, strategy strategyFunc) *ledger {
wantList: keySet{},
Strategy: strategy,
Partner: p,
sentToPeer: make(map[u.Key]struct{}),
sentToPeer: make(map[u.Key]time.Time),
}
}
......@@ -43,7 +43,7 @@ type ledger struct {
// sentToPeer is a set of keys to ensure we dont send duplicate blocks
// to a given peer
sentToPeer map[u.Key]struct{}
sentToPeer map[u.Key]time.Time
Strategy strategyFunc
}
......
......@@ -10,6 +10,8 @@ import (
u "github.com/jbenet/go-ipfs/util"
)
const resendTimeoutPeriod = time.Minute
var log = u.Logger("strategy")
// TODO niceness should be on a per-peer basis. Use-case: Certain peers are
......@@ -66,8 +68,9 @@ func (s *strategist) ShouldSendBlockToPeer(k u.Key, p peer.Peer) bool {
ledger := s.ledger(p)
// Dont resend blocks
if _, ok := ledger.sentToPeer[k]; ok {
// Dont resend blocks within a certain time period
t, ok := ledger.sentToPeer[k]
if ok && t.Add(resendTimeoutPeriod).After(time.Now()) {
return false
}
......@@ -79,7 +82,7 @@ func (s *strategist) BlockSentToPeer(k u.Key, p peer.Peer) {
defer s.lock.Unlock()
ledger := s.ledger(p)
ledger.sentToPeer[k] = struct{}{}
ledger.sentToPeer[k] = time.Now()
}
func (s *strategist) Seed(int64) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment