diff --git a/cmd/impl.go b/cmd/impl.go index 96add3bac0ff3bf9fad5f5bbd36a04035d7021de..3312503623b8b1c71f2844effff7c77a54ad4bfe 100644 --- a/cmd/impl.go +++ b/cmd/impl.go @@ -45,8 +45,9 @@ type RegistrationImpl struct { //FIXME: it is possible that polling lock and registration lock // do the same job and could conflict. reconsiderations of this logic // may be fruitful - registrationLock sync.Mutex - beginScheduling chan struct{} + registrationLock sync.Mutex + beginScheduling chan struct{} + //TODO-kill this registrationTimes map[id.ID]int64 NDFLock sync.Mutex @@ -198,7 +199,11 @@ func BannedNodeTracker(impl *RegistrationImpl) error { return errors.Errorf("Failed to convert node %s to id.ID: %v", n.Id, err) } - var newNodes []ndf.Node + gatewayID := nodeId.DeepCopy() + gatewayID.SetType(id.Gateway) + + var remainingNodes []ndf.Node + var remainingGateways []ndf.Gateway // Loop through NDF nodes to remove any that are banned for i, n := range def.Nodes { ndfNodeID, err := id.Unmarshal(n.ID) @@ -208,11 +213,35 @@ func BannedNodeTracker(impl *RegistrationImpl) error { if ndfNodeID.Cmp(nodeId) { continue } else { - newNodes = append(newNodes, def.Nodes[i]) + remainingNodes = append(remainingNodes, def.Nodes[i]) + } + } + + for i, g := range def.Gateways { + ndfGatewayID, err := id.Unmarshal(g.ID) + if err != nil { + return errors.WithMessage(err, "Failed to unmarshal gateway id from NDF") + } + if ndfGatewayID.Cmp(gatewayID) { + continue + } else { + remainingGateways = append(remainingGateways, def.Gateways[i]) } } - if len(newNodes) != len(def.Nodes) { - def.Nodes = newNodes + + update := false + + if len(remainingNodes) != len(def.Nodes) { + def.Nodes = remainingNodes + update = true + } + + if len(remainingGateways) != len(def.Gateways) { + def.Gateways = remainingGateways + update = true + } + + if update { err = state.UpdateNdf(def) if err != nil { return errors.WithMessage(err, "Failed to update NDF after bans") diff --git a/cmd/permissioning.go b/cmd/permissioning.go index 82992ffa915d01c2ff3a6f5ee9565e52ea79e32e..55997c83cc984c32cde761c6e2c528c4cc664ef9 100644 --- a/cmd/permissioning.go +++ b/cmd/permissioning.go @@ -188,11 +188,6 @@ func (m *RegistrationImpl) LoadAllRegisteredNodes() error { return errors.WithMessage(err, "Could not register node with "+ "state tracker") } - - err = m.completeNodeRegistration(n.Code) - if err != nil { - return err - } } return nil diff --git a/cmd/permissioning_test.go b/cmd/permissioning_test.go index b14e05d45bae68aebe19410b0fd02daa2bad9f76..67f58b03ac537a97986236deec7b5f785cf69e64 100644 --- a/cmd/permissioning_test.go +++ b/cmd/permissioning_test.go @@ -128,12 +128,12 @@ func TestLoadAllRegisteredNodes(t *testing.T) { if err != nil { t.Error("Failed to unmarshal ID") } - if !id1.Cmp(bannedNodeId) { + if id1.Cmp(bannedNodeId) { t.Errorf("Unexpected node ID for node 1:\n\tGot: %d\n\tExpected: %d", nodeMapNodes[1].GetID(), bannedNodeId) } - id2, err := id.Unmarshal(def.Nodes[2].ID) + id2, err := id.Unmarshal(def.Nodes[1].ID) if err != nil { t.Error("Failed to unmarshal ID") } diff --git a/cmd/poll.go b/cmd/poll.go index 0260baade6eb193264be9d29fb519cfed30628e8..716304f10852975f3a6ca2abefb8afd7a3d0db8f 100644 --- a/cmd/poll.go +++ b/cmd/poll.go @@ -42,11 +42,18 @@ func (m *RegistrationImpl) Poll(msg *pb.PermissioningPoll, auth *connect.Auth) ( return response, connect.AuthError(auth.Sender.GetId()) } + // Check for correct version + err := checkVersion(m.params.minGatewayVersion, m.params.minServerVersion, + msg) + if err != nil { + return response, err + } + // Get the nodeState and update nid := auth.Sender.GetId() n := m.State.GetNodeMap().GetNode(nid) if n == nil { - err := errors.Errorf("Node %s could not be found in internal state "+ + err = errors.Errorf("Node %s could not be found in internal state "+ "tracker", nid) return response, err } @@ -59,19 +66,12 @@ func (m *RegistrationImpl) Poll(msg *pb.PermissioningPoll, auth *connect.Auth) ( activity := current.Activity(msg.Activity) // update ip addresses if necessary - err := checkIPAddresses(m, n, msg, auth.Sender) + err = checkIPAddresses(m, n, msg, auth.Sender) if err != nil { err = errors.WithMessage(err, "Failed to update IP addresses") return response, err } - // Check for correct version - err = checkVersion(m.params.minGatewayVersion, m.params.minServerVersion, - msg) - if err != nil { - return response, err - } - // Increment the Node's poll count n.IncrementNumPolls() @@ -414,11 +414,11 @@ func (m *RegistrationImpl) checkConnectivity(n *node.State, // this will approximately force a recheck of the node state every 3~5 // minutes - if rand.Uint64()%211==13 { + if rand.Uint64()%211 == 13 { n.SetConnectivity(node.PortUnknown) } nodeAddress := "unknown" - if nodeHost, exists := m.Comms.GetHost(n.GetID()); exists{ + if nodeHost, exists := m.Comms.GetHost(n.GetID()); exists { nodeAddress = nodeHost.GetAddress() } // If only the Node port has been marked as failed, @@ -428,7 +428,7 @@ func (m *RegistrationImpl) checkConnectivity(n *node.State, case node.GatewayPortFailed: // this will approximately force a recheck of the node state every 3~5 // minutes - if rand.Uint64()%211==13 { + if rand.Uint64()%211 == 13 { n.SetConnectivity(node.PortUnknown) } gwID := n.GetID().DeepCopy() @@ -440,11 +440,11 @@ func (m *RegistrationImpl) checkConnectivity(n *node.State, case node.PortFailed: // this will approximately force a recheck of the node state every 3~5 // minutes - if rand.Uint64()%211==13 { + if rand.Uint64()%211 == 13 { n.SetConnectivity(node.PortUnknown) } nodeAddress := "unknown" - if nodeHost, exists := m.Comms.GetHost(n.GetID()); exists{ + if nodeHost, exists := m.Comms.GetHost(n.GetID()); exists { nodeAddress = nodeHost.GetAddress() } // If the port has been marked as failed, diff --git a/cmd/version.go b/cmd/version.go index 0887c28039c03be0f68aadf2d6d934d663621367..5538b347495a7cba45640f945bf7b3e8ce4d7471 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -16,7 +16,7 @@ import ( ) // Change this value to set the version for this build -const currentVersion = "2.1.0" +const currentVersion = "2.1.1" func printVersion() { fmt.Printf("xx network Permissioning Server v%s -- %s\n\n", diff --git a/cmd/version_vars.go b/cmd/version_vars.go index 25f85082e0ebe1e8e76c74c6bea2062308e98a5d..ee02af21971089bfeda383dfe37cc32ad58821c8 100644 --- a/cmd/version_vars.go +++ b/cmd/version_vars.go @@ -1,10 +1,10 @@ // Code generated by go generate; DO NOT EDIT. // This file was generated by robots at -// 2021-03-15 14:57:45.9221426 -0700 PDT m=+0.184213301 +// 2021-03-18 13:26:45.482145 -0500 CDT m=+0.026916965 package cmd -const GITVERSION = `56bc43b Merge branch 'NDFPruning' into 'release'` -const SEMVER = "2.1.0" +const GITVERSION = `f6c4767 check node/gw version earlier in the polling process` +const SEMVER = "2.1.1" const DEPENDENCIES = `module gitlab.com/elixxir/registration go 1.13 @@ -26,12 +26,12 @@ require ( github.com/spf13/cobra v1.1.3 github.com/spf13/jwalterweatherman v1.1.0 github.com/spf13/viper v1.7.1 - gitlab.com/elixxir/client v1.5.1-0.20210315164614-e33b49a633c3 - gitlab.com/elixxir/comms v0.0.4-0.20210311180506-28ae742c5e35 - gitlab.com/elixxir/crypto v0.0.7-0.20210309193114-8a6225c667e2 + gitlab.com/elixxir/client v1.2.1-0.20210222224029-4300043d7ce8 + gitlab.com/elixxir/comms v0.0.4-0.20210316224000-76529267620c + gitlab.com/elixxir/crypto v0.0.7-0.20210316212419-025ba777a80b gitlab.com/elixxir/primitives v0.0.3-0.20210309193003-ef42ebb4800b - gitlab.com/xx_network/comms v0.0.4-0.20210309192940-6b7fb39b4d01 - gitlab.com/xx_network/crypto v0.0.5-0.20210309192854-cf32117afb96 + gitlab.com/xx_network/comms v0.0.4-0.20210316212314-d9a2a5e589c8 + gitlab.com/xx_network/crypto v0.0.5-0.20210316212152-504c0a1e0da0 gitlab.com/xx_network/primitives v0.0.4-0.20210309173740-eb8cd411334a golang.org/x/crypto v0.0.0-20210314154223-e6e6c4f2bb5b // indirect golang.org/x/net v0.0.0-20210315170653-34ac3e1c2000 // indirect diff --git a/go.mod b/go.mod index 790ac23a22abaa5ee769619a12f7c1381f1853a7..2acc96310e275f36b97f2060b8b588ee4ee3881d 100644 --- a/go.mod +++ b/go.mod @@ -20,10 +20,10 @@ require ( github.com/spf13/jwalterweatherman v1.1.0 github.com/spf13/viper v1.7.1 gitlab.com/elixxir/client v1.2.1-0.20210222224029-4300043d7ce8 - gitlab.com/elixxir/comms v0.0.4-0.20210316224000-76529267620c + gitlab.com/elixxir/comms v0.0.4-0.20210318223653-0d4e0688da7e gitlab.com/elixxir/crypto v0.0.7-0.20210316212419-025ba777a80b gitlab.com/elixxir/primitives v0.0.3-0.20210309193003-ef42ebb4800b - gitlab.com/xx_network/comms v0.0.4-0.20210316212314-d9a2a5e589c8 + gitlab.com/xx_network/comms v0.0.4-0.20210318220114-fddcc4e1445d gitlab.com/xx_network/crypto v0.0.5-0.20210316212152-504c0a1e0da0 gitlab.com/xx_network/primitives v0.0.4-0.20210309173740-eb8cd411334a golang.org/x/crypto v0.0.0-20210314154223-e6e6c4f2bb5b // indirect diff --git a/go.sum b/go.sum index fc0907502a173eba1604b80e120b1e8a93203212..57d475c83946f20fb33c48aa728ca3bf9ee1babb 100644 --- a/go.sum +++ b/go.sum @@ -316,6 +316,10 @@ gitlab.com/elixxir/comms v0.0.4-0.20210316212548-21282c4ffdeb h1:uHSUmO4Z1GKj+kh gitlab.com/elixxir/comms v0.0.4-0.20210316212548-21282c4ffdeb/go.mod h1:yMy042ResQpS2cM6mdaoRYhAtQX9Yx5r3H9jS7619AU= gitlab.com/elixxir/comms v0.0.4-0.20210316224000-76529267620c h1:0G5UuaWzSersRRq6xcXD0LTP5KY2eKrB1G+TusLxcbk= gitlab.com/elixxir/comms v0.0.4-0.20210316224000-76529267620c/go.mod h1:yMy042ResQpS2cM6mdaoRYhAtQX9Yx5r3H9jS7619AU= +gitlab.com/elixxir/comms v0.0.4-0.20210318211017-914687d3a27c h1:jTJBclHYkHJsGimnXi6NDgWott8Vs2/ZYVVo5EafIrE= +gitlab.com/elixxir/comms v0.0.4-0.20210318211017-914687d3a27c/go.mod h1:x0d8M9ivm0HxVgCifxC/nQ/06vCzsbVM4iZAKoL0uUE= +gitlab.com/elixxir/comms v0.0.4-0.20210318223653-0d4e0688da7e h1:BNRr8HEaD9K2fk8sm7fJymYAbxbqWYsu9Q03vcvYSZA= +gitlab.com/elixxir/comms v0.0.4-0.20210318223653-0d4e0688da7e/go.mod h1:lvnV9TBQJa/PCXJ1dOleX3JZzh4bAkgGxIJPKSe4jZQ= gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4/go.mod h1:ucm9SFKJo+K0N2GwRRpaNr+tKXMIOVWzmyUD0SbOu2c= gitlab.com/elixxir/crypto v0.0.3/go.mod h1:ZNgBOblhYToR4m8tj4cMvJ9UsJAUKq+p0gCp07WQmhA= gitlab.com/elixxir/crypto v0.0.7-0.20210216174551-f806f79610eb h1:aPcrTC0QdrPqz4NgoAt5sfXt/+EFrNUwIns0s0VCQmg= @@ -344,6 +348,10 @@ gitlab.com/xx_network/comms v0.0.4-0.20210309192940-6b7fb39b4d01 h1:f93iz7mTHt3r gitlab.com/xx_network/comms v0.0.4-0.20210309192940-6b7fb39b4d01/go.mod h1:aNPRHmPssXc1JMJ83DAknT2C2iMgKL1wH3//AqQrhQc= gitlab.com/xx_network/comms v0.0.4-0.20210316212314-d9a2a5e589c8 h1:WED5SlL+t6nW/gwFgyJv5vqPb/1pFVd1HRC1wgL+9wY= gitlab.com/xx_network/comms v0.0.4-0.20210316212314-d9a2a5e589c8/go.mod h1:+4Qb4c5K0yj9Je0b8fxxw+aKZdM5y3PrpQ+ZXUwdUsI= +gitlab.com/xx_network/comms v0.0.4-0.20210318210121-588846979bad h1:vh+ApxKmOIWu4ZVSiBn6cvz2oXf7J29ULo1hOlxYp90= +gitlab.com/xx_network/comms v0.0.4-0.20210318210121-588846979bad/go.mod h1:+4Qb4c5K0yj9Je0b8fxxw+aKZdM5y3PrpQ+ZXUwdUsI= +gitlab.com/xx_network/comms v0.0.4-0.20210318220114-fddcc4e1445d h1:N8kVPT7EDfUnzNuAvGJgYnUQe2Zkhc8qHryzF9v6xZo= +gitlab.com/xx_network/comms v0.0.4-0.20210318220114-fddcc4e1445d/go.mod h1:+4Qb4c5K0yj9Je0b8fxxw+aKZdM5y3PrpQ+ZXUwdUsI= gitlab.com/xx_network/crypto v0.0.3/go.mod h1:DF2HYvvCw9wkBybXcXAgQMzX+MiGbFPjwt3t17VRqRE= gitlab.com/xx_network/crypto v0.0.4/go.mod h1:+lcQEy+Th4eswFgQDwT0EXKp4AXrlubxalwQFH5O0Mk= gitlab.com/xx_network/crypto v0.0.5-0.20210216174356-e81e1ddf8fb7 h1:vyL+m7D7w+RgMPARzcKCR8UMGC2foqNU6cSb1J6Dkis= diff --git a/storage/nodeDb.go b/storage/nodeDb.go index 63c41915d8d533adc4d41b5bb396ef77adf6c271..cb8266c7d5d1521e25401c7cca6c1df5ae51bb7f 100644 --- a/storage/nodeDb.go +++ b/storage/nodeDb.go @@ -10,6 +10,7 @@ package storage import ( + jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/registration/storage/node" "gitlab.com/xx_network/primitives/id" "time" @@ -64,6 +65,8 @@ func (d *DatabaseImpl) GetNodeById(id *id.ID) (*Node, error) { func (d *DatabaseImpl) GetNodesByStatus(status node.Status) ([]*Node, error) { var nodes []*Node err := d.db.Where("status = ?", uint8(status)).Find(&nodes).Error + jww.INFO.Printf("GetNodesByStatus: Got %d nodes with status "+ + "%s(%d) from the database", len(nodes), status, status) return nodes, err }