Example #1
0
class FileCompare:
    def __init__(self, protocol):
        self.protocol = protocol
        self._tm = TransferMediator()
        self.__buffer = list()
        self.__lock = Semaphore()

    def connect(self, ip, port):
        return self._tm.connect(ip, port)

    def disconnect(self):
        self._tm.disconnect()

    def _checkfile_master(self, file):
        self._tm.send(self.protocol.request())
        if not self.protocol.is_ready(self._tm.receive()):
            return False
        checker = FileCheckerBuilder(self.protocol['hash']['type'])
        # здесь разделяется на 2 потока: 1 считает, 2 отправляет

    def _checkfile_slave(self, file):
        self.protocol = FCProtocol(self._tm.receive())
        self._tm.send(self.protocol.ready())
        checker = FileCheckerBuilder(self.protocol['hash']['type'])
        # здесь разделяется на 2 потока: 1 считает, 2 принимает и сравнивает

    def checkfile(self, file, slave=False):
        if not slave:
            return self._checkfile_master(file)
        else:
            return self._checkfile_slave(file)
Example #2
0
 def __init__(self, protocol):
     self.protocol = protocol
     self._tm = TransferMediator()
     self.__buffer = list()
     self.__lock = Semaphore()