Jelajahi Sumber

Merge pull request #1406 from mrjana/bugs

Ensure add newly joined node to networknodes
Santhosh Manohar 9 tahun lalu
induk
melakukan
173832dd19
2 mengubah file dengan 16 tambahan dan 1 penghapusan
  1. 2 1
      libnetwork/networkdb/delegate.go
  2. 14 0
      libnetwork/networkdb/networkdb.go

+ 2 - 1
libnetwork/networkdb/delegate.go

@@ -53,6 +53,7 @@ func (nDB *NetworkDB) handleNetworkEvent(nEvent *NetworkEvent) bool {
 			n.leaveTime = time.Now()
 		}
 
+		nDB.addNetworkNode(nEvent.NetworkID, nEvent.NodeName)
 		return true
 	}
 
@@ -66,7 +67,7 @@ func (nDB *NetworkDB) handleNetworkEvent(nEvent *NetworkEvent) bool {
 		ltime: nEvent.LTime,
 	}
 
-	nDB.networkNodes[nEvent.NetworkID] = append(nDB.networkNodes[nEvent.NetworkID], nEvent.NodeName)
+	nDB.addNetworkNode(nEvent.NetworkID, nEvent.NodeName)
 	return true
 }
 

+ 14 - 0
libnetwork/networkdb/networkdb.go

@@ -455,6 +455,20 @@ func (nDB *NetworkDB) LeaveNetwork(nid string) error {
 	return nil
 }
 
+// addNetworkNode adds the node to the list of nodes which participate
+// in the passed network only if it is not already present. Caller
+// should hold the NetworkDB lock while calling this
+func (nDB *NetworkDB) addNetworkNode(nid string, nodeName string) {
+	nodes := nDB.networkNodes[nid]
+	for _, node := range nodes {
+		if node == nodeName {
+			return
+		}
+	}
+
+	nDB.networkNodes[nid] = append(nDB.networkNodes[nid], nodeName)
+}
+
 // Deletes the node from the list of nodes which participate in the
 // passed network. Caller should hold the NetworkDB lock while calling
 // this