asimov.tcpros

decode-header

(decode-header ch)
Decodes the tcpros header of a connection.

Expects:
 ch:channel An aleph channel of the connections bytestream.

Returns a vector of a future containing the parsed tcpros header as a map
and a channel containing the undecoded rest of the provided channel.

encode-header

(encode-header h)
Encodes a tcpros header map for sending over a connection.

Expects:
 h:map The tcpros header map containing arbitary keys and values.

Returns the header in binary encoded form where the contents are simply turned into strings.

handler-fn

(handler-fn node)
Returns a handler function that accepts and establishes
 publishing tcpros connections with other nodes.

Expects:
 node:atom The node the incomming connections should be connected to.

Returns the handler function to be used with an aleph tcp server.

header-frame

listen!

(listen! node)
Starts an aleph tcp server on a random port that waits for
incomming subscription to topics of the provided node.

Expects:
 node:atom the node incomming connections are registered on.

Returns a map containing a function to stop the server as well as the randomly choosen port.

Throws an exception if no free port can be found after 1000 retries.

rand-port

(rand-port)
Returns a random port in the ephemeral port range.

subscribe!

(subscribe! addr callerid topic msg-def)
Establishes a subscribing tcpros connection with another node.

Expects:
 addr:map The address map describing the node to be connected to.
 callerid:string A string identifying the connecting node.
 topic:string The name of the topic to be subscribed to.

Returns a channel delivering messages from the node connected to.