trixy

The main Trixy module contains the parent classes that can be modified for custom functionality.

class trixy.TrixyInput(loop)[source]

Bases: trixy.TrixyNode, asyncio.protocols.Protocol

Once a connection is open, establish an output chain.

add_downstream_node(node)

Add a one direction downstream link to the node parameter.

Parameters:node (TrixyNode) – The downstream node to create a unidirectional link to.
add_upstream_node(node)

Add a one direction upstream link to the node parameter.

Parameters:node (TrixyNode) – The upstream node to create a unidirectional link to.
connect_node(node)

Create a bidirectional connection between the two nodes with the downstream node being the parameter.

Parameters:node (TrixyNode) – The downstream node to create a bidirectional connection to.
connection_lost(ex)[source]

The connection from the client was lost. Close the chain.

connection_made(transport)[source]

An incoming connection has been established; save the transport.

data_received(data)[source]

Received data from the client; forward it up the chain.

eof_received()

Called when the other end calls write_eof() or equivalent.

If this returns a false value (including None), the transport will close itself. If it returns a true value, closing the transport is up to the protocol.

forward_packet_down(data)

Forward data to all downstream nodes.

Parameters:data (bytes) – The data to forward.
forward_packet_up(data)

Forward data to all upstream nodes.

Parameters:data (bytes) – The data to forward.
handle_packet_down(data)[source]

Take a downward-bound packet and forward it to the client.

handle_packet_up(data)

Hadle data moving upwards. TrixyProcessor children should perform some action on data whereas TrixyOutput children should send the data to the desired output location.

Generally, the a child implementation of this method should be implemented such that it calls self.forward_packet_down with the data (post-modification if necessary) to forward the data to other processors in the chain. However, if the processor is a filter, it may drop the packet by omitting that call.

Parameters:data (bytes) – The data that is being handled.
pause_writing()

Called when the transport’s buffer goes over the high-water mark.

Pause and resume calls are paired – pause_writing() is called once when the buffer goes strictly over the high-water mark (even if subsequent writes increases the buffer size even more), and eventually resume_writing() is called once when the buffer size reaches the low-water mark.

Note that if the buffer size equals the high-water mark, pause_writing() is not called – it must go strictly over. Conversely, resume_writing() is called when the buffer size is equal or lower than the low-water mark. These end conditions are important to ensure that things go as expected when either mark is zero.

NOTE: This is the only Protocol callback that is not called through EventLoop.call_soon() – if it were, it would have no effect when it’s most needed (when the app keeps writing without yielding until pause_writing() is called).

resume_writing()

Called when the transport’s buffer drains below the low-water mark.

See pause_writing() for details.

class trixy.TrixyNode[source]

Bases: object

A base class for TrixyNodes that implements some default packet forwarding and node linking.

add_downstream_node(node)[source]

Add a one direction downstream link to the node parameter.

Parameters:node (TrixyNode) – The downstream node to create a unidirectional link to.
add_upstream_node(node)[source]

Add a one direction upstream link to the node parameter.

Parameters:node (TrixyNode) – The upstream node to create a unidirectional link to.
connect_node(node)[source]

Create a bidirectional connection between the two nodes with the downstream node being the parameter.

Parameters:node (TrixyNode) – The downstream node to create a bidirectional connection to.
forward_packet_down(data)[source]

Forward data to all downstream nodes.

Parameters:data (bytes) – The data to forward.
forward_packet_up(data)[source]

Forward data to all upstream nodes.

Parameters:data (bytes) – The data to forward.
handle_close(direction='down')[source]

The connection has closed on one end. So, shutdown what we are doing and notify the nodes we are connected to.

Parameters:direction (str) – ‘down’ or ‘up’ depending on if downstream nodes need to be closed, or upstream nodes need to be closed.
handle_packet_down(data)[source]

Hadle data moving downwards. TrixyProcessor children should perform some action on data whereas TrixyOutput children should send the data to the desired output location.

Generally, the a child implementation of this method should be implemented such that it calls self.forward_packet_down with the data (post-modification if necessary) to forward the data to other processors in the chain. However, if the processor is a filter, it may drop the packet by omitting that call.

Parameters:data (bytes) – The data that is being handled.
handle_packet_up(data)[source]

Hadle data moving upwards. TrixyProcessor children should perform some action on data whereas TrixyOutput children should send the data to the desired output location.

Generally, the a child implementation of this method should be implemented such that it calls self.forward_packet_down with the data (post-modification if necessary) to forward the data to other processors in the chain. However, if the processor is a filter, it may drop the packet by omitting that call.

Parameters:data (bytes) – The data that is being handled.
class trixy.TrixyOutput(loop, host, port, autoconnect=True)[source]

Bases: trixy.TrixyNode, asyncio.protocols.Protocol

Output node; generally to connect to another network service.

add_downstream_node(node)

Add a one direction downstream link to the node parameter.

Parameters:node (TrixyNode) – The downstream node to create a unidirectional link to.
add_upstream_node(node)

Add a one direction upstream link to the node parameter.

Parameters:node (TrixyNode) – The upstream node to create a unidirectional link to.
connect()[source]

Connect to the saved hsot and port. This method is commonly called by __init__() when autoconnect is enabled.

connect_node(node)

Create a bidirectional connection between the two nodes with the downstream node being the parameter.

Parameters:node (TrixyNode) – The downstream node to create a bidirectional connection to.
connection_lost(exc)

Called when the connection is lost or closed.

The argument is an exception object or None (the latter meaning a regular EOF is received or the connection was aborted or closed).

connection_made(transport)[source]

Outbound connection successful; save the transport.

data_received(data)[source]

Received incoming data; forward it down the chain.

Parameters:data (bytes) – a bytes object of the received data.
eof_received()

Called when the other end calls write_eof() or equivalent.

If this returns a false value (including None), the transport will close itself. If it returns a true value, closing the transport is up to the protocol.

forward_packet_down(data)

Forward data to all downstream nodes.

Parameters:data (bytes) – The data to forward.
forward_packet_up(data)[source]

If the transport is connected, send the data onwards; otherwise it will be added to the buffer.

This method require buffering because data often becomes available immediately for upload, but the transport needs time to connect. (This is especially the case when autoconnect is set to True).

handle_close(direction='down')

The connection has closed on one end. So, shutdown what we are doing and notify the nodes we are connected to.

Parameters:direction (str) – ‘down’ or ‘up’ depending on if downstream nodes need to be closed, or upstream nodes need to be closed.
handle_packet_down(data)

Hadle data moving downwards. TrixyProcessor children should perform some action on data whereas TrixyOutput children should send the data to the desired output location.

Generally, the a child implementation of this method should be implemented such that it calls self.forward_packet_down with the data (post-modification if necessary) to forward the data to other processors in the chain. However, if the processor is a filter, it may drop the packet by omitting that call.

Parameters:data (bytes) – The data that is being handled.
handle_packet_up(data)

Hadle data moving upwards. TrixyProcessor children should perform some action on data whereas TrixyOutput children should send the data to the desired output location.

Generally, the a child implementation of this method should be implemented such that it calls self.forward_packet_down with the data (post-modification if necessary) to forward the data to other processors in the chain. However, if the processor is a filter, it may drop the packet by omitting that call.

Parameters:data (bytes) – The data that is being handled.
pause_writing()

Called when the transport’s buffer goes over the high-water mark.

Pause and resume calls are paired – pause_writing() is called once when the buffer goes strictly over the high-water mark (even if subsequent writes increases the buffer size even more), and eventually resume_writing() is called once when the buffer size reaches the low-water mark.

Note that if the buffer size equals the high-water mark, pause_writing() is not called – it must go strictly over. Conversely, resume_writing() is called when the buffer size is equal or lower than the low-water mark. These end conditions are important to ensure that things go as expected when either mark is zero.

NOTE: This is the only Protocol callback that is not called through EventLoop.call_soon() – if it were, it would have no effect when it’s most needed (when the app keeps writing without yielding until pause_writing() is called).

resume_writing()

Called when the transport’s buffer drains below the low-water mark.

See pause_writing() for details.

class trixy.TrixyProcessor[source]

Bases: trixy.TrixyNode

Perform processing on data moving through Trixy.

add_downstream_node(node)

Add a one direction downstream link to the node parameter.

Parameters:node (TrixyNode) – The downstream node to create a unidirectional link to.
add_upstream_node(node)

Add a one direction upstream link to the node parameter.

Parameters:node (TrixyNode) – The upstream node to create a unidirectional link to.
connect_node(node)

Create a bidirectional connection between the two nodes with the downstream node being the parameter.

Parameters:node (TrixyNode) – The downstream node to create a bidirectional connection to.
forward_packet_down(data)

Forward data to all downstream nodes.

Parameters:data (bytes) – The data to forward.
forward_packet_up(data)

Forward data to all upstream nodes.

Parameters:data (bytes) – The data to forward.
handle_close(direction='down')

The connection has closed on one end. So, shutdown what we are doing and notify the nodes we are connected to.

Parameters:direction (str) – ‘down’ or ‘up’ depending on if downstream nodes need to be closed, or upstream nodes need to be closed.
handle_packet_down(data)

Hadle data moving downwards. TrixyProcessor children should perform some action on data whereas TrixyOutput children should send the data to the desired output location.

Generally, the a child implementation of this method should be implemented such that it calls self.forward_packet_down with the data (post-modification if necessary) to forward the data to other processors in the chain. However, if the processor is a filter, it may drop the packet by omitting that call.

Parameters:data (bytes) – The data that is being handled.
handle_packet_up(data)

Hadle data moving upwards. TrixyProcessor children should perform some action on data whereas TrixyOutput children should send the data to the desired output location.

Generally, the a child implementation of this method should be implemented such that it calls self.forward_packet_down with the data (post-modification if necessary) to forward the data to other processors in the chain. However, if the processor is a filter, it may drop the packet by omitting that call.

Parameters:data (bytes) – The data that is being handled.
class trixy.TrixyServer(tinput, host, port, loop=None)[source]

Bases: object

Main server to grab incoming connections and forward them.

close()[source]

Shutdown the server.

run_loop()[source]

Run the event loop so that the server functions.