Commit f6230f4f authored by Jeromy's avatar Jeromy

Only open a message sender when we have messages to send

License: MIT
Signed-off-by: default avatarJeromy <jeromyj@gmail.com>
parent bf2c4e4e
......@@ -187,15 +187,6 @@ func (mq *msgQueue) runQueue(ctx context.Context) {
}
func (mq *msgQueue) doWork(ctx context.Context) {
if mq.sender == nil {
err := mq.openSender(ctx)
if err != nil {
log.Infof("cant open message sender to peer %s: %s", mq.p, err)
// TODO: cant connect, what now?
return
}
}
// grab outgoing message
mq.outlk.Lock()
wlm := mq.out
......@@ -206,6 +197,16 @@ func (mq *msgQueue) doWork(ctx context.Context) {
mq.out = nil
mq.outlk.Unlock()
// NB: only open a stream if we actually have data to send
if mq.sender == nil {
err := mq.openSender(ctx)
if err != nil {
log.Infof("cant open message sender to peer %s: %s", mq.p, err)
// TODO: cant connect, what now?
return
}
}
// send wantlist updates
for { // try to send this message until we fail.
err := mq.sender.SendMsg(ctx, wlm)
......
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