<commit_before>#!/usr/bin/env python


from .base import Socks5Connection

from fukei.config import Config
import socket
import logging 

logger = logging.getLogger('connection.local')

class LocalConnection(Socks5Connection):

    """LocalSocksServer"""

    # def __init__(self, stream, address, upstream_cls=None)

    #     super(LocalConncection, self).__init__(stream, address, upstream_cls)

    def on_connected(self):
        logger.debug('start connect...')
        self.stream.set_close_callback(self.on_connection_close)
        self.stream.read_bytes(2, self.on_auth_num_methods)


    def do_connect(self):
    	config = Config.current()
        logger.error( "add type : %s " % socket.AF_INET)

        self.upstream = self.upstream_cls((config.server, config.server_port),
                            socket.AF_INET,
                            self.on_upstream_connect, self.on_upstream_error,
                            self.on_upstream_data, self.on_upstream_close)

    def on_upstream_connect(self, _dummy):
        self.write_reply(0x00, socket.inet_aton('0.0.0.0') + struct.pack("!H", config.server_port))
        on_finish = functools.partial(self.on_socks_data, finished=True)
        #self.upstream.write()
        self.stream.read_until_close(on_finish, self.on_socks_data)<commit_msg>Fixed local connection unimport struct and functools , and added write request handle remote server<commit_after>#!/usr/bin/env python


from .base import Socks5Connection

from fukei.config import Config
import socket
import struct
import logging 
import functools

logger = logging.getLogger('connection.local')

class LocalConnection(Socks5Connection):

    """LocalSocksServer"""

    # def __init__(self, stream, address, upstream_cls=None)

    #     super(LocalConncection, self).__init__(stream, address, upstream_cls)

    def on_connected(self):
        logger.debug('start connect...')
        self.stream.set_close_callback(self.on_connection_close)
        self.stream.read_bytes(2, self.on_auth_num_methods)



    def do_connect(self):
    	config = Config.current()
        
        logger.info("server : %s, %s" % (config.server, config.server_port))
        logger.info("server dest: %s, %s" % self.dest)
        dest = (config.server, config.server_port)
        self.upstream = self.upstream_cls( dest, socket.AF_INET,
                            self.on_upstream_connect, self.on_upstream_error,
                            self.on_upstream_data, self.on_upstream_close)

    def on_upstream_connect(self, _dummy):
        config = Config.current()
        #self.write_reply(0x00, socket.inet_aton('0.0.0.0') + struct.pack("!H", config.server_port))
        on_finish = functools.partial(self.on_socks_data, finished=True)
        #self.write_request()
        self.stream.read_until_close(on_finish, self.on_socks_data)

    def write_request(self, data=None):
        logger.info('wait request...')
        address_type = self.atyp
        if data is None:
            if self.dest:
                data = self.raw_dest_addr + self.raw_dest_port
            else:
                data = struct.pack("!BLH", 0x01, 0x00, 0x00)
        else:
            if self.atyp == 0x03:
                address_type = 0x01
        self.upstream.write(struct.pack("!BBBB", self.ver, 0x01, 0x00, socket.AF_INET
                                      ) + data)
        # logger.debug("sent request: %s" % (self.REPLY_CODES.get(
        #     code, "UNKNOWN REPLY")))
{'fraction_non_alphanumeric': 0.11021814006888633, 'fraction_numerical': 0.011768082663605052, 'mean_word_length': 2.715351812366738, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1649794', 'n_tokens_mistral': 1126, 'n_tokens_neox': 1082, 'n_words': 197}