Skip to content

Commit

Permalink
Updated sync RouteTable
Browse files Browse the repository at this point in the history
  • Loading branch information
Dliv3 committed Jan 27, 2019
1 parent 3c0fbf1 commit 2d636e2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions admin/dispather/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ func SendSyncCmd() {
// 重新初始化网络拓扑,这样当有节点断开时网络拓扑会实时改变
node.GNetworkTopology.InitNetworkMap()

networkMap := node.GNetworkTopology.GenerateNetworkMapData()

for i := range node.Nodes {
// 向直连的节点发送SYNC数据包,同步网络拓扑
// 目标节点会递归处理SYNC数据包,以获得全网拓扑
Expand All @@ -33,7 +35,6 @@ func SendSyncCmd() {
CmdType: protocol.SYNC,
}
// 生成本节点网络拓扑数据
networkMap := node.GNetworkTopology.GenerateNetworkMapData()
syncPacket := protocol.SyncPacket{
NetworkMapLen: uint64(len(networkMap)),
NetworkMap: networkMap,
Expand Down Expand Up @@ -103,9 +104,9 @@ func SendListenCmd(peerNode *node.Node, port uint16) {
node.CurrentNode.CommandBuffers[protocol.LISTEN].ReadPacket(&packetHeader, &listenPacketRet)

if listenPacketRet.Success == 1 {
fmt.Println("listen local port success!")
fmt.Println("listen remote port success!")
} else {
fmt.Println("listen local port failed!")
fmt.Println("listen remote port failed!")
fmt.Println(string(listenPacketRet.Msg))
}
}
Expand Down
5 changes: 3 additions & 2 deletions agent/dispather/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ func handleSyncCmd() {
// nextNode为下一跳
nextNode := node.Nodes[node.GNetworkTopology.RouteTable[peerNodeID]]

networkMap := node.GNetworkTopology.GenerateNetworkMapData()

// 递归向其他节点发送sync同步路由表请求
for i := range node.Nodes {
if node.Nodes[i].HashID != peerNodeID && node.Nodes[i].DirectConnection {
Expand All @@ -84,7 +86,6 @@ func handleSyncCmd() {
DstHashID: utils.UUIDToArray32(node.Nodes[i].HashID),
CmdType: protocol.SYNC,
}
networkMap := node.GNetworkTopology.GenerateNetworkMapData()
tempSyncPacket := protocol.SyncPacket{
NetworkMapLen: uint64(len(networkMap)),
NetworkMap: networkMap,
Expand Down Expand Up @@ -134,7 +135,7 @@ func handleSyncCmd() {
DstHashID: packetHeader.SrcHashID,
CmdType: protocol.SYNC,
}
networkMap := node.GNetworkTopology.GenerateNetworkMapData()
networkMap = node.GNetworkTopology.GenerateNetworkMapData()
syncPacket = protocol.SyncPacket{
NetworkMapLen: uint64(len(networkMap)),
NetworkMap: networkMap,
Expand Down
2 changes: 1 addition & 1 deletion node/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (nt *NetworkTopology) recursiveUpdateRouteTable(root string, key string) {
// 避免成环
if _, ok := nt.RouteTable[v]; !ok {
nt.RouteTable[v] = root
nt.recursiveUpdateRouteTable(v, v)
nt.recursiveUpdateRouteTable(root, v)
}
}
}
Expand Down

0 comments on commit 2d636e2

Please sign in to comment.