Commit 96bea099 authored by David Stainton's avatar David Stainton

Simplify error handling, fatal errors are fatal

parent 84643d1a
Pipeline #970 failed with stage
in 10 minutes and 51 seconds
......@@ -34,31 +34,38 @@ const roundTripTimeSlop = time.Duration(88 * time.Second)
var ReplyTimeoutError = errors.New("Failure waiting for reply, timeout reached")
func (s *Session) sendNext() error {
func (s *Session) sendNext() {
msg, err := s.egressQueue.Peek()
if err != nil {
return err
err := errors.New("Impossible failure to Peek from queue")
s.log.Error(err.Error())
s.fatalErrCh <- err
return
}
if msg == nil {
return errors.New("send next failure, message is nil")
err := errors.New("Impossible failure, got nil message from queue")
s.log.Error(err.Error())
s.fatalErrCh <- err
return
}
m, ok := msg.(*Message)
if !ok {
return errors.New("send next failure, unknown message type")
}
err = s.doSend(m)
m := msg.(*Message)
s.doSend(m)
_, err = s.egressQueue.Pop()
if err != nil {
return err
err := errors.New("Impossible failure to Pop from queue")
s.log.Error(err.Error())
s.fatalErrCh <- err
}
_, err = s.egressQueue.Pop()
return err
}
func (s *Session) doSend(msg *Message) error {
func (s *Session) doSend(msg *Message) {
surbID := [sConstants.SURBIDLength]byte{}
_, err := io.ReadFull(rand.Reader, surbID[:])
if err != nil {
return err
err := fmt.Errorf("Impossible failure, failed to generate SURB ID for message ID %x", *msg.ID)
s.log.Error(err.Error())
s.fatalErrCh <- err
return
}
idStr := fmt.Sprintf("[%v]", hex.EncodeToString(surbID[:]))
s.log.Debugf("doSend with SURB ID %x", idStr)
......@@ -69,9 +76,6 @@ func (s *Session) doSend(msg *Message) error {
} else {
err = s.minclient.SendUnreliableCiphertext(msg.Recipient, msg.Provider, msg.Payload)
}
if err != nil {
return err
}
if msg.WithSURB {
s.log.Debugf("doSend setting ReplyETA to %v", eta)
msg.Key = key
......@@ -86,30 +90,36 @@ func (s *Session) doSend(msg *Message) error {
err := fmt.Errorf("Impossible failure, sentWaitChan not found for message ID %x", *msg.ID)
s.log.Error(err.Error())
s.fatalErrCh <- err
return
}
sentWaitChan := sentWaitChanRaw.(chan *Message)
sentWaitChan <- msg
} else {
s.eventCh.In() <- &MessageSentEvent{
MessageID: msg.ID,
Err: nil, // XXX send error
Err: err,
}
}
return nil
}
func (s *Session) sendLoopDecoy() error {
func (s *Session) sendLoopDecoy() {
s.log.Info("sending loop decoy")
const loopService = "loop"
serviceDesc, err := s.GetService(loopService)
if err != nil {
return err
err := errors.New("failure to get loop service")
s.log.Error(err.Error())
s.fatalErrCh <- err
return
}
payload := [constants.UserForwardPayloadLength]byte{}
id := [cConstants.MessageIDLength]byte{}
_, err = io.ReadFull(rand.Reader, id[:])
if err != nil {
return err
err := errors.New("failure to generate message ID for loop decoy")
s.log.Error(err.Error())
s.fatalErrCh <- err
return
}
msg := &Message{
ID: &id,
......@@ -120,7 +130,7 @@ func (s *Session) sendLoopDecoy() error {
IsDecoy: true,
}
defer s.incrementDecoyLoopTally()
return s.doSend(msg)
s.doSend(msg)
}
func (s *Session) composeMessage(recipient, provider string, message []byte, isBlocking bool) (*Message, error) {
......
......@@ -134,10 +134,7 @@ func (s *Session) worker() {
}
if lambdaLFired {
if isConnected && !s.cfg.Debug.DisableDecoyTraffic {
err := s.sendLoopDecoy()
if err != nil {
s.log.Error(err.Error())
}
s.sendLoopDecoy()
}
}
if qo != nil {
......@@ -172,16 +169,10 @@ func (s *Session) sendFromQueueOrDecoy() {
// Otherwise send a drop decoy message.
_, err := s.egressQueue.Peek()
if err == nil {
err := s.sendNext()
if err != nil {
panic(err)
}
s.sendNext()
} else {
if !s.cfg.Debug.DisableDecoyTraffic {
err = s.sendLoopDecoy()
if err != nil {
s.log.Warningf("Failed to send loop decoy traffic: %v", err)
}
s.sendLoopDecoy()
}
}
}
......
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