def processCBT(self, cbt):
        if cbt.action == 'ADD_MAPPING':
            try:
                # cbt.data contains a {'uid': <uid>, 'ip': <ip>} mapping
                self.ip_map[cbt.data['uid']] = cbt.data['ip']
            except KeyError:
                log = "invalid ADD_MAPPING configuration"
                self.registerCBT('Logger', 'warning', log)

        elif cbt.action == 'DEL_MAPPING':
            self.ip_map.pop(cbt.data)

        elif cbt.action == 'RESOLVE':
            data = ipoplib.gen_ip4(cbt.data, self.ip_map, self.CMConfig["ip4"])
            self.registerCBT(cbt.initiator, 'RESOLVE_RESP', data, cbt.uid)

        elif cbt.action == 'QUERY_IP_MAP':
            self.registerCBT(cbt.initiator, 'QUERY_IP_MAP_RESP', self.ip_map,
                             cbt.uid)

        elif cbt.action == 'REVERSE_RESOLVE':
            self.registerCBT(cbt.initiator, 'REVERSE_RESOLVE_RESP', data,
                             cbt.uid)

        else:
            log = '{0}: unrecognized CBT {1} received from {2}'\
                    .format(cbt.recipient, cbt.action, cbt.initiator)
            self.registerCBT('Logger', 'warning', log)
    def processCBT(self, cbt):
        if cbt.action == 'ADD_MAPPING':
            try:
                # cbt.data contains a {'uid': <uid>, 'ip': <ip>} mapping
                self.ip_map[cbt.data['uid']] = cbt.data['ip']
            except KeyError:
                log = "invalid ADD_MAPPING configuration"
                self.registerCBT('Logger', 'warning', log)

        elif cbt.action == 'DEL_MAPPING':
            self.ip_map.pop(cbt.data)

        elif cbt.action == 'RESOLVE':
            data = ipoplib.gen_ip4(cbt.data, self.ip_map, self.CMConfig["ip4"])
            self.registerCBT(cbt.initiator, 'RESOLVE_RESP', data, cbt.uid)

        elif cbt.action == 'QUERY_IP_MAP':
            self.registerCBT(cbt.initiator, 'QUERY_IP_MAP_RESP', self.ip_map, cbt.uid)

        elif cbt.action == 'REVERSE_RESOLVE':
            self.registerCBT(cbt.initiator, 'REVERSE_RESOLVE_RESP', data, cbt.uid)

        else:
            log = '{0}: unrecognized CBT {1} received from {2}'\
                    .format(cbt.recipient, cbt.action, cbt.initiator)
            self.registerCBT('Logger', 'warning', log)
    def processCBT(self, cbt):

        # In case of a fresh CBT, request the required services
        # from the other modules, by issuing CBTs. If no services
        # from other modules required, process the CBT here only
        if (not self.checkMapping(cbt)):
            if (cbt.action == "TINCAN_MSG"):
                msg = cbt.data
                msg_type = msg.get("type", None)

                # we ignore connection status notification for now
                if msg_type == "con_stat":
                    pass

                elif msg_type == "con_req" or msg_type == "con_resp":
                    stateCBT = self.CFxHandle.createCBT(initiator='Base'
                                                        'TopologyManager',
                                                        recipient='Watchdog',
                                                        action='QUERY_IPOP'
                                                        '_STATE',
                                                        data="")
                    self.CFxHandle.submitCBT(stateCBT)
                    self.CBTMappings[cbt.uid] = [stateCBT.uid]

                    mapCBT = self.CFxHandle.createCBT(initiator='BaseTopology'
                                                      'Manager',
                                                      recipient='Address'
                                                      'Mapper',
                                                      action='RESOLVE',
                                                      data=msg['uid'])
                    self.CFxHandle.submitCBT(mapCBT)
                    self.CBTMappings[cbt.uid].append(mapCBT.uid)

                    ip_mapCBT = self.CFxHandle.createCBT(initiator='Base'
                                                         'TopologyManager',
                                                         recipient='Address'
                                                         'Mapper',
                                                         action='QUERY_IP_MAP',
                                                         data="")
                    self.CFxHandle.submitCBT(ip_mapCBT)
                    self.CBTMappings[cbt.uid].append(ip_mapCBT.uid)

                    conn_stat_CBT = self.CFxHandle.createCBT(
                        initiator='Base'
                        'TopologyManager',
                        recipient='Monitor',
                        action='QUERY_'
                        'CONN_STAT',
                        data=msg['uid'])
                    self.CFxHandle.submitCBT(conn_stat_CBT)
                    self.CBTMappings[cbt.uid].append(conn_stat_CBT.uid)

                    peer_list_CBT = self.CFxHandle.createCBT(
                        initiator='Base'
                        'TopologyManager',
                        recipient='Monitor',
                        action='QUERY_'
                        'PEER_LIST',
                        data='')
                    self.CFxHandle.submitCBT(peer_list_CBT)
                    self.CBTMappings[cbt.uid].append(peer_list_CBT.uid)

                    # Add CBT to pendingCBT dictionary
                    self.pendingCBT[cbt.uid] = cbt

                # Pass for now
                elif msg_type == "send_msg":
                    pass

            elif (cbt.action == "QUERY_PEER_LIST_RESP"):

                # cbt.data is a dict of peers
                self.__link_trimmer(cbt.data)

            else:
                logCBT = self.CFxHandle.createCBT(initiator='BaseTopology'
                                                  'Manager',
                                                  recipient='Logger',
                                                  action='warning',
                                                  data="BaseTopologyManager:"
                                                  " Unrecognized CBT "
                                                  "from " + cbt.initiator)
                self.CFxHandle.submitCBT(logCBT)

        # Case when one of the requested service CBT comes back

        else:
            # Get the source CBT of this request
            sourceCBT_uid = self.checkMapping(cbt)
            self.pendingCBT[cbt.uid] = cbt
            # If all the other services of this sourceCBT are also completed,
            # process CBT here. Else wait for other CBTs to arrive
            if (self.allServicesCompleted(sourceCBT_uid)):
                if (self.pendingCBT[sourceCBT_uid].action == 'TINCAN_MSG'):
                    msg = self.pendingCBT[sourceCBT_uid].data
                    msg_type = msg.get("type", None)
                    if msg_type == "con_req" or msg_type == "con_resp":
                        for key in self.CBTMappings[sourceCBT_uid]:
                            if (self.pendingCBT[key].action ==
                                    'QUERY_IPOP_STATE_RESP'):
                                self.ipop_state = self.pendingCBT[key].data
                            elif (self.pendingCBT[key].action == 'RESOLVE_RESP'
                                  ):
                                ip4 = self.pendingCBT[key].data
                            elif (self.pendingCBT[key].action ==
                                  'QUERY_CONN_STAT_RESP'):
                                conn_stat = self.pendingCBT[key].data
                            elif (self.pendingCBT[key].action ==
                                  'QUERY_PEER_LIST_RESP'):
                                peer_list = self.pendingCBT[key].data
                            elif (self.pendingCBT[key].action ==
                                  'QUERY_IP_MAP_RESP'):
                                ip_map = self.pendingCBT[key].data

                        logCBT = self.CFxHandle.createCBT(initiator='Base'
                                                          'TopologyManager',
                                                          recipient='Logger',
                                                          action='info',
                                                          data="Received"
                                                          " connection request"
                                                          "/response")
                        self.CFxHandle.submitCBT(logCBT)

                        if self.CMConfig["multihop"]:
                            conn_cnt = 0
                            for k, v in peer_list.iteritems():
                                if "fpr" in v and v["status"] == "online":
                                    conn_cnt += 1
                            if conn_cnt >= self.CMConfig["multihop_cl"]:
                                return
                        if self.check_collision(msg_type, msg["uid"],
                                                conn_stat):
                            return
                        fpr_len = len(self.ipop_state["_fpr"])
                        fpr = msg["data"][:fpr_len]
                        cas = msg["data"][fpr_len + 1:]
                        ip4 = ipoplib.gen_ip4(msg["uid"], ip_map,
                                              self.ipop_state["_ip4"])
                        self.create_connection(msg["uid"], fpr, 1,
                                               self.CMConfig["sec"], cas, ip4)
    def processCBT(self, cbt):
        # new CBTs request for services from other modules by issuing CBTs; if no
        # services are required, the CBT is processed here.
        # con_ack packages and moves cas over XMPP/Overlay
        # con_resp is cas received from tin-can after transport allocation is done.
        if not self.checkMapping(cbt):
            if cbt.action in ["TINCAN_MSG", "XMPP_MSG"]:
                msg = cbt.data
                msg_type = msg.get("type", None)

                if msg_type in ["con_req","con_resp","con_ack"]:
                    stateCBT = self.registerCBT('Watchdog', 'QUERY_IPOP_STATE')
                    self.CBTMappings[cbt.uid] = [stateCBT.uid]

                    mapCBT = self.registerCBT('AddressMapper', 'RESOLVE', msg['uid'])
                    self.CBTMappings[cbt.uid].append(mapCBT.uid)

                    ip_mapCBT = self.registerCBT('AddressMapper', 'QUERY_IP_MAP')
                    self.CBTMappings[cbt.uid].append(ip_mapCBT.uid)

                    conn_stat_CBT = self.registerCBT('Monitor', 'QUERY_CONN_STAT', msg['uid'])
                    self.CBTMappings[cbt.uid].append(conn_stat_CBT.uid)

                    peer_list_CBT = self.registerCBT('Monitor', 'QUERY_PEER_LIST')
                    self.CBTMappings[cbt.uid].append(peer_list_CBT.uid)

                    self.pendingCBT[cbt.uid] = cbt
                    self.log("put in cbt queue {0}".format(msg_type))

            elif cbt.action == "QUERY_PEER_LIST_RESP":
                # cbt.data contains a dict of peers
                self.__link_trimmer(cbt.data)

            else:
                log = '{0}: unrecognized CBT {1} received from {2}'\
                        .format(cbt.recipient, cbt.action, cbt.initiator)
                self.registerCBT('Logger', 'warning', log)

        # CBTs that required servicing by other modules are processed here
        else:
            # get the source CBT of this request
            sourceCBT_uid = self.checkMapping(cbt)
            self.pendingCBT[cbt.uid] = cbt

            # wait until all requested services are complete
            if self.allServicesCompleted(sourceCBT_uid):
                if self.pendingCBT[sourceCBT_uid].action in ['TINCAN_MSG', 'XMPP_MSG']:
                    msg = self.pendingCBT[sourceCBT_uid].data
                    msg_type = msg.get("type", None)
                    if msg_type in ["con_req","con_resp","con_ack"]:
                        for key in self.CBTMappings[sourceCBT_uid]:
                            if self.pendingCBT[key].action == 'QUERY_IPOP_STATE_RESP':
                                self.ipop_state = self.pendingCBT[key].data
                            elif self.pendingCBT[key].action == 'RESOLVE_RESP':
                                ip4 = self.pendingCBT[key].data
                            elif self.pendingCBT[key].action == 'QUERY_CONN_STAT_RESP':
                                conn_stat = self.pendingCBT[key].data
                            elif self.pendingCBT[key].action == 'QUERY_PEER_LIST_RESP':
                                peer_list = self.pendingCBT[key].data
                            elif self.pendingCBT[key].action == 'QUERY_IP_MAP_RESP':
                                ip_map = self.pendingCBT[key].data

                        # process the original CBT when all values have been received
                        self.log("Received {0} action of type {1}".format(self.pendingCBT[sourceCBT_uid].action,msg_type))

                        if self.CMConfig["multihop"]:
                            conn_cnt = 0
                            for k, v in peer_list.items():
                                if "fpr" in v and v["status"] == "online":
                                    conn_cnt += 1
                            if conn_cnt >= self.CMConfig["multihop_cl"]:
                                return
                        if self.check_collision(msg_type, msg["uid"], conn_stat):
                            return
                        fpr_len = len(self.ipop_state["_fpr"])
                        fpr = msg["data"][:fpr_len]
                        cas = msg["data"][fpr_len + 1:]
                        ip4 = ipoplib.gen_ip4(msg["uid"],
                                ip_map,
                                self.ipop_state["_ip4"])

                        if (msg_type == "con_resp"):
                            # My cas recvd from tin-can, send it wrapped in a 
                            # con_ack to peer
                            target_uid = msg["uid"]
                            data = msg["data"]
                            self.send_msg_srv("con_ack",target_uid,data)
                            log = "recv con_resp from Tincan for {0}".format(msg["uid"])
                            self.registerCBT('Logger', 'info', log)
                        else:
                            self.create_connection(msg["uid"], fpr, 0,
                                    self.CMConfig["sec"], cas, ip4)
    def processCBT(self, cbt):
        # new CBTs request for services from other modules by issuing CBTs; if no
        # services are required, the CBT is processed here only
        if not self.checkMapping(cbt):
            if cbt.action == "TINCAN_MSG":
                msg = cbt.data
                msg_type = msg.get("type", None)

                if msg_type == "con_req" or msg_type == "con_resp":
                    stateCBT = self.registerCBT('Watchdog', 'QUERY_IPOP_STATE')
                    self.CBTMappings[cbt.uid] = [stateCBT.uid]

                    mapCBT = self.registerCBT('AddressMapper', 'RESOLVE',
                                              msg['uid'])
                    self.CBTMappings[cbt.uid].append(mapCBT.uid)

                    ip_mapCBT = self.registerCBT('AddressMapper',
                                                 'QUERY_IP_MAP')
                    self.CBTMappings[cbt.uid].append(ip_mapCBT.uid)

                    conn_stat_CBT = self.registerCBT('Monitor',
                                                     'QUERY_CONN_STAT',
                                                     msg['uid'])
                    self.CBTMappings[cbt.uid].append(conn_stat_CBT.uid)

                    peer_list_CBT = self.registerCBT('Monitor',
                                                     'QUERY_PEER_LIST')
                    self.CBTMappings[cbt.uid].append(peer_list_CBT.uid)

                    self.pendingCBT[cbt.uid] = cbt

            elif cbt.action == "QUERY_PEER_LIST_RESP":
                # cbt.data contains a dict of peers
                self.__link_trimmer(cbt.data)

            else:
                log = '{0}: unrecognized CBT {1} received from {2}'\
                        .format(cbt.recipient, cbt.action, cbt.initiator)
                self.registerCBT('Logger', 'warning', log)

        # CBTs that required servicing by other modules are processed here
        else:
            # get the source CBT of this request
            sourceCBT_uid = self.checkMapping(cbt)
            self.pendingCBT[cbt.uid] = cbt

            # wait until all requested services are complete
            if self.allServicesCompleted(sourceCBT_uid):
                if self.pendingCBT[sourceCBT_uid].action == 'TINCAN_MSG':
                    msg = self.pendingCBT[sourceCBT_uid].data
                    msg_type = msg.get("type", None)
                    if msg_type == "con_req" or msg_type == "con_resp":
                        for key in self.CBTMappings[sourceCBT_uid]:
                            if self.pendingCBT[
                                    key].action == 'QUERY_IPOP_STATE_RESP':
                                self.ipop_state = self.pendingCBT[key].data
                            elif self.pendingCBT[key].action == 'RESOLVE_RESP':
                                ip4 = self.pendingCBT[key].data
                            elif self.pendingCBT[
                                    key].action == 'QUERY_CONN_STAT_RESP':
                                conn_stat = self.pendingCBT[key].data
                            elif self.pendingCBT[
                                    key].action == 'QUERY_PEER_LIST_RESP':
                                peer_list = self.pendingCBT[key].data
                            elif self.pendingCBT[
                                    key].action == 'QUERY_IP_MAP_RESP':
                                ip_map = self.pendingCBT[key].data

                        # process the original CBT when all values have been received
                        log = "received connection request/response"
                        self.registerCBT('Logger', 'info', log)

                        if self.CMConfig["multihop"]:
                            conn_cnt = 0
                            for k, v in peer_list.items():
                                if "fpr" in v and v["status"] == "online":
                                    conn_cnt += 1
                            if conn_cnt >= self.CMConfig["multihop_cl"]:
                                return
                        if self.check_collision(msg_type, msg["uid"],
                                                conn_stat):
                            return
                        fpr_len = len(self.ipop_state["_fpr"])
                        fpr = msg["data"][:fpr_len]
                        cas = msg["data"][fpr_len + 1:]
                        ip4 = ipoplib.gen_ip4(msg["uid"], ip_map,
                                              self.ipop_state["_ip4"])

                        self.create_connection(msg["uid"], fpr, 1,
                                               self.CMConfig["sec"], cas, ip4)
    def processCBT(self, cbt):
        # new CBTs request for services from other modules by issuing CBTs; if no
        # services are required, the CBT is processed here only
        if not self.checkMapping(cbt):
            if cbt.action == "TINCAN_MSG":
                msg = cbt.data
                msg_type = msg.get("type", None)

                if msg_type == "con_req" or msg_type == "con_resp":
                    stateCBT = self.registerCBT('Watchdog', 'QUERY_IPOP_STATE')
                    self.CBTMappings[cbt.uid] = [stateCBT.uid]

                    mapCBT = self.registerCBT('AddressMapper', 'RESOLVE', msg['uid'])
                    self.CBTMappings[cbt.uid].append(mapCBT.uid)

                    ip_mapCBT = self.registerCBT('AddressMapper', 'QUERY_IP_MAP')
                    self.CBTMappings[cbt.uid].append(ip_mapCBT.uid)

                    conn_stat_CBT = self.registerCBT('Monitor', 'QUERY_CONN_STAT', msg['uid'])
                    self.CBTMappings[cbt.uid].append(conn_stat_CBT.uid)

                    peer_list_CBT = self.registerCBT('Monitor', 'QUERY_PEER_LIST')
                    self.CBTMappings[cbt.uid].append(peer_list_CBT.uid)

                    self.pendingCBT[cbt.uid] = cbt

            elif cbt.action == "QUERY_PEER_LIST_RESP":
                # cbt.data contains a dict of peers
                self.__link_trimmer(cbt.data)

            else:
                log = '{0}: unrecognized CBT {1} received from {2}'\
                        .format(cbt.recipient, cbt.action, cbt.initiator)
                self.registerCBT('Logger', 'warning', log)

        # CBTs that required servicing by other modules are processed here
        else:
            # get the source CBT of this request
            sourceCBT_uid = self.checkMapping(cbt)
            self.pendingCBT[cbt.uid] = cbt

            # wait until all requested services are complete
            if self.allServicesCompleted(sourceCBT_uid):
                if self.pendingCBT[sourceCBT_uid].action == 'TINCAN_MSG':
                    msg = self.pendingCBT[sourceCBT_uid].data
                    msg_type = msg.get("type", None)
                    if msg_type == "con_req" or msg_type == "con_resp":
                        for key in self.CBTMappings[sourceCBT_uid]:
                            if self.pendingCBT[key].action == 'QUERY_IPOP_STATE_RESP':
                                self.ipop_state = self.pendingCBT[key].data
                            elif self.pendingCBT[key].action == 'RESOLVE_RESP':
                                ip4 = self.pendingCBT[key].data
                            elif self.pendingCBT[key].action == 'QUERY_CONN_STAT_RESP':
                                conn_stat = self.pendingCBT[key].data
                            elif self.pendingCBT[key].action == 'QUERY_PEER_LIST_RESP':
                                peer_list = self.pendingCBT[key].data
                            elif self.pendingCBT[key].action == 'QUERY_IP_MAP_RESP':
                                ip_map = self.pendingCBT[key].data

                        # process the original CBT when all values have been received
                        log = "received connection request/response"
                        self.registerCBT('Logger', 'info', log)

                        if self.CMConfig["multihop"]:
                            conn_cnt = 0
                            for k, v in peer_list.items():
                                if "fpr" in v and v["status"] == "online":
                                    conn_cnt += 1
                            if conn_cnt >= self.CMConfig["multihop_cl"]:
                                return
                        if self.check_collision(msg_type, msg["uid"], conn_stat):
                            return
                        fpr_len = len(self.ipop_state["_fpr"])
                        fpr = msg["data"][:fpr_len]
                        cas = msg["data"][fpr_len + 1:]
                        ip4 = ipoplib.gen_ip4(msg["uid"],
                                ip_map,
                                self.ipop_state["_ip4"])

                        self.create_connection(msg["uid"], fpr, 1,
                                self.CMConfig["sec"], cas, ip4)
Exemple #7
0
    def processCBT(self, cbt):

        if(cbt.action == 'ADD_MAPPING'):

            try:
                # cbt.data is a dict with uid and ip keys
                self.ip_map[cbt.data['uid']] = cbt.data['ip']
            except KeyError:

                logCBT = self.CFxHandle.createCBT(initiator='AddressMapper',
                                                  recipient='Logger',
                                                  action='warning',
                                                  data="Invalid ADD_MAPPING"
                                                  " Configuration")
                self.CFxHandle.submitCBT(logCBT)

        elif(cbt.action == 'DEL_MAPPING'):

            self.ip_map.pop(cbt.data)  # Remove mapping if it exists

        elif(cbt.action == 'RESOLVE'):

            # Modify the CBT with the response data and send it back
            cbt.action = 'RESOLVE_RESP'

            # Compute the IP4 address
            cbt.data = ipoplib.gen_ip4(cbt.data, self.ip_map, self.CMConfig["ip4"])

            # Swap inititator and recipient
            cbt.initiator, cbt.recipient = cbt.recipient, cbt.initiator

            self.CFxHandle.submitCBT(cbt)

        elif (cbt.action == 'QUERY_IP_MAP'):

            cbt.action = 'QUERY_IP_MAP_RESP'

            cbt.data = self.ip_map
            cbt.initiator, cbt.recipient = cbt.recipient, cbt. initiator
            self.CFxHandle.submitCBT(cbt)

        elif(cbt.action == 'REVERSE_RESOLVE'):

            # Modify the CBT with the response data and send it back
            cbt.action = 'REVERSE_RESOLVE_RESP'
            ip = cbt.data
            cbt.data = None
            # Iterate through all items in dict for reverse lookup
            for key, value in self.ip_map.items():
                if(value == ip):
                    cbt.data = key
                    break

            # Swap inititator and recipient
            cbt.initiator, cbt.recipient = cbt.recipient, cbt.initiator

            self.CFxHandle.submitCBT(cbt)

        else:
            logCBT = self.CFxHandle.createCBT(initiator='AddressMapper',
                                              recipient='Logger',
                                              action='warning',
                                              data="AddressMapper: "
                                              "Invalid CBT received"
                                              " from " + cbt.initiator)
            self.CFxHandle.submitCBT(logCBT)
    def processCBT(self, cbt):
        # new CBTs request for services from other modules by issuing CBTs; if no
        # services are required, the CBT is processed here.
        # con_ack packages and moves cas over XMPP/Overlay
        # con_resp is cas received from tin-can after transport allocation is done.
        if not self.checkMapping(cbt):
            if cbt.action in ["TINCAN_MSG", "XMPP_MSG"]:
                msg = cbt.data
                msg_type = msg.get("type", None)

                if msg_type in ["con_req", "con_resp", "con_ack"]:
                    stateCBT = self.registerCBT('Watchdog', 'QUERY_IPOP_STATE')
                    self.CBTMappings[cbt.uid] = [stateCBT.uid]

                    mapCBT = self.registerCBT('AddressMapper', 'RESOLVE',
                                              msg['uid'])
                    self.CBTMappings[cbt.uid].append(mapCBT.uid)

                    ip_mapCBT = self.registerCBT('AddressMapper',
                                                 'QUERY_IP_MAP')
                    self.CBTMappings[cbt.uid].append(ip_mapCBT.uid)

                    conn_stat_CBT = self.registerCBT('Monitor',
                                                     'QUERY_CONN_STAT',
                                                     msg['uid'])
                    self.CBTMappings[cbt.uid].append(conn_stat_CBT.uid)

                    peer_list_CBT = self.registerCBT('Monitor',
                                                     'QUERY_PEER_LIST')
                    self.CBTMappings[cbt.uid].append(peer_list_CBT.uid)

                    self.pendingCBT[cbt.uid] = cbt
                    self.log("put in cbt queue {0}".format(msg_type))

            elif cbt.action == "QUERY_PEER_LIST_RESP":
                # cbt.data contains a dict of peers
                self.__link_trimmer(cbt.data)

            else:
                log = '{0}: unrecognized CBT {1} received from {2}'\
                        .format(cbt.recipient, cbt.action, cbt.initiator)
                self.registerCBT('Logger', 'warning', log)

        # CBTs that required servicing by other modules are processed here
        else:
            # get the source CBT of this request
            sourceCBT_uid = self.checkMapping(cbt)
            self.pendingCBT[cbt.uid] = cbt

            # wait until all requested services are complete
            if self.allServicesCompleted(sourceCBT_uid):
                if self.pendingCBT[sourceCBT_uid].action in [
                        'TINCAN_MSG', 'XMPP_MSG'
                ]:
                    msg = self.pendingCBT[sourceCBT_uid].data
                    msg_type = msg.get("type", None)
                    if msg_type in ["con_req", "con_resp", "con_ack"]:
                        for key in self.CBTMappings[sourceCBT_uid]:
                            if self.pendingCBT[
                                    key].action == 'QUERY_IPOP_STATE_RESP':
                                self.ipop_state = self.pendingCBT[key].data
                            elif self.pendingCBT[key].action == 'RESOLVE_RESP':
                                ip4 = self.pendingCBT[key].data
                            elif self.pendingCBT[
                                    key].action == 'QUERY_CONN_STAT_RESP':
                                conn_stat = self.pendingCBT[key].data
                            elif self.pendingCBT[
                                    key].action == 'QUERY_PEER_LIST_RESP':
                                peer_list = self.pendingCBT[key].data
                            elif self.pendingCBT[
                                    key].action == 'QUERY_IP_MAP_RESP':
                                ip_map = self.pendingCBT[key].data

                        # process the original CBT when all values have been received
                        self.log("Received {0} action of type {1}".format(
                            self.pendingCBT[sourceCBT_uid].action, msg_type))

                        if self.CMConfig["multihop"]:
                            conn_cnt = 0
                            for k, v in peer_list.items():
                                if "fpr" in v and v["status"] == "online":
                                    conn_cnt += 1
                            if conn_cnt >= self.CMConfig["multihop_cl"]:
                                return
                        if self.check_collision(msg_type, msg["uid"],
                                                conn_stat):
                            return
                        fpr_len = len(self.ipop_state["_fpr"])
                        fpr = msg["data"][:fpr_len]
                        cas = msg["data"][fpr_len + 1:]
                        ip4 = ipoplib.gen_ip4(msg["uid"], ip_map,
                                              self.ipop_state["_ip4"])

                        if (msg_type == "con_resp"):
                            # My cas recvd from tin-can, send it wrapped in a
                            # con_ack to peer
                            target_uid = msg["uid"]
                            data = msg["data"]
                            self.send_msg_srv("con_ack", target_uid, data)
                            log = "recv con_resp from Tincan for {0}".format(
                                msg["uid"])
                            self.registerCBT('Logger', 'info', log)
                        else:
                            self.create_connection(msg["uid"], fpr, 0,
                                                   self.CMConfig["sec"], cas,
                                                   ip4)
    def processCBT(self, cbt):

        # In case of a fresh CBT, request the required services
        # from the other modules, by issuing CBTs. If no services
        # from other modules required, process the CBT here only
        if(not self.checkMapping(cbt)):
            if(cbt.action == "TINCAN_MSG"):
                msg = cbt.data
                msg_type = msg.get("type", None)

                # we ignore connection status notification for now
                if msg_type == "con_stat":
                    pass

                elif msg_type == "con_req" or msg_type == "con_resp":
                    stateCBT = self.CFxHandle.createCBT(initiator='Base'
                                                        'TopologyManager',
                                                        recipient='Watchdog',
                                                        action='QUERY_IPOP'
                                                        '_STATE',
                                                        data="")
                    self.CFxHandle.submitCBT(stateCBT)
                    self.CBTMappings[cbt.uid] = [stateCBT.uid]

                    mapCBT = self.CFxHandle.createCBT(initiator='BaseTopology'
                                                      'Manager',
                                                      recipient='Address'
                                                      'Mapper',
                                                      action='RESOLVE',
                                                      data=msg['uid'])
                    self.CFxHandle.submitCBT(mapCBT)
                    self.CBTMappings[cbt.uid].append(mapCBT.uid)

                    ip_mapCBT = self.CFxHandle.createCBT(initiator='Base'
                                                         'TopologyManager',
                                                         recipient='Address'
                                                         'Mapper',
                                                         action='QUERY_IP_MAP',
                                                         data="")
                    self.CFxHandle.submitCBT(ip_mapCBT)
                    self.CBTMappings[cbt.uid].append(ip_mapCBT.uid)

                    conn_stat_CBT = self.CFxHandle.createCBT(initiator='Base'
                                                             'TopologyManager',
                                                             recipient='Monitor',
                                                             action='QUERY_'
                                                             'CONN_STAT',
                                                             data=msg['uid'])
                    self.CFxHandle.submitCBT(conn_stat_CBT)
                    self.CBTMappings[cbt.uid].append(conn_stat_CBT.uid)

                    peer_list_CBT = self.CFxHandle.createCBT(initiator='Base'
                                                             'TopologyManager',
                                                             recipient='Monitor',
                                                             action='QUERY_'
                                                             'PEER_LIST',
                                                             data='')
                    self.CFxHandle.submitCBT(peer_list_CBT)
                    self.CBTMappings[cbt.uid].append(peer_list_CBT.uid)

                    # Add CBT to pendingCBT dictionary
                    self.pendingCBT[cbt.uid] = cbt

                # Pass for now
                elif msg_type == "send_msg":
                    pass

            elif(cbt.action == "QUERY_PEER_LIST_RESP"):

                # cbt.data is a dict of peers
                self.__link_trimmer(cbt.data)

            else:
                logCBT = self.CFxHandle.createCBT(initiator='BaseTopology'
                                                  'Manager',
                                                  recipient='Logger',
                                                  action='warning',
                                                  data="BaseTopologyManager:"
                                                  " Unrecognized CBT "
                                                  "from " + cbt.initiator)
                self.CFxHandle.submitCBT(logCBT)

        # Case when one of the requested service CBT comes back

        else:
            # Get the source CBT of this request
            sourceCBT_uid = self.checkMapping(cbt)
            self.pendingCBT[cbt.uid] = cbt
            # If all the other services of this sourceCBT are also completed,
            # process CBT here. Else wait for other CBTs to arrive
            if(self.allServicesCompleted(sourceCBT_uid)):
                if(self.pendingCBT[sourceCBT_uid].action == 'TINCAN_MSG'):
                    msg = self.pendingCBT[sourceCBT_uid].data
                    msg_type = msg.get("type", None)
                    if msg_type == "con_req" or msg_type == "con_resp":
                        for key in self.CBTMappings[sourceCBT_uid]:
                            if(self.pendingCBT[key].action ==
                                    'QUERY_IPOP_STATE_RESP'):
                                self.ipop_state = self.pendingCBT[key].data
                            elif(self.pendingCBT[key].action ==
                                    'RESOLVE_RESP'):
                                ip4 = self.pendingCBT[key].data
                            elif(self.pendingCBT[key].action ==
                                    'QUERY_CONN_STAT_RESP'):
                                conn_stat = self.pendingCBT[key].data
                            elif(self.pendingCBT[key].action ==
                                    'QUERY_PEER_LIST_RESP'):
                                peer_list = self.pendingCBT[key].data
                            elif(self.pendingCBT[key].action ==
                                    'QUERY_IP_MAP_RESP'):
                                ip_map = self.pendingCBT[key].data

                        logCBT = self.CFxHandle.createCBT(initiator='Base'
                                                          'TopologyManager',
                                                          recipient='Logger',
                                                          action='info',
                                                          data="Received"
                                                          " connection request"
                                                          "/response")
                        self.CFxHandle.submitCBT(logCBT)

                        if self.CMConfig["multihop"]:
                            conn_cnt = 0
                            for k, v in peer_list.iteritems():
                                if "fpr" in v and v["status"] == "online":
                                    conn_cnt += 1
                            if conn_cnt >= self.CMConfig["multihop_cl"]:
                                return
                        if self.check_collision(msg_type, msg["uid"],
                                                conn_stat):
                            return
                        fpr_len = len(self.ipop_state["_fpr"])
                        fpr = msg["data"][:fpr_len]
                        cas = msg["data"][fpr_len + 1:]
                        ip4 = ipoplib.gen_ip4(msg["uid"],
                                              ip_map,
                                              self.ipop_state["_ip4"])
                        self.create_connection(msg["uid"], fpr, 1,
                                               self.CMConfig["sec"], cas, ip4)