Merge pull request #1199 from cfromknecht/queue-msg-err-chans

peer/server: Remove Broadcast err chans
This commit is contained in:
Olaoluwa Osuntokun
2018-05-10 16:55:57 -07:00
committed by GitHub
2 changed files with 20 additions and 9 deletions

View File

@@ -1092,7 +1092,7 @@ func (s *server) SendToPeer(target *btcec.PublicKey,
case err := <-errChan:
return err
case <-targetPeer.quit:
return fmt.Errorf("peer shutting down")
return ErrPeerExiting
case <-s.quit:
return ErrServerShuttingDown
}
@@ -1184,7 +1184,8 @@ func (s *server) sendPeerMessages(
// event, we defer a call to Done on both WaitGroups to 1) ensure that
// server will be able to shutdown after its go routines exit, and 2)
// so the server can return to the caller of BroadcastMessage.
if wg != nil {
isBroadcast := wg != nil
if isBroadcast {
defer s.wg.Done()
defer wg.Done()
}
@@ -1194,9 +1195,16 @@ func (s *server) sendPeerMessages(
// the queue.
var errChans []chan error
for _, msg := range msgs {
errChan := make(chan error, 1)
// If this is not broadcast, create error channels to provide
// synchronous feedback regarding the delivery of the message to
// a specific peer.
var errChan chan error
if !isBroadcast {
errChan = make(chan error, 1)
errChans = append(errChans, errChan)
}
targetPeer.queueMsg(msg, errChan)
errChans = append(errChans, errChan)
}
return errChans