Esempio n. 1
0
    def recv(self, msg):
        '''
        Accepts string or frame.Frame

        In the future, we may want to consider non-frames a ValueError
        '''
        logger.debug("Handling frame: %s", repr(msg))
        if not isinstance(msg, frame.base.BaseFrame):
            try:
                msg = frame.createFrame(msg)
            except Exception:
                logger.info("Router could not parse frame: %s", repr(msg))
                return
        if isinstance(msg, frame.address.ReceiverCategory):
            recvr = self.client(msg.address) or self.jack(msg.address)
            if recvr:
                with Guard():
                    recvr.route(msg)
            else:
                logger.info("Router could not deliver frame: %s",
                            str(msg.address))
        elif isinstance(msg, frame.address.SenderCategory):
            logger.info("Frame recieved directly from %s", str(msg.address))
        else:
            logger.info(
                "Frame has a type that the router does not understand (%r)",
                msg)
Esempio n. 2
0
 def rcv_callback(self, msg, client_obj):
     data = msg.unpack()
     mtype = data['type']
     if mtype == 'ejforward-notify':
         self._status = data
         for callback in self._status_callbacks:
             callback(self)
         self._status_callbacks = []
     elif mtype == 'ejforward-message':
         internal = RawData(data['data'])
         self.ack([hashfunc(internal)])
         try:
             self.send(frame.createFrame(internal))  # forward to router
         except ValueError:
             logger.warning("Invalid frame, discarding")
     else:
         logger.warning("Unknown message type, %r" % mtype)
 def test_registration(self):
     self.assertEqual(frame.createFrame('c\x00'),
                      frame.compressed.CompressedFrame('c\x00'))
Esempio n. 4
0
 def test_registration(self):
     self.assertEqual(frame.createFrame('s\x00'),
                      frame.signed.SignedFrame('s\x00'))
Esempio n. 5
0
 def test_registration(self):
     self.assertEqual(frame.createFrame('r\x00'),
                      frame.encrypted.EncryptedFrame('r\x00'))
Esempio n. 6
0
 def test_registration(self):
     self.assertEqual(frame.createFrame('j\x00'),
                      frame.json.JSONFrame('j\x00'))