forked from bankonme/OpenBazaar-Server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interfaces.py
60 lines (48 loc) · 2.11 KB
/
interfaces.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
__author__ = 'chris'
from zope.interface import Interface, Attribute
class MessageProcessor(Interface):
"""
This is an interface for processing messages coming off the wire. Classes that implement this interface should be
passed into 'OpenBazaarProtocol.register_processor' which will parse new messages to determine the message type
then route them to the correct processor.
"""
multiplexer = Attribute("""The main `ConnectionMultiplexer` protocol.
We pass it in here so we can send datagrams from this class.""")
def receive_message(datagram, connection):
"""
Called by OpenBazaarProtocol when it receives a new message intended for this processor.
Args:
datagram: The protobuf that came off the wire in unserialized format. Basic validity checks, such as
minimum size and valid protobuf format have already been done.
connection: the txrudp connection to the peer who sent the message. To respond directly to the peer call
connection.send_message()
"""
def connect_multiplexer(multiplexer):
"""
Connect the main ConnectionMultiplexer to this class so we can send outgoing messages.
"""
def __iter__():
"""
OpenBazaarProtocol will use this to check which message types are handled by this processor.
:return: iter([list of enums])
"""
class NotificationListener(Interface):
"""
An interface for handling notifications sent to followers.
"""
def notify(guid, message):
"""
New notifications will be sent here. They will only show if this node is following the node
which sent the notification.
"""
class MessageListener(Interface):
"""
An interface for handling messages sent between nodes.
"""
def notify(plaintext_message, signature):
"""
New messages will be sent here if they decrypt and parse correctly.
Args:
plaintext_message: the protobuf object containing the message
signature: the signature covering the message.
"""