def on_connection_update(self, connection_event):
     """
     Updates the connection edge's current state based on the provided event. This is the
     completion for a create or remove connection request to Link Manager.
     """
     peer_id = connection_event["PeerId"]
     link_id = connection_event["LinkId"]
     overlay_id = connection_event["OverlayId"]
     with self._lock:
         if connection_event["UpdateType"] == "CREATING":
             conn_edge = self._current_adj_list.conn_edges.get(
                 peer_id, None)
             if not conn_edge:
                 # this happens when the neighboring peer initiates the connection bootstrap
                 self._refresh_in_progress += 1
                 conn_edge = ConnectionEdge(peer_id, "CETypePredecessor")
                 self._current_adj_list.conn_edges[peer_id] = conn_edge
             conn_edge.edge_state = "CEStateCreated"
             conn_edge.link_id = link_id
         elif connection_event["UpdateType"] == "REMOVED":
             self._current_adj_list.conn_edges.pop(peer_id, None)
             self._refresh_in_progress -= 1
         elif connection_event["UpdateType"] == "CONNECTED":
             self._current_adj_list.conn_edges[
                 peer_id].edge_state = "CEStateConnected"
             self._current_adj_list.conn_edges[peer_id].connected_time = \
                 connection_event["ConnectedTimestamp"]
             self._refresh_in_progress -= 1
         elif connection_event["UpdateType"] == "DISCONNECTED":
             # the local topology did not request removal of the connection
             self._top.top_log(
                 "CEStateDisconnected event recvd peer_id: {0}, link_id: {1}"
                 .format(peer_id, link_id))
             self._current_adj_list.conn_edges[
                 peer_id].edge_state = "CEStateDisconnected"
             self._refresh_in_progress += 1
             self._top.top_remove_edge(overlay_id, peer_id)
         elif connection_event["UpdateType"] == "RemoveEdgeFailed":
             # leave the node in the adj list and marked for removal to be retried.
             self._refresh_in_progress -= 1
         else:
             self._top.top_log(
                 "Logger", "LOG_WARNING",
                 "Invalid UpdateType specified for connection update")
Exemple #2
0
 def on_connection_update(self, connection_event):
     """
     Updates the connection edge's current state based on the provided event. This is the
     completion for a create or remove connection request to Link Manager.
     """
     peer_id = connection_event["PeerId"]
     link_id = connection_event["LinkId"]
     overlay_id = connection_event["OverlayId"]
     with self._lock:
         if connection_event["UpdateType"] == "CREATING":
             conn_edge = self._current_edges.conn_edges.get(peer_id, None)
             if not conn_edge:
                 # this happens when the neighboring peer initiates the connection bootstrap
                 self._refresh_in_progress = self._refresh_in_progress + 1
                 conn_edge = ConnectionEdge(peer_id)
                 self._current_edges.conn_edges[peer_id] = conn_edge
                 conn_edge.type = "CETypePredecessor"
             conn_edge.state = "CEStateCreated"
             conn_edge.link_id = link_id
         elif connection_event["UpdateType"] == "REMOVED":
             self._current_edges.conn_edges.pop(peer_id, None)
             self._refresh_in_progress = self._refresh_in_progress - 1
         elif connection_event["UpdateType"] == "CONNECTED":
             self._current_edges.conn_edges[
                 peer_id].state = "CEStateConnected"
             self._current_edges.conn_edges[peer_id].connected_time = \
                 connection_event["ConnectedTimestamp"]
             self._refresh_in_progress = self._refresh_in_progress - 1
         elif connection_event["UpdateType"] == "DISCONNECTED":
             # this branch is taken when the local node did not explicitly remove the connection
             self._top.top_log(
                 "CEStateDisconnected event recvd peer_id: {0}, link_id: {1}"
                 .format(peer_id, link_id))
             self._current_edges.conn_edges[
                 peer_id].state = "CEStateDisconnected"
             self._refresh_in_progress = self._refresh_in_progress + 1
             self._top.top_remove_edge(overlay_id, peer_id)