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

Merge branch 'release' of gitlab.com:elixxir/client into XX-3103/ShareMessageFix

parents 6d4dfda1 434ab85d
No related branches found
No related tags found
No related merge requests found
...@@ -485,6 +485,26 @@ func (c *Client) GetNetworkInterface() interfaces.NetworkManager { ...@@ -485,6 +485,26 @@ func (c *Client) GetNetworkInterface() interfaces.NetworkManager {
return c.network return c.network
} }
// GetNodeRegistrationStatus gets the current status of node registration. It
// returns the number of nodes that the client is registered and the number of
// in progress node registrations. An error is returned if the network is not
// healthy.
func (c *Client) GetNodeRegistrationStatus() (int, int, error) {
// Return an error if the network is not healthy
if !c.GetHealth().IsHealthy() {
return 0, 0, errors.New("Cannot get number of node registrations when " +
"network is not healthy")
}
// Get the number of nodes that client is registered with
registeredNodes := c.storage.Cmix().Count()
// Get the number of in progress node registrations
inProgress := c.network.InProgressRegistrations()
return registeredNodes, inProgress, nil
}
// ----- Utility Functions ----- // ----- Utility Functions -----
// parseNDF parses the initial ndf string for the client. do not check the // parseNDF parses the initial ndf string for the client. do not check the
// signature, it is deprecated. // signature, it is deprecated.
......
...@@ -115,3 +115,7 @@ func (t *testNetworkManagerGeneric) GetRemoteVersion() (string, error) { ...@@ -115,3 +115,7 @@ func (t *testNetworkManagerGeneric) GetRemoteVersion() (string, error) {
func (t *testNetworkManagerGeneric) GetStoppable() stoppable.Stoppable { func (t *testNetworkManagerGeneric) GetStoppable() stoppable.Stoppable {
return &stoppable.Multi{} return &stoppable.Multi{}
} }
func (t *testNetworkManagerGeneric) InProgressRegistrations() int {
return 0
}
...@@ -338,6 +338,14 @@ func (c *Client) GetUser() *User { ...@@ -338,6 +338,14 @@ func (c *Client) GetUser() *User {
return &User{u: &u} return &User{u: &u}
} }
// GetNodeRegistrationStatus returns a struct with the number of nodes the
// client is registered with and the number of in progress registrations.
func (c *Client) GetNodeRegistrationStatus() (*NodeRegistrationsStatus, error) {
registered, inProgress, err := c.api.GetNodeRegistrationStatus()
return &NodeRegistrationsStatus{registered, inProgress}, err
}
/* /*
// SearchWithHandler is a non-blocking search that also registers // SearchWithHandler is a non-blocking search that also registers
// a callback interface for user disovery events. // a callback interface for user disovery events.
......
///////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
///////////////////////////////////////////////////////////////////////////////
package bindings
// NodeRegistrationsStatus structure for returning node registration statuses
// for bindings.
type NodeRegistrationsStatus struct {
registered int
inProgress int
}
// GetRegistered returns the number of nodes registered with the client.
func (nrs *NodeRegistrationsStatus) GetRegistered() int {
return nrs.registered
}
// GetInProgress return the number of nodes currently registering.
func (nrs *NodeRegistrationsStatus) GetInProgress() int {
return nrs.inProgress
}
...@@ -26,6 +26,7 @@ type NetworkManager interface { ...@@ -26,6 +26,7 @@ type NetworkManager interface {
GetHealthTracker() HealthTracker GetHealthTracker() HealthTracker
Follow() (stoppable.Stoppable, error) Follow() (stoppable.Stoppable, error)
CheckGarbledMessages() CheckGarbledMessages()
InProgressRegistrations() int
} }
//for use in key exchange which needs to be callable inside of network //for use in key exchange which needs to be callable inside of network
......
...@@ -99,6 +99,10 @@ func (t *testNetworkManagerGeneric) GetStoppable() stoppable.Stoppable { ...@@ -99,6 +99,10 @@ func (t *testNetworkManagerGeneric) GetStoppable() stoppable.Stoppable {
return &stoppable.Multi{} return &stoppable.Multi{}
} }
func (t *testNetworkManagerGeneric) InProgressRegistrations() int {
return 0
}
func InitTestingContextGeneric(i interface{}) (*storage.Session, interfaces.NetworkManager) { func InitTestingContextGeneric(i interface{}) (*storage.Session, interfaces.NetworkManager) {
switch i.(type) { switch i.(type) {
case *testing.T, *testing.M, *testing.B, *testing.PB: case *testing.T, *testing.M, *testing.B, *testing.PB:
...@@ -202,6 +206,10 @@ func (t *testNetworkManagerFullExchange) GetStoppable() stoppable.Stoppable { ...@@ -202,6 +206,10 @@ func (t *testNetworkManagerFullExchange) GetStoppable() stoppable.Stoppable {
return &stoppable.Multi{} return &stoppable.Multi{}
} }
func (t *testNetworkManagerFullExchange) InProgressRegistrations() int {
return 0
}
func InitTestingContextFullExchange(i interface{}) (*storage.Session, *switchboard.Switchboard, interfaces.NetworkManager) { func InitTestingContextFullExchange(i interface{}) (*storage.Session, *switchboard.Switchboard, interfaces.NetworkManager) {
switch i.(type) { switch i.(type) {
case *testing.T, *testing.M, *testing.B, *testing.PB: case *testing.T, *testing.M, *testing.B, *testing.PB:
......
...@@ -74,6 +74,10 @@ func (t *testNetworkManager) Follow() (stoppable.Stoppable, error) { ...@@ -74,6 +74,10 @@ func (t *testNetworkManager) Follow() (stoppable.Stoppable, error) {
func (t *testNetworkManager) CheckGarbledMessages() {} func (t *testNetworkManager) CheckGarbledMessages() {}
func (t *testNetworkManager) InProgressRegistrations() int {
return 0
}
func NewTestNetworkManager(i interface{}) interfaces.NetworkManager { func NewTestNetworkManager(i interface{}) interfaces.NetworkManager {
switch i.(type) { switch i.(type) {
case *testing.T, *testing.M, *testing.B: case *testing.T, *testing.M, *testing.B:
......
...@@ -167,3 +167,8 @@ func (m *manager) GetInstance() *network.Instance { ...@@ -167,3 +167,8 @@ func (m *manager) GetInstance() *network.Instance {
func (m *manager) CheckGarbledMessages() { func (m *manager) CheckGarbledMessages() {
m.message.CheckGarbledMessages() m.message.CheckGarbledMessages()
} }
// InProgressRegistrations returns the number of in progress node registrations.
func (m *manager) InProgressRegistrations() int {
return len(m.Internal.NodeRegistration) + 1
}
...@@ -318,6 +318,10 @@ func (tnm *testNetworkManager) Follow() (stoppable.Stoppable, error) { ...@@ -318,6 +318,10 @@ func (tnm *testNetworkManager) Follow() (stoppable.Stoppable, error) {
func (tnm *testNetworkManager) CheckGarbledMessages() {} func (tnm *testNetworkManager) CheckGarbledMessages() {}
func (tnm *testNetworkManager) InProgressRegistrations() int {
return 0
}
func getNDF() *ndf.NetworkDefinition { func getNDF() *ndf.NetworkDefinition {
return &ndf.NetworkDefinition{ return &ndf.NetworkDefinition{
E2E: ndf.Group{ E2E: ndf.Group{
......
...@@ -185,6 +185,13 @@ func (s *Store) IsRegistered(nid *id.ID) bool { ...@@ -185,6 +185,13 @@ func (s *Store) IsRegistered(nid *id.ID) bool {
return ok return ok
} }
// Count returns the number of registered nodes.
func (s *Store) Count() int {
s.mux.RLock()
defer s.mux.RUnlock()
return len(s.nodes)
}
// save stores the cMix store. // save stores the cMix store.
func (s *Store) save() error { func (s *Store) save() error {
now := time.Now() now := time.Now()
......
...@@ -160,7 +160,33 @@ func TestStore_GetRoundKeys_Missing(t *testing.T) { ...@@ -160,7 +160,33 @@ func TestStore_GetRoundKeys_Missing(t *testing.T) {
} }
} }
// Main testing function // Happy path.
func TestStore_Count(t *testing.T) {
vkv := versioned.NewKV(make(ekv.Memstore))
grp := cyclic.NewGroup(large.NewInt(173), large.NewInt(2))
store, err := NewStore(grp, vkv, grp.NewInt(2))
if err != nil {
t.Fatalf("Failed to generate new Store: %+v", err)
}
if store.Count() != 0 {
t.Errorf("Count() did not return the expected value for a new Store."+
"\nexpected: %d\nreceived: %d", 0, store.Count())
}
count := 50
for i := 0; i < count; i++ {
store.Add(id.NewIdFromUInt(uint64(i), id.Node, t), grp.NewInt(int64(42+i)))
}
if store.Count() != count {
t.Errorf("Count() did not return the expected value."+
"\nexpected: %d\nreceived: %d", count, store.Count())
}
}
// Main testing function.
func makeTestStore() (*Store, *versioned.KV) { func makeTestStore() (*Store, *versioned.KV) {
kv := make(ekv.Memstore) kv := make(ekv.Memstore)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment