def init_func(self, creator_fd, dns_fd, whitelist, debug=False): taddr = fnc_config.configs["tcp_server_address"] s = socket.socket() self.set_socket(s) self.connect(taddr, 6) crypto_info = fnc_config.configs["tcp_crypto_module"] name = crypto_info["name"] args = crypto_info["args"] name = "freenet.lib.crypto.%s" % name __import__(name) m = sys.modules[name] self.__encrypt = m.encrypt(*args) self.__decrypt = m.decrypt(*args) self.__debug = debug self.__static_nat = static_nat.nat() self.__dns_fd = dns_fd self.__traffic_send_fd = self.create_handler(self.fileno, traffic_pass.traffic_send) self.__timer = timer.timer() self.__udp_proxy_map = {} # 如果是非全局UDP代理,那么开启UDP白名单模式 if not fnc_config.configs["udp_global"]: self.__udp_whitelist = udp_whitelist.whitelist() for subn, mask in whitelist: self.__udp_whitelist.add_rule(subn, mask) if not self.__debug: sys.stdout = open(fnc_config.configs["access_log"], "a+") sys.stderr = open(fnc_config.configs["error_log"], "a+") return self.fileno
def init_func(self, creator_fd, dns_fd, raw_socket_fd, whitelist, debug=False): self.__nat = static_nat.nat() self.__server = fnc_config.configs["udp_server_address"] name = "freenet.lib.crypto.%s" % fnc_config.configs["udp_crypto_module"]["name"] __import__(name) m = sys.modules.get(name, None) crypto_args = fnc_config.configs["udp_crypto_module"].get("args", ()) self.__encrypt_m = m.encrypt(*crypto_args) self.__decrypt_m = m.decrypt(*crypto_args) self.__debug = debug self.__timer = timer.timer() self.__traffic_send_fd = raw_socket_fd s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.set_socket(s) self.__dns_fd = dns_fd try: self.connect(self.__server) except socket.gaierror: self.dispatcher.ctunnel_fail() return -1 ipaddr, _ = s.getpeername() self.__server_ipaddr = ipaddr self.register(self.fileno) self.add_evt_read(self.fileno) self.__udp_proxy_map = {} # 如果是非全局UDP代理,那么开启UDP白名单模式 if not fnc_config.configs["udp_global"]: self.__udp_whitelist = udp_whitelist.whitelist() for subn, mask in whitelist: self.__udp_whitelist.add_rule(subn, mask) if not self.__debug: sys.stdout = open(fnc_config.configs["access_log"], "a+") sys.stderr = open(fnc_config.configs["error_log"], "a+") self.__force_udp_global_clients = {} for client_ip in fnc_config.configs["udp_force_global_clients"]: saddr = socket.inet_aton(client_ip) self.__force_udp_global_clients[saddr] = None self.fn_init() self.fn_auth_request() self.set_timeout(self.fileno, self.__TIMEOUT_NO_AUTH) return self.fileno
def init_func(self, creator_fd, dns_fd, whitelist, debug=False): self.__nat = static_nat.nat() self.__server = fnc_config.configs["udp_server_address"] name = "freenet.lib.crypto.%s" % fnc_config.configs[ "udp_crypto_module"]["name"] __import__(name) m = sys.modules.get(name, None) crypto_args = fnc_config.configs["udp_crypto_module"].get("args", ()) self.__encrypt_m = m.encrypt(*crypto_args) self.__decrypt_m = m.decrypt(*crypto_args) self.__debug = debug self.__timer = timer.timer() self.__traffic_send_fd = self.create_handler(self.fileno, traffic_pass.traffic_send) s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.set_socket(s) self.__dns_fd = dns_fd try: self.connect(self.__server) except socket.gaierror: self.dispatcher.ctunnel_fail() return -1 ipaddr, _ = s.getpeername() self.__server_ipaddr = ipaddr self.register(self.fileno) self.add_evt_read(self.fileno) self.__udp_proxy_map = {} # 如果是非全局UDP代理,那么开启UDP白名单模式 if not fnc_config.configs["udp_global"]: self.__udp_whitelist = udp_whitelist.whitelist() for subn, mask in whitelist: self.__udp_whitelist.add_rule(subn, mask) if not self.__debug: sys.stdout = open(fnc_config.configs["access_log"], "a+") sys.stderr = open(fnc_config.configs["error_log"], "a+") self.fn_init() self.fn_auth_request() self.set_timeout(self.fileno, self.__TIMEOUT_NO_AUTH) return self.fileno
def create_fn_server(self): name = "freenet.tunnels_auth.%s" % fns_config.configs["auth_module"] __import__(name) m = sys.modules[name] auth_module = m.auth() auth_module.init() if not self.debug: sys.stdout = open(fns_config.configs["access_log"], "a+") sys.stderr = open(fns_config.configs["error_log"], "a+") subnet = fns_config.configs["subnet"] nat = static_nat.nat(subnet) subnet = fns_config.configs["subnet"] tun_fd = self.create_handler(-1, tundev.tuns, "fdslight", subnet, nat) dns_fd = self.create_handler(-1, dns_proxy.dnsd_proxy, fns_config.configs["dns"]) self.get_handler(dns_fd).set_dns_id_max( int(fns_config.configs["max_dns_request"])) args = (tun_fd, -1, dns_fd, auth_module) kwargs = {"debug": self.debug} self.create_handler(-1, tunnels_udp.tunnels_udp_listener, *args, **kwargs) self.create_handler(-1, tunnels_tcp.tunnel_tcp_listener, *args, **kwargs) if fns_config.configs["enable_ipv6_tunnel"]: kwargs["is_ipv6"] = True self.create_handler(-1, tunnels_udp.tunnels_udp_listener, *args, **kwargs) self.create_handler(-1, tunnels_tcp.tunnel_tcp_listener, *args, **kwargs) return