Commit 7005603e authored by David Stainton's avatar David Stainton

Handle disconnects properly

parent 5e4c580a
Pipeline #980 failed with stage
in 10 minutes and 56 seconds
......@@ -92,17 +92,29 @@ func TestDockerClientAsyncSendReceive(t *testing.T) {
require.NoError(err)
t.Logf("sent message ID %x", msgID)
eventRaw := <-clientSession.EventSink
event1 := eventRaw.(*session.MessageSentEvent)
require.Equal(msgID[:], event1.MessageID[:])
t.Logf("received event: %s", event1)
eventRaw = <-clientSession.EventSink
event2 := eventRaw.(*session.MessageReplyEvent)
t.Logf("received event: %s", event2)
require.Equal(msgID[:], event2.MessageID[:])
require.True(utils.CtIsZero(event2.Payload))
require.NoError(event2.Err)
var wg sync.WaitGroup
wg.Add(2)
go func() {
for eventRaw := range clientSession.EventSink {
switch event := eventRaw.(type) {
case *session.MessageSentEvent:
if bytes.Equal(msgID[:], event.MessageID[:]) {
require.NoError(event.Err)
wg.Done()
}
case *session.MessageReplyEvent:
if bytes.Equal(msgID[:], event.MessageID[:]) {
require.NoError(event.Err)
require.True(utils.CtIsZero(event.Payload))
wg.Done()
return
}
default:
continue
}
}
}()
wg.Wait()
}
func TestDockerClientAsyncSendReceiveWithDecoyTraffic(t *testing.T) {
......@@ -143,6 +155,8 @@ func TestDockerClientAsyncSendReceiveWithDecoyTraffic(t *testing.T) {
wg.Done()
return
}
default:
continue
}
}
}()
......
......@@ -56,9 +56,16 @@ func (t *Fount) DescriptorEquals(s *Descriptor) bool {
return t.desc.Equals(s)
}
// SetPoisson sets a new Poisson descriptor.
// SetPoisson sets a new Poisson descriptor if the
// descriptor is different than the one we have set already.
func (t *Fount) SetPoisson(desc *Descriptor) {
t.desc = desc
if !t.DescriptorEquals(desc) {
if !t.Timer.Stop() {
<-t.Timer.C
}
t.desc = desc
t.Next()
}
}
func (t *Fount) nextInterval() time.Duration {
......@@ -86,6 +93,9 @@ func (t *Fount) Next() {
// NextMax resets the timer to the maximum
// possible value.
func (t *Fount) NextMax() {
if !t.Timer.Stop() {
<-t.Timer.C
}
t.Timer.Reset(math.MaxInt64)
}
......
// event.go - mixnet client session events
// events.go - mixnet client session events
// Copyright (C) 2018, 2019 Yawning Angel and David Stainton.
//
// This program is free software: you can redistribute it and/or modify
......
......@@ -200,12 +200,17 @@ func (s *Session) GetService(serviceName string) (*utils.ServiceDescriptor, erro
}
// OnConnection will be called by the minclient api
// upon connecting to the Provider
// upon connection change status to the Provider
func (s *Session) onConnection(err error) {
if err == nil {
s.opCh <- opConnStatusChanged{
isConnected: true,
}
s.log.Debugf("onConnection %v", err)
s.eventCh.In() <- &ConnectionStatusEvent{
IsConnected: err == nil,
Err: err,
}
s.opCh <- opConnStatusChanged{
isConnected: err == nil,
}
}
......
// worker.go - mixnet client worker
// Copyright (C) 2018 David Stainton.
// Copyright (C) 2018, 2019 David Stainton.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
......@@ -94,8 +94,9 @@ func (s *Session) maybeUpdateTimers(doc *pki.Document) {
// Determine if PKI doc is valid. If not then abort.
err := s.isDocValid(doc)
if err != nil {
s.log.Errorf("Aborting, PKI doc is not valid for the Loopix decoy traffic use case: %v", err)
s.fatalErrCh <- fmt.Errorf("Aborting, PKI doc is not valid for the Loopix decoy traffic use case: %v", err)
err := fmt.Errorf("Aborting, PKI doc is not valid for the Loopix decoy traffic use case: %v", err)
s.log.Error(err.Error())
s.fatalErrCh <- err
return
}
s.setTimers(doc)
......@@ -151,14 +152,17 @@ func (s *Session) worker() {
s.log.Warningf("BUG: Worker received nonsensical op: %T", op)
} // end of switch
}
if lambdaPFired {
s.pTimer.Next()
}
if lambdaLFired {
s.lTimer.Next()
if isConnected {
if lambdaPFired {
s.pTimer.Next()
}
if lambdaLFired {
s.lTimer.Next()
}
} else {
s.pTimer.NextMax()
s.lTimer.NextMax()
}
}
// NOTREACHED
......
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