コード例 #1
0
ファイル: connection.py プロジェクト: youprofit/OpenBazaar
class Connection(object):
    def __init__(self, packet_sender):

        self.log = logging.getLogger('%s' % self.__class__.__name__)
        self.log.info('Init Connection')

        self.event_emitter = EventEmitter()

        self._sender = Sender(packet_sender)
        self._receiver = Receiver(packet_sender)

        # pylint: disable=unused-variable
        @self._receiver.event_emitter.on('data')
        def on_data(data):
            self.log.debug('Received IncomingMessage: %s', data)
            self.event_emitter.emit('data', data)

        # pylint: disable=unused-variable
        @self._receiver.event_emitter.on('_reset')
        def on_reset(data):
            self.log.debug('Received reset message')
            #self._sender = Sender(packet_sender)

    def send(self, data):
        self._sender.send(data)
        count_outgoing_packet(data)

    def receive(self, packet):
        if packet._acknowledgement:
            self._sender.verify_acknowledgement(packet._sequence_number)
        else:
            self._receiver.receive(packet)
        count_incoming_packet(packet)
コード例 #2
0
ファイル: connection.py プロジェクト: youprofit/OpenBazaar
    def __init__(self, packet_sender):

        self.log = logging.getLogger('%s' % self.__class__.__name__)
        self.log.info('Init Connection')

        self.event_emitter = EventEmitter()

        self._sender = Sender(packet_sender)
        self._receiver = Receiver(packet_sender)

        # pylint: disable=unused-variable
        @self._receiver.event_emitter.on('data')
        def on_data(data):
            self.log.debug('Received IncomingMessage: %s', data)
            self.event_emitter.emit('data', data)

        # pylint: disable=unused-variable
        @self._receiver.event_emitter.on('_reset')
        def on_reset(data):
            self.log.debug('Received reset message')