Skip to content
Snippets Groups Projects
Commit be5dcc89 authored by Jake Taylor's avatar Jake Taylor :lips:
Browse files

Merge branch 'XX-2816/AddressUpdate' into 'master'

add address updating

See merge request elixxir/registration!234
parents 7a453973 46f557de
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,7 @@ import (
"gitlab.com/elixxir/primitives/id"
"gitlab.com/elixxir/primitives/ndf"
"gitlab.com/elixxir/primitives/version"
"gitlab.com/elixxir/registration/storage"
"gitlab.com/elixxir/registration/storage/node"
"gitlab.com/xx_network/comms/connect"
"net"
......@@ -366,6 +367,13 @@ func checkIPAddresses(m *RegistrationImpl, n *node.State, msg *pb.PermissioningP
jww.TRACE.Printf("UPDATING gateway and node update: %s, %s", nodeAddress,
gatewayAddress)
// Update address information in Storage
err = storage.PermissioningDb.UpdateNodeAddresses(nodeHost.GetId(), nodeAddress, gatewayAddress)
if err != nil {
return err
}
m.NDFLock.Lock()
currentNDF := m.State.GetFullNdf().Get()
......
......@@ -59,6 +59,7 @@ type NodeRegistration interface {
InsertRoundMetric(metric *RoundMetric, topology [][]byte) error
// Insert RoundError object
InsertRoundError(roundId id.Round, errStr string) error
UpdateNodeAddresses(id *id.ID, nodeAddr, gwAddr string) error
}
type ClientRegistration interface {
......
......@@ -71,7 +71,7 @@ func (m *DatabaseImpl) UpdateSalt(id *id.ID, salt []byte) error {
// If Node registration code is valid, add Node information
func (m *DatabaseImpl) RegisterNode(id *id.ID, salt []byte, code, serverAddr, serverCert,
gatewayAddress, gatewayCert string) error {
newNode := Node{
newNode := &Node{
Code: code,
Id: id.Marshal(),
Salt: salt,
......@@ -85,6 +85,19 @@ func (m *DatabaseImpl) RegisterNode(id *id.ID, salt []byte, code, serverAddr, se
return m.db.Model(&newNode).Update(&newNode).Error
}
// Update the address fields for the Node with the given id
func (m *DatabaseImpl) UpdateNodeAddresses(id *id.ID, nodeAddr, gwAddr string) error {
newNode := &Node{
Id: id.Marshal(),
ServerAddress: nodeAddr,
GatewayAddress: gwAddr,
}
return m.db.Model(newNode).Where("id = ?", newNode.Id).Updates(map[string]interface{}{
"server_address": nodeAddr,
"gateway_address": gwAddr,
}).Error
}
// Get Node information for the given Node registration code
func (m *DatabaseImpl) GetNode(code string) (*Node, error) {
newNode := &Node{}
......
......@@ -134,6 +134,22 @@ func (m *MapImpl) RegisterNode(id *id.ID, salt []byte, code, serverAddress, serv
}
// Update the address fields for the Node with the given id
func (m *MapImpl) UpdateNodeAddresses(id *id.ID, nodeAddr, gwAddr string) error {
m.mut.Lock()
defer m.mut.Unlock()
for _, v := range m.nodes {
if bytes.Compare(v.Id, id.Marshal()) == 0 {
v.GatewayAddress = gwAddr
v.ServerAddress = nodeAddr
return nil
}
}
return errors.Errorf("unable to update addresses for %s", id.String())
}
// Get Node information for the given Node registration code
func (m *MapImpl) GetNode(code string) (*Node, error) {
m.mut.Lock()
......
......@@ -49,6 +49,11 @@ import (
// t.Errorf(err.Error())
// return
// }
// err = db.UpdateNodeAddresses(testId, "6.6.6.6", "6.6.7.7")
// if err != nil {
// t.Errorf(err.Error())
// return
// }
// err = db.UpdateSalt(testId, []byte("test123"))
// if err != nil {
// t.Errorf(err.Error())
......@@ -323,6 +328,33 @@ func TestMapImpl_RegisterNode_Invalid(t *testing.T) {
}
}
// Happy path
func TestMapImpl_UpdateNodeAddresses(t *testing.T) {
m := &MapImpl{
nodes: make(map[string]*Node),
}
testString := "test"
testId := id.NewIdFromString(testString, id.Node, t)
testResult := "newAddr"
m.nodes[testString] = &Node{
Code: testString,
Id: testId.Marshal(),
ServerAddress: testString,
GatewayAddress: testString,
}
err := m.UpdateNodeAddresses(testId, testResult, testResult)
if err != nil {
t.Errorf(err.Error())
}
if result := m.nodes[testString]; result.ServerAddress != testResult || result.GatewayAddress != testResult {
t.Errorf("Field values did not update correctly, got Node %s Gateway %s",
result.ServerAddress, result.GatewayAddress)
}
}
// Happy path
func TestMapImpl_GetNode(t *testing.T) {
m := &MapImpl{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment