def udp_readable(self, message, address): addr_id = "%s-%s" % address if addr_id not in self.__permits: return self.__update_time = time.time() n_saddr = socket.inet_aton(address[0]) sport = address[1] if self.__is_ipv6: mtu = 1280 else: mtu = 1500 udp_packets = ippkts.build_udp_packets(n_saddr, self.__byte_internal_ip, sport, self.__port, message, mtu=mtu, is_udplite=self.__is_udplite, is_ipv6=self.__is_ipv6) for udp_pkt in udp_packets: self.dispatcher.send_msg_to_tunnel_from_p2p_proxy( self.__session_id, udp_pkt) return
def __handle_msg_from_response(self, message): try: msg = dns.message.from_wire(message) except: return dns_id = (message[0] << 8) | message[1] if not self.dns_id_map_exists(dns_id): return saddr, daddr, dport, n_dns_id, flags, is_ipv6 = self.get_dns_id_map(dns_id) self.del_dns_id_map(dns_id) L = list(message) L[0:2] = ( (n_dns_id & 0xff00) >> 8, n_dns_id & 0xff, ) message = bytes(L) for rrset in msg.answer: for cname in rrset: ip = cname.__str__() if utils.is_ipv4_address(ip): self.__set_route(ip, flags, is_ipv6=False) if utils.is_ipv6_address(ip): self.__set_route(ip, flags, is_ipv6=True) '''''' '''''' if not self.__server_side: if self.__is_ipv6: mtu = 1280 else: mtu = 1500 packets = ippkts.build_udp_packets(saddr, daddr, 53, dport, message, mtu=mtu, is_ipv6=self.__is_ipv6) for packet in packets: self.dispatcher.send_msg_to_tun(packet) self.del_dns_id_map(dns_id) self.__timer.drop(dns_id) return if self.__is_ipv6 != is_ipv6 and self.__server_side: if self.__is_ipv6: is_ipv6 = False else: is_ipv6 = True self.dispatcher.send_msg_to_other_dnsservice_for_dns_response(message, is_ipv6=is_ipv6) if self.__is_ipv6: sts_daddr = socket.inet_ntop(socket.AF_INET6, daddr) else: sts_daddr = socket.inet_ntop(socket.AF_INET, daddr) self.del_dns_id_map(dns_id) self.__timer.drop(dns_id) self.sendto(message, (sts_daddr, dport)) self.add_evt_write(self.fileno)
def udp_readable(self, message, address): addr_id = "%s-%s" % address if addr_id not in self.__permits: return n_saddr = socket.inet_aton(address[0]) sport = address[1] udp_packets = ippkts.build_udp_packets(n_saddr, self.__byte_internal_ip, sport, self.__port, message, mtu=self.__mtu, is_udplite=self.__is_udplite, is_ipv6=self.__is_ipv6) self.__packets += udp_packets self.__send_to_tunnel()