def __init__(self, CONFIG_, logger, observerable, run_event):

        #super(IpopController, self).__init__("controller")
        #self.observable = observer.Observable()
        #self.observable.register(self)

        global CONFIG
        CONFIG = CONFIG_
        self.run_event = run_event
        self.observable = observerable
        il.UdpServer.__init__(self, CONFIG["xmpp_username"], 
          CONFIG["xmpp_password"], CONFIG["xmpp_host"], CONFIG["ip4"], logger)
        self.idle_peers = {}
        self.user = CONFIG["xmpp_username"] # XMPP username
        self.password = CONFIG["xmpp_password"] # XMPP Password
        self.host = CONFIG["xmpp_host"] # XMPP host
        self.ip4 = CONFIG["ip4"]
        self.uid = il.gen_uid(self.ip4) # SHA-1 hash
        self.vpn_type = CONFIG["controller_type"]
        self.ctrl_conn_init()
        global logging
        print dir(logger)
        logging = logger
        print dir(logging)
        logging.error("what")

        self.uid_ip_table = {}
        parts = CONFIG["ip4"].split(".")
        ip_prefix = parts[0] + "." + parts[1] + "."
        # Populating the uid_ip_table with all the IPv4 addresses
        # and the corresponding UIDs in the /16 subnet
        for i in range(0, 255):
            for j in range(0, 255):
                ip = ip_prefix + str(i) + "." + str(j)
                uid = il.gen_uid(ip)
                self.uid_ip_table[uid] = ip

        # Ignore the network interfaces in the list
        if "network_ignore_list" in CONFIG:
            logging.debug("network ignore list")
            il.make_call(self.sock, m="set_network_ignore_list",\
                      network_ignore_list=CONFIG["network_ignore_list"])
    def create_connection_req(self, data, idle_peers):
        version_ihl = struct.unpack('!B', data[54:55])
        version = version_ihl[0] >> 4
        if version == 4:
            s_addr = socket.inet_ntoa(data[66:70])
            d_addr = socket.inet_ntoa(data[70:74])
        elif version == 6:
            s_addr = socket.inet_ntop(socket.AF_INET6, data[62:78])
            d_addr = socket.inet_ntop(socket.AF_INET6, data[78:94])

            # At present, we do not handle ipv6 multicast
            if d_addr.startswith("ff02"):
                return

        uid = ipoplib.gen_uid(d_addr)

        try:
            msg = idle_peers[uid]
        except KeyError:
            logCBT = self.CFxHandle.createCBT(initiator='BaseTopology'
                                              'Manager',
                                              recipient='Logger',
                                              action='error',
                                              data="Peer {0} is not "
                                              "logged in".format(d_addr))
            self.CFxHandle.submitCBT(logCBT)
            return

        logCBT = self.CFxHandle.createCBT(initiator='BaseTopology'
                                          'Manager',
                                          recipient='Logger',
                                          action='debug',
                                          data="idle_peers[uid]"
                                          " --- {0}".format(msg))
        self.CFxHandle.submitCBT(logCBT)

        cbt_data = {
            'uid': uid,
            'idle_peers': idle_peers,
            'send_req': True
        }

        CBT = self.CFxHandle.createCBT(initiator='BaseTopologyManager',
                                       recipient='BaseTopologyManager',
                                       action='ONDEMAND_CONNECTION',
                                       data=cbt_data)
        self.CFxHandle.submitCBT(CBT)
    def initialize(self):

        # Populating the uid_ip_table with all the IPv4 addresses
        # and the corresponding UIDs in the /16 subnet
        parts = self.CMConfig["ip4"].split(".")
        ip_prefix = parts[0] + "." + parts[1] + "."
        for i in range(0, 255):
            for j in range(0, 255):
                ip = ip_prefix + str(i) + "." + str(j)
                uid = gen_uid(ip)
                self.uid_ip_table[uid] = ip

        logCBT = self.CFxHandle.createCBT(initiator='AddressMapper',
                                          recipient='Logger',
                                          action='info',
                                          data="AddressMapper Loaded")
        self.CFxHandle.submitCBT(logCBT)
示例#4
0
    def __init__(self):

        with open('config.json') as data_file:

            # Read config.json into an OrderedDict, to load the
            # modules in the order in which they appear in config.json
            self.json_data = json.load(data_file,
                                       object_pairs_hook=OrderedDict)

        # Parse config and update default CONFIG in ipoplib
        self.parse_config()
        ipoplib.CONFIG = self.CONFIG

        # CFxHandleDict is a dict containing the references to
        # CFxHandles of all CMs with key as the module name and
        # value as the CFxHandle reference
        self.CFxHandleDict = {}

        self.vpn_type = self.CONFIG['CFx']['vpn_type']
        self.user = self.CONFIG['CFx']["xmpp_username"]
        self.password = self.CONFIG['CFx']["xmpp_password"]
        self.host = self.CONFIG['CFx']["xmpp_host"]
        self.ip4 = self.CONFIG['AddressMapper']["ip4"]
        if(self.vpn_type == 'GroupVPN'):
            self.uid = ipoplib.gen_uid(self.ip4)  # SHA-1 Hash
        elif(self.vpn_type == 'SocialVPN'):
            self.uid = self.CONFIG['CFx']['local_uid']
        self.ip6 = ipoplib.gen_ip6(self.uid)

        if socket.has_ipv6:
            self.sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
            self.sock_svr = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
            self.sock_svr.bind((self.CONFIG['TincanSender']["localhost6"],
                                self.CONFIG['CFx']["contr_port"]))
        else:
            self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            self.sock_svr = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            self.sock_svr.bind((self.CONFIG['TincanSender']["localhost"],
                                self.CONFIG['CFx']["contr_port"]))
        self.sock.bind(("", 0))
        self.sock_list = [self.sock, self.sock_svr]