PyOuroboros: Difference between revisions

From Ouroboros
Jump to navigation Jump to search
No edit summary
No edit summary
Line 73: Line 73:
f.writeline(str, count)  # write up to count characters from string
f.writeline(str, count)  # write up to count characters from string
</syntaxhighlight>
</syntaxhighlight>
== Quality of Service (QoS) ==
You can specify a QoSSpec for flow allocation.
<syntaxhighlight lang="Python">
    """
    delay:        In ms, default 1000s
    bandwidth:    In bits / s, default 0
    availability: Class of 9s, default 0
    loss:        Packet loss in ppm, default MILLION
    ber:          Bit error rate, errors per billion bits. default BILLION
    in_order:    In-order delivery, enables FRCT, default 0
    max_gap:      Maximum interruption in ms, default MILLION
    cypher_s:    Requested encryption strength in bits
    timeout:      Timeout for the flow to declare the peer dead
    """
</syntaxhighlight>
For instance,
<syntaxhighlight lang="Python">
qos = QoSSpec(loss=0, cypher_s=256)
f = flow_alloc("name", qos)
</syntaxhighlight>
will create a new flow with FRCP retransmission enabled and encrypted using a 256-bit ECDHE-AES-SHA3 cypher. The number of encryption options will further expand as the prototype matures.

Revision as of 18:29, 8 June 2022

Under contruction This page is under construction  

The python API allows you to write Ouroboros-native programs in Python (>=3.4) is available as a separate repository. You need Ouroboros installed before installing PyOuroboros. To download and install PyOuroboros(virtual environment recommended)

$ git clone https://ouroboros.rocks/git/pyouroboros
# Or github mirror:
# git clone https://github.com/dstaesse/pyouroboros
$ cd pyouroboros
./setup.py install

Basic Usage

import the Ouroboros dev library:

from ouroboros.dev import *

On the server side, Accepting a flow:

f = flow_accept()

returns a new allocated flow object.

Client side: Allocating a flow to a certain name:

f = flow_alloc("name")

returns a new allocated Flow object.

Broadcast:

f = flow_join("name")

returns a new allocated Flow object to a broadcast layer.

When a flow is not needed anymore, it can be deallocated:

f.dealloc()

To avoid having to call dealloc(), you can also use the with statement:

with flow_alloc("dst") as f:
    f.writeline("line")
    print(f.readline())

After the flow is deallocated, it is not readable or writeable anymore.

f.alloc("name")

will allocate a new flow for an existing Flow object.

To read / write from a flow:

f.read(count)             # read up to count bytes and return bytes
f.readline(count)         # read up to count characters as a string
f.write(buf, count)       # write up to count bytes from buffer
f.writeline(str, count)   # write up to count characters from string

Quality of Service (QoS)

You can specify a QoSSpec for flow allocation.

    """
    delay:        In ms, default 1000s
    bandwidth:    In bits / s, default 0
    availability: Class of 9s, default 0
    loss:         Packet loss in ppm, default MILLION
    ber:          Bit error rate, errors per billion bits. default BILLION
    in_order:     In-order delivery, enables FRCT, default 0
    max_gap:      Maximum interruption in ms, default MILLION
    cypher_s:     Requested encryption strength in bits
    timeout:      Timeout for the flow to declare the peer dead
    """

For instance,


qos = QoSSpec(loss=0, cypher_s=256)
f = flow_alloc("name", qos)

will create a new flow with FRCP retransmission enabled and encrypted using a 256-bit ECDHE-AES-SHA3 cypher. The number of encryption options will further expand as the prototype matures.