Skip to content
Snippets Groups Projects
Commit 1d25fdae authored by Josh Brooks's avatar Josh Brooks
Browse files

Add timeout to connect/ package

parent b9d73b83
Branches
Tags
3 merge requests!510Release,!216Xx 3895/authenticated connection,!207WIP: Client Restructure
......@@ -30,6 +30,12 @@ import (
"time"
)
const (
// connectionTimeout is the time.Duration for a connection
// to be established before the requester times out.
connectionTimeout = 15 * time.Second
)
// Connection is a wrapper for the E2E and auth packages.
// It can be used to automatically establish an E2E partnership
// with a partner.Manager, or be built from an existing E2E partnership.
......@@ -73,6 +79,7 @@ func GetDefaultParams() Params {
Auth: auth.GetDefaultParams(),
Rekey: rekey.GetDefaultParams(),
Event: event.NewEventManager(),
Timeout: connectionTimeout,
}
}
......@@ -120,8 +127,10 @@ func Connect(recipient contact.Contact, myId *id.ID, privKey *cyclic.Int,
// Block waiting for auth to confirm
jww.DEBUG.Printf("Connection waiting for auth request "+
"for %s to be confirmed...", recipient.ID.String())
newConnection := <-signalChannel
timeout := time.NewTimer(p.Timeout)
defer timeout.Stop()
select {
case newConnection := <-signalChannel:
// Verify the Connection is complete
if newConnection == nil {
return nil, errors.Errorf("Unable to complete connection "+
......@@ -129,8 +138,11 @@ func Connect(recipient contact.Contact, myId *id.ID, privKey *cyclic.Int,
}
jww.DEBUG.Printf("Connection auth request for %s confirmed",
recipient.ID.String())
return newConnection, nil
case <-timeout.C:
return nil, errors.Errorf("Connection request with "+
"partner %s timed out", recipient.ID.String())
}
}
// RegisterConnectionCallback assembles a Connection object on the reception-side
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment