def cmd_connect(self, req): url = self.match.find(req.dstaddr, req.dstport, proto="tcp") if not url: # no rule found, go as local socks proxy handler = SocksSession(self.socksconn) self.handler = handler handler.proc_tcp_request(req) handler.relay_tcp() else: if url.scheme != 'socks5': raise SmartRelayError("forward url %s not supported" % str(url)) self.smart_socks_tcp(url, req)
def cmd_udp_associate(self, req): local_handler = SocksSession(self.socksconn) self.handler = local_handler if local_handler.proc_udp_request(req): # a UDP session is determined by first UDP packet firstdata, firstaddr = local_handler.wait_for_first_udp() url = self.match.find(firstaddr[0], firstaddr[1], proto="udp") if not url: # no rule found, go as local socks proxy local_handler.relay_udp(firstdata, firstaddr) else: if url.scheme != 'socks5': raise SmartRelayError("forward url %s not supported" % str(url)) self.smart_socks_udp(url, local_handler, firstdata, firstaddr)
def cmd_connect(self, req): dst = self.matcher.find(req.dstaddr, req.dstport, proto="tcp") if not dst: # no forward schemes found, go as local socks proxy handler = SocksSession(self.socksconn) self.handler = handler handler.proc_tcp_request(req) handler.relay_tcp() else: self.forward_tcp(dst, req)
def cmd_udp_associate(self, req): handler = SocksSession(self.socksconn) self.handler = handler if handler.proc_udp_request(req): # a UDP session is determined by first UDP packet firstdata, firstaddr = handler.wait_for_first_udp() scheme = self.matcher.find(firstaddr[0], firstaddr[1], proto="udp") if not scheme: # no forward schemes found, go as local socks proxy handler.relay_udp(firstdata, firstaddr) else: self.forward_udp(scheme, handler, firstdata, firstaddr)