Skip to content
Snippets Groups Projects
Commit 1cfbcaba authored by Jono Wenger's avatar Jono Wenger Committed by Benjamin Wenger
Browse files

Add InProgressRegistrations to the network manager, which returns the number...

Add InProgressRegistrations to the network manager, which returns the number of in progress node registrations
parent eb3f085a
No related branches found
No related tags found
No related merge requests found
......@@ -485,6 +485,26 @@ func (c *Client) GetNetworkInterface() interfaces.NetworkManager {
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 -----
// parseNDF parses the initial ndf string for the client. do not check the
// signature, it is deprecated.
......
......@@ -115,3 +115,7 @@ func (t *testNetworkManagerGeneric) GetRemoteVersion() (string, error) {
func (t *testNetworkManagerGeneric) GetStoppable() stoppable.Stoppable {
return &stoppable.Multi{}
}
func (t *testNetworkManagerGeneric) InProgressRegistrations() int {
return 0
}
......@@ -338,6 +338,14 @@ func (c *Client) GetUser() *User {
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
// 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 {
GetHealthTracker() HealthTracker
Follow() (stoppable.Stoppable, error)
CheckGarbledMessages()
InProgressRegistrations() int
}
//for use in key exchange which needs to be callable inside of network
......
......@@ -99,6 +99,10 @@ func (t *testNetworkManagerGeneric) GetStoppable() stoppable.Stoppable {
return &stoppable.Multi{}
}
func (t *testNetworkManagerGeneric) InProgressRegistrations() int {
return 0
}
func InitTestingContextGeneric(i interface{}) (*storage.Session, interfaces.NetworkManager) {
switch i.(type) {
case *testing.T, *testing.M, *testing.B, *testing.PB:
......@@ -202,6 +206,10 @@ func (t *testNetworkManagerFullExchange) GetStoppable() stoppable.Stoppable {
return &stoppable.Multi{}
}
func (t *testNetworkManagerFullExchange) InProgressRegistrations() int {
return 0
}
func InitTestingContextFullExchange(i interface{}) (*storage.Session, *switchboard.Switchboard, interfaces.NetworkManager) {
switch i.(type) {
case *testing.T, *testing.M, *testing.B, *testing.PB:
......
......@@ -74,6 +74,10 @@ func (t *testNetworkManager) Follow() (stoppable.Stoppable, error) {
func (t *testNetworkManager) CheckGarbledMessages() {}
func (t *testNetworkManager) InProgressRegistrations() int {
return 0
}
func NewTestNetworkManager(i interface{}) interfaces.NetworkManager {
switch i.(type) {
case *testing.T, *testing.M, *testing.B:
......
......@@ -167,3 +167,8 @@ func (m *manager) GetInstance() *network.Instance {
func (m *manager) 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) {
func (tnm *testNetworkManager) CheckGarbledMessages() {}
func (tnm *testNetworkManager) InProgressRegistrations() int {
return 0
}
func getNDF() *ndf.NetworkDefinition {
return &ndf.NetworkDefinition{
E2E: ndf.Group{
......
......@@ -185,6 +185,13 @@ func (s *Store) IsRegistered(nid *id.ID) bool {
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.
func (s *Store) save() error {
now := time.Now()
......
......@@ -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) {
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