Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix peer state update #320

Merged
merged 2 commits into from
Aug 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 8 additions & 24 deletions poc-cb-net/cmd/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ func watchPeers(ctx context.Context, etcdClient *clientv3.Client, wg *sync.WaitG
}

// Store peers to synchronize and use it in local
prevThisPeer := CBNet.ThisPeer
// prevThisPeer := CBNet.ThisPeer
CBNet.StorePeer(peer)

// Initialize or update networking rule
Expand Down Expand Up @@ -536,12 +536,12 @@ func watchPeers(ctx context.Context, etcdClient *clientv3.Client, wg *sync.WaitG

} else if peer.State == netstate.Tunneling {

// Update networking rule if it's not a simple state chanage of this peer
if prevThisPeer.State == peer.State {
// Update the networking rule for this peer
CBLogger.Debug("Update the networking rule for this peer")
updateNetworkingRule(CBNet.ThisPeer, CBNet.OtherPeers, ruleType, etcdClient)
}
// // Update networking rule if it's not a simple state chanage of this peer
// if prevThisPeer.State == peer.State {
// Update the networking rule for this peer
CBLogger.Debug("Update the networking rule for this peer")
updateNetworkingRule(CBNet.ThisPeer, CBNet.OtherPeers, ruleType, etcdClient)
// }

} else {
CBLogger.Debugf("Skip to update the networking rule (this peer's state: %v)", peer.State)
Expand Down Expand Up @@ -657,23 +657,7 @@ func updatePeerInNetworkingRule(thisPeer model.Peer, otherPeer model.Peer, ruleT

networkingRule := CBNet.NetworkingRule

// Get a specification of a cloud adaptive network
keyCLADNetSpec := fmt.Sprint(etcdkey.CLADNetSpecification + "/" + thisPeer.CladnetID)
CBLogger.Tracef("Get - %v", keyCLADNetSpec)

respCLADNetSpec, etcdErr := etcdClient.Get(context.Background(), keyCLADNetSpec)
if etcdErr != nil {
CBLogger.Error(etcdErr)
}
CBLogger.Tracef("GetResponse: %v", respCLADNetSpec)

var cladnetSpec model.CLADNetSpecification
if err := json.Unmarshal(respCLADNetSpec.Kvs[0].Value, &cladnetSpec); err != nil {
CBLogger.Error(err)
}
CBLogger.Tracef("The CLADNet spec: %v", cladnetSpec)

// Create networking rule table for each peer
// Update networking rule for the peer

// Select destination IP
selectedIP, peerScope, err := cbnet.SelectDestinationByRuleType(ruleType, thisPeer, otherPeer)
Expand Down