Exemple #1
0
class MessageListenerImpl(object):
    implements(MessageListener)

    def __init__(self, web_socket_factory):
        self.ws = web_socket_factory
        self.db = MessageStore()

    def notify(self, plaintext, signature):

        self.db.save_message(plaintext.sender_guid, plaintext.handle,
                             plaintext.signed_pubkey,
                             plaintext.encryption_pubkey, plaintext.subject,
                             Plaintext_Message.Type.Name(plaintext.type),
                             plaintext.message, plaintext.avatar_hash,
                             plaintext.timestamp, signature)

        # TODO: should probably resolve the handle and make sure it matches the guid so the sender can't spoof it

        message_json = {
            "message": {
                "sender": plaintext.sender_guid.encode("hex"),
                "subject": plaintext.subject,
                "message_type": Plaintext_Message.Type.Name(plaintext.type),
                "message": plaintext.message,
                "timestamp": plaintext.timestamp,
                "avatar_hash": plaintext.avatar_hash.encode("hex")
            }
        }
        if plaintext.handle:
            message_json["message"]["handle"] = plaintext.handle
        self.ws.push(json.dumps(message_json, indent=4))
class MessageListenerImpl(object):
    implements(MessageListener)

    def __init__(self, web_socket_factory):
        self.ws = web_socket_factory
        self.db = MessageStore()

    def notify(self, plaintext, signature):

        self.db.save_message(plaintext.sender_guid, plaintext.handle, plaintext.signed_pubkey,
                             plaintext.encryption_pubkey, plaintext.subject,
                             Plaintext_Message.Type.Name(plaintext.type), plaintext.message,
                             plaintext.avatar_hash, plaintext.timestamp, signature, False)

        # TODO: should probably resolve the handle and make sure it matches the guid so the sender can't spoof it

        message_json = {
            "message": {
                "sender": plaintext.sender_guid.encode("hex"),
                "subject": plaintext.subject,
                "message_type": Plaintext_Message.Type.Name(plaintext.type),
                "message": plaintext.message,
                "timestamp": plaintext.timestamp,
                "avatar_hash": plaintext.avatar_hash.encode("hex"),
                "encryption_key": plaintext.encryption_pubkey.encode("hex")
            }
        }
        if plaintext.handle:
            message_json["message"]["handle"] = plaintext.handle
        self.ws.push(json.dumps(message_json, indent=4))
Exemple #3
0
    def send_message(self, guid, handle, message, subject, message_type,
                     recipient_encryption_key):
        MessageStore().save_message(guid, handle, "", recipient_encryption_key,
                                    subject, message_type, message, "",
                                    time.time(), "", True)

        def send(node_to_send):
            n = node_to_send if node_to_send is not None else Node(
                unhexlify(guid), "123.4.5.6", 1234)
            self.factory.mserver.send_message(
                n, recipient_encryption_key,
                Plaintext_Message.Type.Value(message_type.upper()), message,
                subject)

        self.factory.kserver.resolve(unhexlify(guid)).addCallback(send)
Exemple #4
0
 def __init__(self, web_socket_factory):
     self.ws = web_socket_factory
     self.db = MessageStore()
 def __init__(self, web_socket_factory):
     self.ws = web_socket_factory
     self.db = MessageStore()