def ctrl_conn_init(self):
        il.do_set_logging(self.sock, CONFIG["tincan_logging"])

        # Callback endpoint to receive notifications
        il.do_set_cb_endpoint(self.sock, self.sock.getsockname()) 

        il.do_set_local_ip(self.sock, self.uid, self.ip4, il.gen_ip6(self.uid),
                           CONFIG["ip4_mask"], CONFIG["ip6_mask"], 
                           CONFIG["subnet_mask"], CONFIG["switchmode"],
                           CONFIG["mtu"], CONFIG["internal_mtu"])

        # Register to the XMPP server
        il.do_register_service(self.sock, self.user, self.password, self.host) 
        il.do_set_switchmode(self.sock, CONFIG["switchmode"])
        il.do_set_trimpolicy(self.sock, CONFIG["trim_enabled"])
        il.do_get_state(self.sock) # Information about the local node
Esempio n. 2
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]
 def create_connection(self, uid, data, nid, sec, cas, ip4):
     il.do_create_link(self.sock, uid, data, nid, sec, cas)
     if (CONFIG["switchmode"] == 1):
         il.do_set_remote_ip(self.sock, uid, ip4, il.gen_ip6(uid))
     else: 
         il.do_set_remote_ip(self.sock, uid, ip4, il.gen_ip6(uid))