From 00ccdb19956717f2a0ba48063476fd2ee6a1b4b8 Mon Sep 17 00:00:00 2001
From: josh <josh@elixxir.io>
Date: Thu, 5 Mar 2020 13:41:17 -0800
Subject: [PATCH] Add update group function

---
 network/dataStructures/ndf.go      |  2 +-
 network/dataStructures/ndf_test.go |  6 +++---
 network/instance.go                | 24 ++++++++++++++++++++++--
 network/securedNdf.go              |  4 ++--
 network/securedNdf_test.go         |  6 +++---
 5 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/network/dataStructures/ndf.go b/network/dataStructures/ndf.go
index a0ef1f6c..c6490bea 100644
--- a/network/dataStructures/ndf.go
+++ b/network/dataStructures/ndf.go
@@ -40,7 +40,7 @@ func NewNdf(definition *ndf.NetworkDefinition) (*Ndf, error) {
 }
 
 //Updates to a new NDF if the passed NDF is valid
-func (file *Ndf) Update(m *pb.NDF, e2eGroup *Group, cmixGroup *Group) error {
+func (file *Ndf) Update(m *pb.NDF) error {
 
 	//build the ndf object
 	decoded, _, err := ndf.DecodeNDF(string(m.Ndf))
diff --git a/network/dataStructures/ndf_test.go b/network/dataStructures/ndf_test.go
index d420c9d8..99940fd7 100644
--- a/network/dataStructures/ndf_test.go
+++ b/network/dataStructures/ndf_test.go
@@ -18,7 +18,7 @@ func setup() *Ndf {
 	}
 	ndf := &Ndf{}
 
-	_ = ndf.Update(msg, nil, nil)
+	_ = ndf.Update(msg)
 	return ndf
 }
 
@@ -39,12 +39,12 @@ func TestNdf_Update(t *testing.T) {
 	}
 	ndf := Ndf{}
 
-	err := ndf.Update(badMsg, nil, nil)
+	err := ndf.Update(badMsg)
 	if err == nil {
 		t.Error("Should have returned error when unable to decode ndf")
 	}
 
-	err = ndf.Update(msg, nil, nil)
+	err = ndf.Update(msg)
 	if err != nil {
 		t.Errorf("Failed to update ndf: %+v", err)
 	}
diff --git a/network/instance.go b/network/instance.go
index 9fae1e6d..f6da1396 100644
--- a/network/instance.go
+++ b/network/instance.go
@@ -78,6 +78,26 @@ func NewInstance(c *connect.ProtoComms, partial, full *ndf.NetworkDefinition) (*
 	}, nil
 }
 
+// UpdateGroup updates the groups of the network instance given an ndf
+func (i *Instance) UpdateGroup(m *pb.NDF) error {
+	decoded, _, err := ndf.DecodeNDF(string(m.Ndf))
+	if err != nil {
+		return errors.WithMessage(err, "Could not decode the NDF")
+	}
+
+	err = i.cmixGroup.Update(decoded.CMIX.String())
+	if err != nil {
+		return errors.WithMessage(err, "Could not update cmix group")
+	}
+
+	err = i.e2eGroup.Update(decoded.E2E.String())
+	if err != nil {
+		return errors.WithMessage(err, "Could not update e2e group")
+	}
+
+	return nil
+}
+
 //update the partial ndf
 func (i *Instance) UpdatePartialNdf(m *pb.NDF) error {
 	perm, success := i.comm.GetHost(id.PERMISSIONING)
@@ -87,7 +107,7 @@ func (i *Instance) UpdatePartialNdf(m *pb.NDF) error {
 			"for NDF partial verification")
 	}
 
-	return i.partial.update(m, perm.GetPubKey(), i.e2eGroup, i.cmixGroup)
+	return i.partial.update(m, perm.GetPubKey())
 }
 
 //update the full ndf
@@ -99,7 +119,7 @@ func (i *Instance) UpdateFullNdf(m *pb.NDF) error {
 			"for full NDF verification")
 	}
 
-	return i.full.update(m, perm.GetPubKey(), i.e2eGroup, i.cmixGroup)
+	return i.full.update(m, perm.GetPubKey())
 }
 
 // Return the partial ndf from this instance
diff --git a/network/securedNdf.go b/network/securedNdf.go
index 5e43728a..34cc6a4b 100644
--- a/network/securedNdf.go
+++ b/network/securedNdf.go
@@ -35,13 +35,13 @@ func NewSecuredNdf(definition *ndf.NetworkDefinition) (*SecuredNdf, error) {
 }
 
 // unexported NDF update code
-func (sndf *SecuredNdf) update(m *pb.NDF, key *rsa.PublicKey, e2eGroup *ds.Group, cmixGroup *ds.Group) error {
+func (sndf *SecuredNdf) update(m *pb.NDF, key *rsa.PublicKey) error {
 	err := signature.Verify(m, key)
 	if err != nil {
 		return errors.WithMessage(err, "Could not validate NDF")
 	}
 
-	return sndf.f.Update(m, e2eGroup, cmixGroup)
+	return sndf.f.Update(m)
 }
 
 // Get the primitives object for an ndf
diff --git a/network/securedNdf_test.go b/network/securedNdf_test.go
index ac30c6af..e03e7e70 100644
--- a/network/securedNdf_test.go
+++ b/network/securedNdf_test.go
@@ -23,7 +23,7 @@ func setup() *ds.Ndf {
 	}
 	ndf := &ds.Ndf{}
 
-	_ = ndf.Update(msg, nil, nil)
+	_ = ndf.Update(msg)
 	return ndf
 }
 
@@ -71,13 +71,13 @@ func TestSecuredNdf_update(t *testing.T) {
 	if err != nil {
 		t.Errorf("Failed to secure ndf: %+v", err)
 	}
-	err = sndf.update(&f, privKey.GetPublic(), nil, nil)
+	err = sndf.update(&f, privKey.GetPublic())
 
 	if err != nil {
 		t.Errorf("Could not update ndf: %s", err)
 	}
 
-	err = sndf.update(&f, badPub, nil, nil)
+	err = sndf.update(&f, badPub)
 	if err == nil {
 		t.Errorf("should have received bad key error")
 	}
-- 
GitLab