Receiving

class p2p0mq.app.server.Receiver(*args, **kwargs)[source]

A thread that receives requests and information from peers.

This is a “server” according to the [zmq_curve](http://api.zeromq.org/4-1:zmq-curve) which states that: > A socket using CURVE can be either client or server, > at any moment, but not both. > The role is independent of bind/connect direction.

To become a CURVE server, the local peer sets the ZMQ_CURVE_SERVER option on the socket, and then sets the ZMQ_CURVE_SECRETKEY option to provide the socket with its long-term secret key. The local peer does not provide the socket with its long-term public key, which is used only by clients.

The receiver listens to messages and creates messages out of them. The messages are then placed in the queue where the local peer will pick them up.

For now the receiver understands two kinds of messages: requests and replies. However,adding additional types is easy: add a queue to the typed_queues member and create code on application side to offload this queue.

create()[source]

Called at thread start to initialize the state.

enqueue(message, messages)[source]

Places a message in the appropriate queue.

Messages not destined to us are placed in a special queue. Others are split based on their type field.

Messages that have unknown types are silently discarded.

execute()[source]

Called to execute the main part of the thread.

In implementations where this function is executed in a loop it is expected to return False to break the loop end terminate the thread.

receive_message()[source]

Receive a single message.

terminate()[source]

Called at thread end to free resources.

update_queues(messages)[source]

Places messages in queues all at once.

The messages is a dictionary, with keys being the