Skip to content
Snippets Groups Projects
Commit 1fb4f73e authored by Richard T. Carback III's avatar Richard T. Carback III
Browse files

Update connect to get rid of it's local parameters and use the xxdk E2E Params

parent 1c471aeb
No related branches found
No related tags found
2 merge requests!510Release,!253General Cleanup
......@@ -8,6 +8,9 @@
package connect
import (
"sync"
"time"
"github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/catalog"
......@@ -19,8 +22,6 @@ import (
"gitlab.com/xx_network/crypto/signature/rsa"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/netTime"
"sync"
"time"
)
// Constant error messages
......@@ -52,7 +53,7 @@ type AuthenticatedCallback func(connection AuthenticatedConnection)
// connection with the server. Once a connect.Connection has been established
// with the server and then authenticate their identity to the server.
func ConnectWithAuthentication(recipient contact.Contact, e2eClient *xxdk.E2e,
p Params) (AuthenticatedConnection, error) {
p xxdk.E2EParams) (AuthenticatedConnection, error) {
// Track the time since we started to attempt to establish a connection
timeStart := netTime.Now()
......@@ -76,7 +77,7 @@ func ConnectWithAuthentication(recipient contact.Contact, e2eClient *xxdk.E2e,
func connectWithAuthentication(conn Connection, timeStart time.Time,
recipient contact.Contact, salt []byte, myRsaPrivKey *rsa.PrivateKey,
rng *fastRNG.StreamGenerator,
net cmix.Client, p Params) (AuthenticatedConnection, error) {
net cmix.Client, p xxdk.E2EParams) (AuthenticatedConnection, error) {
// Construct message to prove your identity to the server
payload, err := buildClientAuthRequest(conn.GetPartner(), rng,
myRsaPrivKey, salt)
......@@ -129,7 +130,7 @@ func connectWithAuthentication(conn Connection, timeStart time.Time,
})
// Find the remaining time in the timeout since we first sent the message
remainingTime := p.Timeout - netTime.Since(timeStart)
remainingTime := p.Base.Timeout - netTime.Since(timeStart)
// Track the result of the round(s) we sent the
// identity authentication message on
......@@ -170,7 +171,8 @@ func connectWithAuthentication(conn Connection, timeStart time.Time,
// authenticate themselves. An established AuthenticatedConnection will
// be passed via the callback.
func StartAuthenticatedServer(identity xxdk.ReceptionIdentity,
cb AuthenticatedCallback, net *xxdk.Cmix, p Params) (*xxdk.E2e, error) {
cb AuthenticatedCallback, net *xxdk.Cmix, p xxdk.E2EParams) (*xxdk.E2e,
error) {
// Register the waiter for a connection establishment
connCb := Callback(func(connection Connection) {
......
......@@ -8,6 +8,11 @@
package connect
import (
"math/rand"
"testing"
"time"
"gitlab.com/elixxir/client/xxdk"
"gitlab.com/elixxir/crypto/contact"
"gitlab.com/elixxir/crypto/diffieHellman"
"gitlab.com/elixxir/crypto/fastRNG"
......@@ -15,9 +20,6 @@ import (
"gitlab.com/xx_network/crypto/signature/rsa"
"gitlab.com/xx_network/crypto/xx"
"gitlab.com/xx_network/primitives/id"
"math/rand"
"testing"
"time"
)
// TestConnectWithAuthentication will test the client/server relationship for
......@@ -77,8 +79,8 @@ func TestConnectWithAuthentication(t *testing.T) {
})
// Initialize params with a shorter timeout to hasten test results
customParams := GetDefaultParams()
customParams.Timeout = 3 * time.Second
customParams := xxdk.GetDefaultE2EParams()
customParams.Base.Timeout = 3 * time.Second
// Initialize the server
serverHandler := buildAuthConfirmationHandler(serverCb, mockConn)
......@@ -96,7 +98,7 @@ func TestConnectWithAuthentication(t *testing.T) {
}
// Wait for the server to establish it's connection via the callback
timeout := time.NewTimer(customParams.Timeout)
timeout := time.NewTimer(customParams.Base.Timeout)
select {
case <-authConnChan:
return
......
......@@ -7,7 +7,6 @@
package connect
import (
"encoding/json"
"io"
"time"
......@@ -22,8 +21,6 @@ import (
clientE2e "gitlab.com/elixxir/client/e2e"
"gitlab.com/elixxir/client/e2e/ratchet/partner"
"gitlab.com/elixxir/client/e2e/receive"
"gitlab.com/elixxir/client/e2e/rekey"
"gitlab.com/elixxir/client/event"
"gitlab.com/elixxir/crypto/contact"
"gitlab.com/elixxir/crypto/e2e"
"gitlab.com/xx_network/primitives/id"
......@@ -80,43 +77,12 @@ type Connection interface {
// new Connection objects as they are established.
type Callback func(connection Connection)
// Params for managing Connection objects.
type Params struct {
Auth auth.Params
Rekey rekey.Params
Event event.Reporter `json:"-"`
Timeout time.Duration
}
// GetDefaultParams returns a usable set of default Connection parameters.
func GetDefaultParams() Params {
return Params{
Auth: auth.GetDefaultTemporaryParams(),
Rekey: rekey.GetDefaultEphemeralParams(),
Event: event.NewEventManager(),
Timeout: connectionTimeout,
}
}
// GetParameters returns the default Params, or override with given
// parameters, if set.
func GetParameters(params string) (Params, error) {
p := GetDefaultParams()
if len(params) > 0 {
err := json.Unmarshal([]byte(params), &p)
if err != nil {
return Params{}, err
}
}
return p, nil
}
// Connect performs auth key negotiation with the given recipient,
// and returns a Connection object for the newly-created partner.Manager
// This function is to be used sender-side and will block until the
// partner.Manager is confirmed.
func Connect(recipient contact.Contact, e2eClient *xxdk.E2e,
p Params) (Connection, error) {
p xxdk.E2EParams) (Connection, error) {
// Build callback for E2E negotiation
signalChannel := make(chan Connection, 1)
......@@ -136,7 +102,7 @@ func Connect(recipient contact.Contact, e2eClient *xxdk.E2e,
// Block waiting for auth to confirm
jww.DEBUG.Printf("Connection waiting for auth request "+
"for %s to be confirmed...", recipient.ID.String())
timeout := time.NewTimer(p.Timeout)
timeout := time.NewTimer(p.Base.Timeout)
defer timeout.Stop()
select {
case newConnection := <-signalChannel:
......@@ -163,12 +129,12 @@ func Connect(recipient contact.Contact, e2eClient *xxdk.E2e,
// This call does an xxDK.ephemeralLogin under the hood and the connection
// server must be the only listener on auth.
func StartServer(identity xxdk.ReceptionIdentity, cb Callback, net *xxdk.Cmix,
p Params) (*xxdk.E2e, error) {
p xxdk.E2EParams) (*xxdk.E2e, error) {
// Build callback for E2E negotiation
callback := getAuthCallback(nil, cb, nil, nil, p)
client, err := xxdk.LoginEphemeral(net, callback, identity)
client, err := xxdk.LoginEphemeral(net, callback, identity, p)
if err != nil {
return nil, err
}
......@@ -183,14 +149,14 @@ type handler struct {
auth auth.State
partner partner.Manager
e2e clientE2e.Handler
params Params
params xxdk.E2EParams
}
// BuildConnection assembles a Connection object
// after an E2E partnership has already been confirmed with the given
// partner.Manager.
func BuildConnection(partner partner.Manager, e2eHandler clientE2e.Handler,
auth auth.State, p Params) Connection {
auth auth.State, p xxdk.E2EParams) Connection {
return &handler{
auth: auth,
partner: partner,
......@@ -244,7 +210,7 @@ type authCallback struct {
// Used for building new Connection objects
connectionE2e clientE2e.Handler
connectionParams Params
connectionParams xxdk.E2EParams
authState auth.State
}
......@@ -252,7 +218,7 @@ type authCallback struct {
// of an auth.State object.
// it will accept requests only if a request callback is passed in
func getAuthCallback(confirm, request Callback, e2e clientE2e.Handler,
auth auth.State, params Params) *authCallback {
auth auth.State, params xxdk.E2EParams) *authCallback {
return &authCallback{
confirmCallback: confirm,
requestCallback: request,
......
......@@ -11,11 +11,13 @@ import (
"bytes"
"encoding/json"
"testing"
"gitlab.com/elixxir/client/xxdk"
)
func TestParams_MarshalUnmarshal(t *testing.T) {
// Construct a set of params
p := GetDefaultParams()
p := xxdk.GetDefaultE2EParams()
// Marshal the params
data, err := json.Marshal(&p)
......@@ -26,7 +28,7 @@ func TestParams_MarshalUnmarshal(t *testing.T) {
t.Logf("%s", string(data))
// Unmarshal the params object
received := Params{}
received := xxdk.E2EParams{}
err = json.Unmarshal(data, &received)
if err != nil {
t.Fatalf("Unmarshal error: %v", err)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment