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

Merge branch 'Optimus/ClientStorage' into XX-2418/ClientStorage-Registration

parents 2b985629 8e4adcd3
Branches
No related tags found
No related merge requests found
...@@ -27,3 +27,8 @@ localdev_* ...@@ -27,3 +27,8 @@ localdev_*
*.class *.class
*.aar *.aar
*.jar *.jar
# Ignore test output related to ekv
.ekv*
.*test*
*.1
*.2
...@@ -24,12 +24,14 @@ update_release: ...@@ -24,12 +24,14 @@ update_release:
GOFLAGS="" go get -u gitlab.com/elixxir/crypto@release GOFLAGS="" go get -u gitlab.com/elixxir/crypto@release
GOFLAGS="" go get -u gitlab.com/elixxir/comms@release GOFLAGS="" go get -u gitlab.com/elixxir/comms@release
GOFLAGS="" go get -u gitlab.com/xx_network/comms@release GOFLAGS="" go get -u gitlab.com/xx_network/comms@release
GOFLAGS="" go get -u gitlab.com/xx_network/primitives@release
update_master: update_master:
GOFLAGS="" go get -u gitlab.com/elixxir/primitives@master GOFLAGS="" go get -u gitlab.com/elixxir/primitives@master
GOFLAGS="" go get -u gitlab.com/elixxir/crypto@master GOFLAGS="" go get -u gitlab.com/elixxir/crypto@master
GOFLAGS="" go get -u gitlab.com/elixxir/comms@master GOFLAGS="" go get -u gitlab.com/elixxir/comms@master
GOFLAGS="" go get -u gitlab.com/xx_network/comms@master GOFLAGS="" go get -u gitlab.com/xx_network/comms@master
GOFLAGS="" go get -u gitlab.com/xx_network/primitives@master
master: clean update_master build version master: clean update_master build version
......
...@@ -28,10 +28,10 @@ import ( ...@@ -28,10 +28,10 @@ import (
"gitlab.com/elixxir/crypto/large" "gitlab.com/elixxir/crypto/large"
"gitlab.com/elixxir/crypto/signature/rsa" "gitlab.com/elixxir/crypto/signature/rsa"
"gitlab.com/elixxir/crypto/tls" "gitlab.com/elixxir/crypto/tls"
"gitlab.com/elixxir/primitives/id"
"gitlab.com/elixxir/primitives/ndf"
"gitlab.com/elixxir/primitives/switchboard" "gitlab.com/elixxir/primitives/switchboard"
"gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/comms/connect"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/ndf"
goio "io" goio "io"
"path/filepath" "path/filepath"
"strings" "strings"
...@@ -446,30 +446,28 @@ type SearchCallback interface { ...@@ -446,30 +446,28 @@ type SearchCallback interface {
func (cl *Client) SearchForUser(emailAddress string, func (cl *Client) SearchForUser(emailAddress string,
cb SearchCallback, timeout time.Duration) { cb SearchCallback, timeout time.Duration) {
//see if the user has been searched before, if it has, return it //see if the user has been searched before, if it has, return it
uid, pk := cl.session.GetContactByValue(emailAddress) contact, err := cl.sessionV2.GetContact(emailAddress)
if uid != nil { // if we successfully got the contact, return it.
cb.Callback(uid.Bytes(), pk, nil) // errors can include the email address not existing,
// so errors from the GetContact call are ignored
if contact != nil && err == nil {
cb.Callback(contact.Id.Bytes(), contact.PublicKey, nil)
return
} }
valueType := "EMAIL" valueType := "EMAIL"
go func() { go func() {
uid, pubKey, err := bots.Search(valueType, emailAddress, cl.opStatus, timeout) contact, err := bots.Search(valueType, emailAddress, cl.opStatus, timeout)
if err == nil && uid != nil && pubKey != nil { if err == nil && contact.Id != nil && contact.PublicKey != nil {
cl.opStatus(globals.UDB_SEARCH_BUILD_CREDS) cl.opStatus(globals.UDB_SEARCH_BUILD_CREDS)
err = cl.registerUserE2E(uid, pubKey) err = cl.registerUserE2E(contact)
if err != nil { if err != nil {
cb.Callback(uid[:], pubKey, err) cb.Callback(contact.Id.Bytes(), contact.PublicKey, err)
return return
} }
//store the user so future lookups can find it //store the user so future lookups can find it
cl.session.StoreContactByValue(emailAddress, uid, pubKey) err = cl.sessionV2.SetContact(emailAddress, contact)
err = cl.session.StoreSession()
if err != nil {
cb.Callback(uid[:], pubKey, err)
return
}
// If there is something in the channel then send it; otherwise, // If there is something in the channel then send it; otherwise,
// skip over it // skip over it
...@@ -478,7 +476,7 @@ func (cl *Client) SearchForUser(emailAddress string, ...@@ -478,7 +476,7 @@ func (cl *Client) SearchForUser(emailAddress string,
default: default:
} }
cb.Callback(uid[:], pubKey, err) cb.Callback(contact.Id.Bytes(), contact.PublicKey, err)
} else { } else {
if err == nil { if err == nil {
......
...@@ -13,6 +13,7 @@ import ( ...@@ -13,6 +13,7 @@ import (
"gitlab.com/elixxir/client/io" "gitlab.com/elixxir/client/io"
"gitlab.com/elixxir/client/keyStore" "gitlab.com/elixxir/client/keyStore"
"gitlab.com/elixxir/client/parse" "gitlab.com/elixxir/client/parse"
"gitlab.com/elixxir/client/storage"
"gitlab.com/elixxir/client/user" "gitlab.com/elixxir/client/user"
"gitlab.com/elixxir/crypto/csprng" "gitlab.com/elixxir/crypto/csprng"
"gitlab.com/elixxir/crypto/cyclic" "gitlab.com/elixxir/crypto/cyclic"
...@@ -22,7 +23,7 @@ import ( ...@@ -22,7 +23,7 @@ import (
"gitlab.com/elixxir/crypto/large" "gitlab.com/elixxir/crypto/large"
"gitlab.com/elixxir/crypto/signature/rsa" "gitlab.com/elixxir/crypto/signature/rsa"
"gitlab.com/elixxir/primitives/format" "gitlab.com/elixxir/primitives/format"
"gitlab.com/elixxir/primitives/id" "gitlab.com/xx_network/primitives/id"
"reflect" "reflect"
"testing" "testing"
"time" "time"
...@@ -177,7 +178,13 @@ func TestRegisterUserE2E(t *testing.T) { ...@@ -177,7 +178,13 @@ func TestRegisterUserE2E(t *testing.T) {
testClient.session = session testClient.session = session
testClient.registerUserE2E(partner, partnerPubKeyCyclic.Bytes()) err = testClient.registerUserE2E(&storage.Contact{
Id: partner,
PublicKey: partnerPubKeyCyclic.Bytes(),
})
if err != nil {
t.Fatal(err)
}
// Confirm we can get all types of keys // Confirm we can get all types of keys
km := session.GetKeyStore().GetSendManager(partner) km := session.GetKeyStore().GetSendManager(partner)
...@@ -243,7 +250,7 @@ func TestRegisterUserE2E(t *testing.T) { ...@@ -243,7 +250,7 @@ func TestRegisterUserE2E(t *testing.T) {
func TestRegisterUserE2E_CheckAllKeys(t *testing.T) { func TestRegisterUserE2E_CheckAllKeys(t *testing.T) {
testClient, err := NewClient(&globals.RamStorage{}, ".ekv-testrege2e-allkeys", "", def) testClient, err := NewClient(&globals.RamStorage{}, ".ekv-testrege2e-allkeys", "", def)
if err != nil { if err != nil {
t.Error(err) t.Fatal(err)
} }
cmixGrp, e2eGrp := getGroups() cmixGrp, e2eGrp := getGroups()
...@@ -268,7 +275,13 @@ func TestRegisterUserE2E_CheckAllKeys(t *testing.T) { ...@@ -268,7 +275,13 @@ func TestRegisterUserE2E_CheckAllKeys(t *testing.T) {
testClient.session = session testClient.session = session
testClient.registerUserE2E(partner, partnerPubKeyCyclic.Bytes()) err = testClient.registerUserE2E(&storage.Contact{
Id: partner,
PublicKey: partnerPubKeyCyclic.Bytes(),
})
if err != nil {
t.Fatal(err)
}
// Generate all keys and confirm they all match // Generate all keys and confirm they all match
keyParams := testClient.GetKeyParams() keyParams := testClient.GetKeyParams()
...@@ -712,8 +725,8 @@ func TestClient_LogoutTimeout(t *testing.T) { ...@@ -712,8 +725,8 @@ func TestClient_LogoutTimeout(t *testing.T) {
// Test that if we logout we can logback in. // Test that if we logout we can logback in.
func TestClient_LogoutAndLoginAgain(t *testing.T) { func TestClient_LogoutAndLoginAgain(t *testing.T) {
//Initialize a client //Initialize a client
storage := &DummyStorage{LocationA: ".ekv-logoutlogin", StoreA: []byte{'a', 'b', 'c'}} dummyStorage := &DummyStorage{LocationA: ".ekv-logoutlogin", StoreA: []byte{'a', 'b', 'c'}}
tc, err := NewClient(storage, ".ekv-logoutlogin", "", def) tc, err := NewClient(dummyStorage, ".ekv-logoutlogin", "", def)
if err != nil { if err != nil {
t.Errorf("Failed to create new client: %+v", err) t.Errorf("Failed to create new client: %+v", err)
} }
...@@ -750,7 +763,7 @@ func TestClient_LogoutAndLoginAgain(t *testing.T) { ...@@ -750,7 +763,7 @@ func TestClient_LogoutAndLoginAgain(t *testing.T) {
} }
//Redefine client with old session files and attempt to login. //Redefine client with old session files and attempt to login.
tc, err = NewClient(storage, ".ekv-logoutlogin", "", def) tc, err = NewClient(dummyStorage, ".ekv-logoutlogin", "", def)
if err != nil { if err != nil {
t.Errorf("Failed second client initialization: %+v", err) t.Errorf("Failed second client initialization: %+v", err)
} }
......
...@@ -11,10 +11,10 @@ import ( ...@@ -11,10 +11,10 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"gitlab.com/elixxir/client/globals" "gitlab.com/elixxir/client/globals"
"gitlab.com/elixxir/client/io" "gitlab.com/elixxir/client/io"
"gitlab.com/elixxir/primitives/id"
"gitlab.com/elixxir/primitives/ndf"
"gitlab.com/elixxir/primitives/version" "gitlab.com/elixxir/primitives/version"
"gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/comms/connect"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/ndf"
) )
var ErrNoPermissioning = errors.New("No Permissioning In NDF") var ErrNoPermissioning = errors.New("No Permissioning In NDF")
......
...@@ -19,10 +19,10 @@ import ( ...@@ -19,10 +19,10 @@ import (
"gitlab.com/elixxir/crypto/e2e" "gitlab.com/elixxir/crypto/e2e"
"gitlab.com/elixxir/crypto/large" "gitlab.com/elixxir/crypto/large"
"gitlab.com/elixxir/primitives/format" "gitlab.com/elixxir/primitives/format"
"gitlab.com/elixxir/primitives/id"
"gitlab.com/elixxir/primitives/ndf"
"gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/comms/connect"
"gitlab.com/xx_network/comms/messages" "gitlab.com/xx_network/comms/messages"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/ndf"
"sync" "sync"
"time" "time"
) )
......
...@@ -17,9 +17,9 @@ import ( ...@@ -17,9 +17,9 @@ import (
pb "gitlab.com/elixxir/comms/mixmessages" pb "gitlab.com/elixxir/comms/mixmessages"
"gitlab.com/elixxir/comms/notificationBot" "gitlab.com/elixxir/comms/notificationBot"
"gitlab.com/elixxir/comms/registration" "gitlab.com/elixxir/comms/registration"
"gitlab.com/elixxir/primitives/id"
"gitlab.com/elixxir/primitives/ndf"
"gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/comms/connect"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/ndf"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
......
...@@ -12,7 +12,7 @@ import ( ...@@ -12,7 +12,7 @@ import (
"encoding/base64" "encoding/base64"
"fmt" "fmt"
"gitlab.com/elixxir/crypto/signature/rsa" "gitlab.com/elixxir/crypto/signature/rsa"
"gitlab.com/elixxir/primitives/ndf" "gitlab.com/xx_network/primitives/ndf"
"reflect" "reflect"
"testing" "testing"
) )
......
...@@ -3,7 +3,7 @@ package api ...@@ -3,7 +3,7 @@ package api
import ( import (
"github.com/pkg/errors" "github.com/pkg/errors"
"gitlab.com/elixxir/comms/mixmessages" "gitlab.com/elixxir/comms/mixmessages"
"gitlab.com/elixxir/primitives/id" "gitlab.com/xx_network/primitives/id"
) )
// RegisterForNotifications sends a message to notification bot indicating it // RegisterForNotifications sends a message to notification bot indicating it
......
...@@ -13,6 +13,7 @@ import ( ...@@ -13,6 +13,7 @@ import (
"gitlab.com/elixxir/client/globals" "gitlab.com/elixxir/client/globals"
"gitlab.com/elixxir/client/io" "gitlab.com/elixxir/client/io"
"gitlab.com/elixxir/client/keyStore" "gitlab.com/elixxir/client/keyStore"
"gitlab.com/elixxir/client/storage"
"gitlab.com/elixxir/client/user" "gitlab.com/elixxir/client/user"
pb "gitlab.com/elixxir/comms/mixmessages" pb "gitlab.com/elixxir/comms/mixmessages"
"gitlab.com/elixxir/crypto/csprng" "gitlab.com/elixxir/crypto/csprng"
...@@ -22,9 +23,9 @@ import ( ...@@ -22,9 +23,9 @@ import (
"gitlab.com/elixxir/crypto/large" "gitlab.com/elixxir/crypto/large"
"gitlab.com/elixxir/crypto/signature/rsa" "gitlab.com/elixxir/crypto/signature/rsa"
"gitlab.com/elixxir/crypto/xx" "gitlab.com/elixxir/crypto/xx"
"gitlab.com/elixxir/primitives/id"
"gitlab.com/elixxir/primitives/ndf"
"gitlab.com/xx_network/comms/messages" "gitlab.com/xx_network/comms/messages"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/ndf"
) )
const PermissioningAddrID = "Permissioning" const PermissioningAddrID = "Permissioning"
...@@ -208,16 +209,15 @@ func (cl *Client) confirmNonce(UID, nonce []byte, ...@@ -208,16 +209,15 @@ func (cl *Client) confirmNonce(UID, nonce []byte,
return nil return nil
} }
func (cl *Client) registerUserE2E(partnerID *id.ID, func (cl *Client) registerUserE2E(partner *storage.Contact) error {
partnerPubKey []byte) error {
// Check that the returned user is valid // Check that the returned user is valid
if partnerKeyStore := cl.session.GetKeyStore().GetSendManager(partnerID); partnerKeyStore != nil { if partnerKeyStore := cl.session.GetKeyStore().GetSendManager(partner.Id); partnerKeyStore != nil {
return errors.New(fmt.Sprintf("UDB searched failed for %v because user has "+ return errors.New(fmt.Sprintf("UDB searched failed for %v because user has "+
"been searched for before", partnerID)) "been searched for before", partner.Id))
} }
if cl.session.GetCurrentUser().User.Cmp(partnerID) { if cl.session.GetCurrentUser().User.Cmp(partner.Id) {
return errors.New("cannot search for yourself on UDB") return errors.New("cannot search for yourself on UDB")
} }
...@@ -228,11 +228,11 @@ func (cl *Client) registerUserE2E(partnerID *id.ID, ...@@ -228,11 +228,11 @@ func (cl *Client) registerUserE2E(partnerID *id.ID,
// Create user private key and partner public key // Create user private key and partner public key
// in the group // in the group
privKeyCyclic := cl.session.GetE2EDHPrivateKey() privKeyCyclic := cl.session.GetE2EDHPrivateKey()
partnerPubKeyCyclic := grp.NewIntFromBytes(partnerPubKey) publicKeyCyclic := grp.NewIntFromBytes(partner.PublicKey)
// Generate baseKey // Generate baseKey
baseKey, _ := diffieHellman.CreateDHSessionKey( baseKey, _ := diffieHellman.CreateDHSessionKey(
partnerPubKeyCyclic, publicKeyCyclic,
privKeyCyclic, privKeyCyclic,
grp) grp)
...@@ -243,7 +243,7 @@ func (cl *Client) registerUserE2E(partnerID *id.ID, ...@@ -243,7 +243,7 @@ func (cl *Client) registerUserE2E(partnerID *id.ID,
// Create Send KeyManager // Create Send KeyManager
km := keyStore.NewManager(baseKey, privKeyCyclic, km := keyStore.NewManager(baseKey, privKeyCyclic,
partnerPubKeyCyclic, partnerID, true, publicKeyCyclic, partner.Id, true,
numKeys, keysTTL, params.NumRekeys) numKeys, keysTTL, params.NumRekeys)
// Generate Send Keys // Generate Send Keys
...@@ -252,7 +252,7 @@ func (cl *Client) registerUserE2E(partnerID *id.ID, ...@@ -252,7 +252,7 @@ func (cl *Client) registerUserE2E(partnerID *id.ID,
// Create Receive KeyManager // Create Receive KeyManager
km = keyStore.NewManager(baseKey, privKeyCyclic, km = keyStore.NewManager(baseKey, privKeyCyclic,
partnerPubKeyCyclic, partnerID, false, publicKeyCyclic, partner.Id, false,
numKeys, keysTTL, params.NumRekeys) numKeys, keysTTL, params.NumRekeys)
// Generate Receive Keys // Generate Receive Keys
...@@ -265,10 +265,10 @@ func (cl *Client) registerUserE2E(partnerID *id.ID, ...@@ -265,10 +265,10 @@ func (cl *Client) registerUserE2E(partnerID *id.ID,
keys := &keyStore.RekeyKeys{ keys := &keyStore.RekeyKeys{
CurrPrivKey: privKeyCyclic, CurrPrivKey: privKeyCyclic,
CurrPubKey: partnerPubKeyCyclic, CurrPubKey: publicKeyCyclic,
} }
rkm.AddKeys(partnerID, keys) rkm.AddKeys(partner.Id, keys)
return nil return nil
} }
......
...@@ -19,8 +19,8 @@ import ( ...@@ -19,8 +19,8 @@ import (
"gitlab.com/elixxir/crypto/registration" "gitlab.com/elixxir/crypto/registration"
"gitlab.com/elixxir/crypto/signature/rsa" "gitlab.com/elixxir/crypto/signature/rsa"
"gitlab.com/elixxir/crypto/tls" "gitlab.com/elixxir/crypto/tls"
"gitlab.com/elixxir/primitives/id" "gitlab.com/xx_network/primitives/id"
"gitlab.com/elixxir/primitives/ndf" "gitlab.com/xx_network/primitives/ndf"
"sync" "sync"
"time" "time"
) )
......
...@@ -9,8 +9,8 @@ import ( ...@@ -9,8 +9,8 @@ import (
"crypto/sha256" "crypto/sha256"
"gitlab.com/elixxir/client/globals" "gitlab.com/elixxir/client/globals"
"gitlab.com/elixxir/client/user" "gitlab.com/elixxir/client/user"
"gitlab.com/elixxir/primitives/id"
"gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/comms/connect"
"gitlab.com/xx_network/primitives/id"
"testing" "testing"
) )
......
...@@ -14,7 +14,7 @@ import ( ...@@ -14,7 +14,7 @@ import (
"gitlab.com/elixxir/client/globals" "gitlab.com/elixxir/client/globals"
"gitlab.com/elixxir/client/parse" "gitlab.com/elixxir/client/parse"
"gitlab.com/elixxir/crypto/csprng" "gitlab.com/elixxir/crypto/csprng"
"gitlab.com/elixxir/primitives/id" "gitlab.com/xx_network/primitives/id"
"io" "io"
"math/big" "math/big"
"strings" "strings"
......
...@@ -25,10 +25,10 @@ import ( ...@@ -25,10 +25,10 @@ import (
"gitlab.com/elixxir/crypto/cyclic" "gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/large" "gitlab.com/elixxir/crypto/large"
"gitlab.com/elixxir/crypto/signature/rsa" "gitlab.com/elixxir/crypto/signature/rsa"
"gitlab.com/elixxir/primitives/id"
"gitlab.com/elixxir/primitives/ndf"
"gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/comms/connect"
"gitlab.com/xx_network/comms/messages" "gitlab.com/xx_network/comms/messages"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/ndf"
"math/rand" "math/rand"
"os" "os"
"reflect" "reflect"
......
...@@ -6,9 +6,9 @@ import ( ...@@ -6,9 +6,9 @@ import (
"gitlab.com/elixxir/client/io" "gitlab.com/elixxir/client/io"
"gitlab.com/elixxir/client/parse" "gitlab.com/elixxir/client/parse"
"gitlab.com/elixxir/client/user" "gitlab.com/elixxir/client/user"
"gitlab.com/elixxir/primitives/id"
"gitlab.com/elixxir/primitives/switchboard" "gitlab.com/elixxir/primitives/switchboard"
"gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/comms/connect"
"gitlab.com/xx_network/primitives/id"
) )
var session user.Session var session user.Session
......
...@@ -20,8 +20,8 @@ import ( ...@@ -20,8 +20,8 @@ import (
"gitlab.com/elixxir/crypto/cyclic" "gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/large" "gitlab.com/elixxir/crypto/large"
"gitlab.com/elixxir/primitives/format" "gitlab.com/elixxir/primitives/format"
"gitlab.com/elixxir/primitives/id"
"gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/comms/connect"
"gitlab.com/xx_network/primitives/id"
"os" "os"
"strings" "strings"
"testing" "testing"
...@@ -126,11 +126,6 @@ func TestRegister(t *testing.T) { ...@@ -126,11 +126,6 @@ func TestRegister(t *testing.T) {
// TestSearch smoke tests the search function // TestSearch smoke tests the search function
func TestSearch(t *testing.T) { func TestSearch(t *testing.T) {
publicKeyString := base64.StdEncoding.EncodeToString(pubKey) publicKeyString := base64.StdEncoding.EncodeToString(pubKey)
//uid := id.NewIdFromUInt(26, id.User, t)
//serRetUid := base64.StdEncoding.EncodeToString(uid[:])
//result, _ := base64.StdEncoding.DecodeString(serRetUid)
//t.Fatal(serRetUid)
//t.Fatal(len(result))
// Send response messages from fake UDB in advance // Send response messages from fake UDB in advance
searchResponseListener <- "blah@elixxir.io FOUND UR69db14ZyicpZVqJ1HFC5rk9UZ8817aV6+VHmrJpGc= AAAAAAAAABoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD 8oKh7TYG4KxQcBAymoXPBHSD/uga9pX3Mn/jKhvcD8M=" searchResponseListener <- "blah@elixxir.io FOUND UR69db14ZyicpZVqJ1HFC5rk9UZ8817aV6+VHmrJpGc= AAAAAAAAABoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD 8oKh7TYG4KxQcBAymoXPBHSD/uga9pX3Mn/jKhvcD8M="
...@@ -141,16 +136,19 @@ func TestSearch(t *testing.T) { ...@@ -141,16 +136,19 @@ func TestSearch(t *testing.T) {
return return
} }
searchedUser, _, err := Search("EMAIL", "blah@elixxir.io", searchedUser, err := Search("EMAIL", "blah@elixxir.io",
dummySearchState, 30*time.Second) dummySearchState, 30*time.Second)
if err != nil { if err != nil {
t.Errorf("Error on Search: %s", err.Error()) t.Fatalf("Error on Search: %s", err.Error())
} }
if !searchedUser.Cmp(id.NewIdFromUInt(26, id.User, t)) { if !searchedUser.Id.Cmp(id.NewIdFromUInt(26, id.User, t)) {
t.Errorf("Search did not return user ID 26! returned %s", searchedUser) t.Errorf("Search did not return user ID 26! returned %s", searchedUser)
} }
//Test the timeout capabilities //Test the timeout capabilities
searchedUser, _, err = Search("EMAIL", "blah@elixxir.io", dummySearchState, 1*time.Millisecond) searchedUser, err = Search("EMAIL", "blah@elixxir.io", dummySearchState, 1*time.Millisecond)
if err == nil {
t.Fatal("udb search timeout should have caused error")
}
if strings.Compare(err.Error(), "UDB search timeout exceeded on user lookup") != 0 { if strings.Compare(err.Error(), "UDB search timeout exceeded on user lookup") != 0 {
t.Errorf("error: %v", err) t.Errorf("error: %v", err)
} }
......
...@@ -16,8 +16,9 @@ import ( ...@@ -16,8 +16,9 @@ import (
"gitlab.com/elixxir/client/cmixproto" "gitlab.com/elixxir/client/cmixproto"
"gitlab.com/elixxir/client/globals" "gitlab.com/elixxir/client/globals"
"gitlab.com/elixxir/client/parse" "gitlab.com/elixxir/client/parse"
"gitlab.com/elixxir/client/storage"
"gitlab.com/elixxir/crypto/hash" "gitlab.com/elixxir/crypto/hash"
"gitlab.com/elixxir/primitives/id" "gitlab.com/xx_network/primitives/id"
"strings" "strings"
"time" "time"
) )
...@@ -38,7 +39,7 @@ func Register(valueType, value string, publicKey []byte, regStatus func(int), ti ...@@ -38,7 +39,7 @@ func Register(valueType, value string, publicKey []byte, regStatus func(int), ti
if valueType == "EMAIL" { if valueType == "EMAIL" {
value, err = hashAndEncode(strings.ToLower(value)) value, err = hashAndEncode(strings.ToLower(value))
if err != nil { if err != nil {
return fmt.Errorf("Could not hash and encode email %s: %+v", value, err) return fmt.Errorf("could not hash and encode email %s: %+v", value, err)
} }
} }
...@@ -114,7 +115,7 @@ func Register(valueType, value string, publicKey []byte, regStatus func(int), ti ...@@ -114,7 +115,7 @@ func Register(valueType, value string, publicKey []byte, regStatus func(int), ti
// Search returns a userID and public key based on the search criteria // Search returns a userID and public key based on the search criteria
// it accepts a valueType of EMAIL and value of an e-mail address, and // it accepts a valueType of EMAIL and value of an e-mail address, and
// returns a map of userid -> public key // returns a map of userid -> public key
func Search(valueType, value string, searchStatus func(int), timeout time.Duration) (*id.ID, []byte, error) { func Search(valueType, value string, searchStatus func(int), timeout time.Duration) (*storage.Contact, error) {
globals.Log.DEBUG.Printf("Running search for %v, %v", valueType, value) globals.Log.DEBUG.Printf("Running search for %v, %v", valueType, value)
searchTimeout := time.NewTimer(timeout) searchTimeout := time.NewTimer(timeout)
...@@ -123,7 +124,7 @@ func Search(valueType, value string, searchStatus func(int), timeout time.Durati ...@@ -123,7 +124,7 @@ func Search(valueType, value string, searchStatus func(int), timeout time.Durati
if valueType == "EMAIL" { if valueType == "EMAIL" {
value, err = hashAndEncode(strings.ToLower(value)) value, err = hashAndEncode(strings.ToLower(value))
if err != nil { if err != nil {
return nil, nil, fmt.Errorf("Could not hash and encode email %s: %+v", value, err) return nil, fmt.Errorf("could not hash and encode email %s: %+v", value, err)
} }
} }
...@@ -135,7 +136,7 @@ func Search(valueType, value string, searchStatus func(int), timeout time.Durati ...@@ -135,7 +136,7 @@ func Search(valueType, value string, searchStatus func(int), timeout time.Durati
}) })
err = sendCommand(&id.UDB, msgBody) err = sendCommand(&id.UDB, msgBody)
if err != nil { if err != nil {
return nil, nil, err return nil, err
} }
var response string var response string
...@@ -149,20 +150,20 @@ func Search(valueType, value string, searchStatus func(int), timeout time.Durati ...@@ -149,20 +150,20 @@ func Search(valueType, value string, searchStatus func(int), timeout time.Durati
case response = <-searchResponseListener: case response = <-searchResponseListener:
empty := fmt.Sprintf("SEARCH %s NOTFOUND", value) empty := fmt.Sprintf("SEARCH %s NOTFOUND", value)
if response == empty { if response == empty {
return nil, nil, nil return nil, nil
} }
if strings.Contains(response, value) { if strings.Contains(response, value) {
found = true found = true
} }
case <-searchTimeout.C: case <-searchTimeout.C:
return nil, nil, errors.New("UDB search timeout exceeded on user lookup") return nil, errors.New("UDB search timeout exceeded on user lookup")
} }
} }
// While search returns more than 1 result, we only process the first // While search returns more than 1 result, we only process the first
cMixUID, keyFP, err := parseSearch(response) cMixUID, keyFP, err := parseSearch(response)
if err != nil { if err != nil {
return nil, nil, err return nil, err
} }
searchStatus(globals.UDB_SEARCH_GETKEY) searchStatus(globals.UDB_SEARCH_GETKEY)
...@@ -174,7 +175,7 @@ func Search(valueType, value string, searchStatus func(int), timeout time.Durati ...@@ -174,7 +175,7 @@ func Search(valueType, value string, searchStatus func(int), timeout time.Durati
}) })
err = sendCommand(&id.UDB, msgBody) err = sendCommand(&id.UDB, msgBody)
if err != nil { if err != nil {
return nil, nil, err return nil, err
} }
// wait for the response to searching for the key against the timeout. // wait for the response to searching for the key against the timeout.
...@@ -187,13 +188,16 @@ func Search(valueType, value string, searchStatus func(int), timeout time.Durati ...@@ -187,13 +188,16 @@ func Search(valueType, value string, searchStatus func(int), timeout time.Durati
found = true found = true
} }
case <-searchTimeout.C: case <-searchTimeout.C:
return nil, nil, errors.New("UDB search timeout exceeded on key lookup") return nil, errors.New("UDB search timeout exceeded on key lookup")
} }
} }
publicKey := parseGetKey(response) publicKey := parseGetKey(response)
return cMixUID, publicKey, nil return &storage.Contact{
Id: cMixUID,
PublicKey: publicKey,
}, nil
} }
func hashAndEncode(s string) (string, error) { func hashAndEncode(s string) (string, error) {
......
...@@ -22,9 +22,9 @@ import ( ...@@ -22,9 +22,9 @@ import (
"gitlab.com/elixxir/client/parse" "gitlab.com/elixxir/client/parse"
"gitlab.com/elixxir/client/user" "gitlab.com/elixxir/client/user"
"gitlab.com/elixxir/crypto/signature/rsa" "gitlab.com/elixxir/crypto/signature/rsa"
"gitlab.com/elixxir/primitives/id"
"gitlab.com/elixxir/primitives/switchboard" "gitlab.com/elixxir/primitives/switchboard"
"gitlab.com/elixxir/primitives/utils" "gitlab.com/elixxir/primitives/utils"
"gitlab.com/xx_network/primitives/id"
"io/ioutil" "io/ioutil"
"os" "os"
"strconv" "strconv"
......
...@@ -9,7 +9,7 @@ package cmd ...@@ -9,7 +9,7 @@ package cmd
import ( import (
"gitlab.com/elixxir/client/api" "gitlab.com/elixxir/client/api"
"gitlab.com/elixxir/client/globals" "gitlab.com/elixxir/client/globals"
"gitlab.com/elixxir/primitives/id" "gitlab.com/xx_network/primitives/id"
"strings" "strings"
"time" "time"
) )
......
...@@ -16,8 +16,8 @@ import ( ...@@ -16,8 +16,8 @@ import (
"gitlab.com/elixxir/crypto/hash" "gitlab.com/elixxir/crypto/hash"
"gitlab.com/elixxir/crypto/large" "gitlab.com/elixxir/crypto/large"
"gitlab.com/elixxir/primitives/format" "gitlab.com/elixxir/primitives/format"
"gitlab.com/elixxir/primitives/id"
"gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/comms/connect"
"gitlab.com/xx_network/primitives/id"
"golang.org/x/crypto/blake2b" "golang.org/x/crypto/blake2b"
"os" "os"
"testing" "testing"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment