Ejemplo n.º 1
0
    def run(self):
        general_logger.info('Compressor Thread Started')
        original_size = 0
        compressed_size = 0

        with open(f'sample/client/{self.filename}', 'rb') as f:
            while True:
                data = f.read(self.block_size)
                original_size += len(data)
                if len(data) < self.block_size:
                    if len(data):
                        compressed_data = self.compress(data)
                        compressed_size += len(compressed_data)
                        self.send_to_encryption(compressed_data)
                    break
                else:
                    compressed_data = self.compress(data)
                    compressed_size += len(compressed_data)
                    self.send_to_encryption(compressed_data)

        self.send_to_encryption(None)
        general_logger.info('Original Size: %s bytes', original_size)
        general_logger.info('Compressed Size: %s bytes', compressed_size)
        general_logger.info('Compression Ratio: %lf',
                            compressed_size / original_size)
        general_logger.info('Compressor Thread Exited')
Ejemplo n.º 2
0
    def send(self):
        try:
            self.send_filename(self.filename)
            self.send_file()
            general_logger.info('File (%s) sent.', self.filename)

        except:
            general_logger.error('Sending File failed', exc_info=True)
Ejemplo n.º 3
0
    def run(self):
        general_logger.info('Encryptor Thread Started')
        
        while True:
            compressed_data = self.read_from_compression()
            if compressed_data is None:
                break
            encrypted_data = self.encrypt(compressed_data)
            self.send_to_transmission(encrypted_data)

        self.send_to_transmission(None)
        general_logger.info('Encryptor Thread Exited')
Ejemplo n.º 4
0
    def send_file(self):
        try:
            total_size = 0
            while True:
                encrypted_data = self.read_from_encryption()
                if encrypted_data is None:
                    break
                total_size += len(encrypted_data)
                self.send_data(encrypted_data)
            general_logger.info('Total encrypted file size: %s', total_size)

        except:
            general_logger.error('Sending file failed.', exc_info=True)
Ejemplo n.º 5
0
    def __init__(self, et_queue, server_ip, server_port, filename):
        super(Client, self).__init__()

        self.server_ip = server_ip
        self.server_port = int(server_port)
        self.filename = filename
        self.et_queue = et_queue

        try:
            self.socket = socket(AF_INET, SOCK_STREAM)
            while True:
                try:
                    self.socket.connect((self.server_ip, self.server_port))
                    break
                except:
                    # general_logger.info('Server not ready, %s:%d', self.server_ip, self.server_port)
                    pass
            general_logger.info('Client now connected to: %s with port %s', self.server_ip, self.server_port)

        except:
            general_logger.error('Client Initialization Failed.', exc_info=True)
Ejemplo n.º 6
0
 def send_filename(self, filename):
     try:
         self.send_data(filename.encode())
         general_logger.info('Filename sent.')
     except:
         general_logger.error('Sending filename failed.', exc_info=True)
Ejemplo n.º 7
0
 def run(self):
     general_logger.info('Client Thread now running.')
     self.send()
     self.socket.close()
     general_logger.info('Client Thread now exited.')
Ejemplo n.º 8
0
from library.logger.client import general_logger, measurement_logger

general_logger.info("PUTANGINA")
measurement_logger.info("%s, %s, %s", 1, 2, 3)