Esempio n. 1
0
 def send(self, msg):
     is_encrypted, msg_or_msg_bytes = MessageCodec.local_encode(msg,
         shared_seed=self.shared_seed)
     if is_encrypted:
         logging.debug("sending encrypted: %s" % msg)
         self.send_bin(msg_or_msg_bytes)
     else:
         self.below_nexus.send_from_outgoing(msg_or_msg_bytes)
Esempio n. 2
0
    def onMessage(self, payload, isBinary):
        if isBinary:
            logging.info("binary payload: %d bytes" % len(payload))

            shared_seed = self.factory.ms_shared_seed

            if not shared_seed and MessageCodec.is_cyphertext(payload):
                self.upward_recv_raw_cb(self, payload)
                return
            msg, err = MessageCodec.wire_decode(payload,
                                                shared_seed=shared_seed)
            if err:
                logging.error("could not decode: %s" % err)
                return
            logging.info("recv msg: %s" % msg)
            self.upward_recv_cb(self, msg)
        else:
            logging.info("text payload: %s" % payload.decode("utf8"))
            logging.error("text payload is unexpected, dropping")
Esempio n. 3
0
    def on_bin_message(self, below_nexus, msg_bytes):
        logging.debug("outgoing local nexus got raw msg: %d" % len(msg_bytes))

        msg, err = MessageCodec.wire_decode(msg_bytes,
            shared_seed=self.shared_seed)
        if err:
            logging.error("could not decode msg: %s" % err)
            super().on_bin_message(below_nexus, msg_bytes)
            return
        super().on_message(below_nexus, msg)
Esempio n. 4
0
    def recv_raw_from_below_cb(self, below_nexus, msg_bytes):
        logging.info("outgoing local nexus got raw msg: %d" % len(msg_bytes))

        msg, err = MessageCodec.wire_decode(msg_bytes,
                                            shared_seed=self.shared_seed)
        if err:
            logging.error("could not decode msg: %s" % err)
            super().recv_raw_from_below_cb(below_nexus, msg_bytes)
            return
        super().recv_from_below_cb(below_nexus, msg)
Esempio n. 5
0
 def onMessage(self, payload, isBinary):
     logging.debug("outgoing message")
     if isBinary:
         logging.debug("binary payload: %d bytes" % len(payload))
         shared_seed = self.factory.ms_shared_seed
         msg, err = MessageCodec.wire_decode(payload,
                                             shared_seed=shared_seed)
         if err:
             logging.error("could not decode: %s" % err)
             return
         logging.debug("recv msg: %s" % msg)
         if self.onmessage:
             self.onmessage(self, msg)
     else:
         logging.debug("text payload: %s" % payload.decode("utf8"))
         logging.error("text payload is unexpected, dropping")
Esempio n. 6
0
 def send(self, msg):
     logging.info("encoding msg: %s" % msg)
     shared_seed = self.factory.ms_shared_seed
     msg_bytes = MessageCodec.wire_encode(msg, shared_seed=shared_seed)
     self.send_raw(msg_bytes)