Ejemplo n.º 1
0
 def makeTimedCaller(timings, clock=None):
     record = []
     call = lambda: record.append("call")
     last = lambda: record.append("last")
     if clock is None:
         caller = timedCaller(timings, call, last)
     else:
         caller = timedCaller(timings, call, last, clock)
     return caller, record
Ejemplo n.º 2
0
 def setUp(self):
     self.clock = Clock()
     self.temp_dir = FilePath(tempfile.mkdtemp()).asBytesMode()
     self.target = self.temp_dir.child(b'foo')
     self.writer = DelayedWriter(self.target, _clock=self.clock, delay=2)
     self.transport = FakeTransport(hostAddress=('127.0.0.1', self.port))
     self.ws = LocalOriginWriteSession(('127.0.0.1', 65465), self.writer, _clock=self.clock)
     self.wd = timedCaller([5], None, self.ws.timedOut, self.clock)
     self.ws.timeout_watchdog = self.wd
     self.ws.transport = self.transport
Ejemplo n.º 3
0
 def setUp(self):
     self.clock = Clock()
     self.temp_dir = FilePath(tempfile.mkdtemp()).asBytesMode()
     self.target = self.temp_dir.child(b'foo')
     with self.target.open('wb') as temp_fd:
         temp_fd.write(self.test_data)
     self.reader = DelayedReader(self.target, _clock=self.clock, delay=2)
     self.transport = FakeTransport(hostAddress=('127.0.0.1', self.port))
     self.rs = LocalOriginReadSession(('127.0.0.1', 65465), self.reader, _clock=self.clock)
     self.wd = timedCaller([5], None, self.rs.timedOut, self.clock)
     self.rs.timeout_watchdog = self.wd
     self.rs.transport = self.transport
Ejemplo n.º 4
0
    def dataFromReader(self, data):
        """Got data from the reader. Send it to the network and start the timeout
        cycle.

        """
        # reached maximum number of blocks. Rolling over
        if self.blocknum == 65536:
            self.blocknum = 0
        if len(data) < self.block_size:
            self.completed = True
        bytes = DATADatagram(self.blocknum, data).to_wire()
        self.timeout_watchdog = timedCaller(
            (0,) + self.timeout, partial(self.sendData, bytes),
            self.timedOut, clock=self._clock)
Ejemplo n.º 5
0
    def startProtocol(self):
        """Connect the transport, respond with an initial ACK or OACK (depending on
        if we were initialized with options or not).

        """
        self.transport.connect(*self.remote)
        if self.options:
            self.resultant_options = self.processOptions(self.options)
            bytes = OACKDatagram(self.resultant_options).to_wire()
        else:
            bytes = ACKDatagram(0).to_wire()
        self.timeout_watchdog = timedCaller(
            chain((0,), self.timeout), partial(self.transport.write, bytes),
            self.timedOut, clock=self._clock)
Ejemplo n.º 6
0
    def dataFromReader(self, data):
        """Got data from the reader. Send it to the network and start the timeout
        cycle.

        """
        # reached maximum number of blocks. Rolling over
        if self.blocknum == 65536:
            self.blocknum = 0
        if len(data) < self.block_size:
            self.completed = True
        bytes = DATADatagram(self.blocknum, data).to_wire()
        self.timeout_watchdog = timedCaller((0, ) + self.timeout,
                                            partial(self.sendData, bytes),
                                            self.timedOut,
                                            clock=self._clock)
Ejemplo n.º 7
0
    def startProtocol(self):
        """Start sending an OACK datagram if we were initialized with options
        or start the L{ReadSession} immediately.

        """
        self.transport.connect(*self.remote)
        if self.options:
            self.resultant_options = self.processOptions(self.options)
            bytes = OACKDatagram(self.resultant_options).to_wire()
            self.timeout_watchdog = timedCaller(
                chain((0,), self.timeout), partial(self.transport.write, bytes),
                self.timedOut, clock=self._clock)
        else:
            self.session.transport = self.transport
            self.session.startProtocol()
            return self.session.nextBlock()
Ejemplo n.º 8
0
    def startProtocol(self):
        """Connect the transport, respond with an initial ACK or OACK (depending on
        if we were initialized with options or not).

        """
        self.transport.connect(*self.remote)
        if self.options:
            self.resultant_options = self.processOptions(self.options)
            bytes = OACKDatagram(self.resultant_options).to_wire()
        else:
            bytes = ACKDatagram(0).to_wire()
        self.timeout_watchdog = timedCaller(chain((0, ), self.timeout),
                                            partial(self.transport.write,
                                                    bytes),
                                            self.timedOut,
                                            clock=self._clock)
Ejemplo n.º 9
0
    def blockWriteSuccess(self, ign, datagram):
        """The write was successful, respond with ACK for current block number

        If this is the last chunk (received data length < block size), the protocol
        will keep running until the end of current timeout period, so we can respond
        to any duplicates.

        @type datagram: L{DATADatagram}

        """
        bytes = ACKDatagram(datagram.blocknum).to_wire()
        self.timeout_watchdog = timedCaller(
            (0,) + self.timeout, partial(self.sendData, bytes),
            self.timedOut, clock=self._clock)
        if len(datagram.data) < self.block_size:
            self.completed = True
            self.writer.finish()
Ejemplo n.º 10
0
    def blockWriteSuccess(self, ign, datagram):
        """The write was successful, respond with ACK for current block number

        If this is the last chunk (received data length < block size), the protocol
        will keep running until the end of current timeout period, so we can respond
        to any duplicates.

        @type datagram: L{DATADatagram}

        """
        bytes = ACKDatagram(datagram.blocknum).to_wire()
        self.timeout_watchdog = timedCaller((0, ) + self.timeout,
                                            partial(self.sendData, bytes),
                                            self.timedOut,
                                            clock=self._clock)
        if len(datagram.data) < self.block_size:
            self.completed = True
            self.writer.finish()
Ejemplo n.º 11
0
    def startProtocol(self):
        """Start sending an OACK datagram if we were initialized with options
        or start the L{ReadSession} immediately.

        """
        self.transport.connect(*self.remote)
        if self.options:
            self.resultant_options = self.processOptions(self.options)
            bytes = OACKDatagram(self.resultant_options).to_wire()
            self.timeout_watchdog = timedCaller(chain((0, ), self.timeout),
                                                partial(
                                                    self.transport.write,
                                                    bytes),
                                                self.timedOut,
                                                clock=self._clock)
        else:
            self.session.transport = self.transport
            self.session.startProtocol()
            return self.session.nextBlock()