PEX: integrate with send throttling
This commit is contained in:
parent
3d87c20766
commit
26071eaad0
|
@ -564,7 +564,9 @@ func (cn *PeerConn) fillWriteBuffer(msg func(pp.Message) bool) {
|
||||||
cn.requestsLowWater = len(cn.requests) / 2
|
cn.requestsLowWater = len(cn.requests) / 2
|
||||||
}
|
}
|
||||||
if cn.pex.IsEnabled() {
|
if cn.pex.IsEnabled() {
|
||||||
cn.pex.Share(msg) // gated internally
|
if flow := cn.pex.Share(msg); !flow {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
cn.upload(msg)
|
cn.upload(msg)
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,20 +68,22 @@ func (s *pexConnState) genmsg() *pp.PexMsg {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Share is called from the writer goroutine if when it is woken up with the write buffers empty
|
// Share is called from the writer goroutine if when it is woken up with the write buffers empty
|
||||||
func (s *pexConnState) Share(postfn messageWriter) {
|
// Returns whether there's more room on the send buffer to write to.
|
||||||
|
func (s *pexConnState) Share(postfn messageWriter) bool {
|
||||||
select {
|
select {
|
||||||
case <-s.gate:
|
case <-s.gate:
|
||||||
if tx := s.genmsg(); tx != nil {
|
if tx := s.genmsg(); tx != nil {
|
||||||
s.dbg.Print("sending PEX message: ", tx)
|
s.dbg.Print("sending PEX message: ", tx)
|
||||||
postfn(tx.Message(s.xid))
|
flow := postfn(tx.Message(s.xid))
|
||||||
s.sched(pexInterval)
|
s.sched(pexInterval)
|
||||||
|
return flow
|
||||||
} else {
|
} else {
|
||||||
// no PEX to send this time - try again shortly
|
// no PEX to send this time - try again shortly
|
||||||
s.sched(pexRetryDelay)
|
s.sched(pexRetryDelay)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recv is called from the reader goroutine
|
// Recv is called from the reader goroutine
|
||||||
|
|
Loading…
Reference in New Issue