| 1 |
Hacking Flow |
|---|
| 2 |
============ |
|---|
| 3 |
|
|---|
| 4 |
These are basic hacking instructions for Flow. |
|---|
| 5 |
|
|---|
| 6 |
Contact |
|---|
| 7 |
------- |
|---|
| 8 |
|
|---|
| 9 |
Hans Petter Jansson <hpj@copyleft.no> |
|---|
| 10 |
|
|---|
| 11 |
Also see the AUTHORS file and individual authors in the source code headers |
|---|
| 12 |
themselves. |
|---|
| 13 |
|
|---|
| 14 |
Legal |
|---|
| 15 |
----- |
|---|
| 16 |
|
|---|
| 17 |
Our policy, in brief: |
|---|
| 18 |
|
|---|
| 19 |
Flow is LGPL. Any contributions to Flow must also fall under the LGPL. Authors |
|---|
| 20 |
retain the copyright to significant contributions. For minor modifications |
|---|
| 21 |
contributed to the Flow mainline, copyright shall be assigned to the original |
|---|
| 22 |
author of the code being modified. |
|---|
| 23 |
|
|---|
| 24 |
Source Code Structure |
|---|
| 25 |
--------------------- |
|---|
| 26 |
|
|---|
| 27 |
A bottom-up overview of the source code, or "where to start looking". The code |
|---|
| 28 |
resides in the "flow" directory. |
|---|
| 29 |
|
|---|
| 30 |
1) Basic utilities and building blocks: |
|---|
| 31 |
|
|---|
| 32 |
- flow-util.[ch] |
|---|
| 33 |
- flow-gobject-util.[ch] |
|---|
| 34 |
|
|---|
| 35 |
Platform-independent utility functions and boilerplate. |
|---|
| 36 |
|
|---|
| 37 |
- flow-common.c |
|---|
| 38 |
- flow-common-impl-*.[ch] |
|---|
| 39 |
|
|---|
| 40 |
Provides platform-specific utilities used by other -impl files in the |
|---|
| 41 |
project. flow-common.c is just a stub that selects and #includes an impl to |
|---|
| 42 |
compile. Note that flow-common-impl-*.h is the only platform-specific |
|---|
| 43 |
header file. It is not installed - it is only #included in other -impl |
|---|
| 44 |
files. |
|---|
| 45 |
|
|---|
| 46 |
- flow-ip-addr.[ch] |
|---|
| 47 |
- flow-ip-addr-impl-*.c |
|---|
| 48 |
- flow-ip-service.[ch] |
|---|
| 49 |
|
|---|
| 50 |
These objects store addresses of IP traffic endpoints. FlowIPAddr stores |
|---|
| 51 |
an IP address (v4 or v6) only. FlowIPService extends that by adding |
|---|
| 52 |
optional port number and quality of service (QoS) information. |
|---|
| 53 |
|
|---|
| 54 |
One of the "impl" files is chosen based on the platform you're compiling |
|---|
| 55 |
for and #included in flow-ip-addr.c. |
|---|
| 56 |
|
|---|
| 57 |
- flow-ip-resolver.[ch] |
|---|
| 58 |
- flow-ip-resolver-impl-*.c |
|---|
| 59 |
|
|---|
| 60 |
An asynchronous resolver that can map DNS names to IP addresses and vice |
|---|
| 61 |
versa. |
|---|
| 62 |
|
|---|
| 63 |
One of the "impl" files is chosen based on the platform you're compiling |
|---|
| 64 |
for and #included in flow-ip-resolver.c. |
|---|
| 65 |
|
|---|
| 66 |
2) Fundamental I/O: |
|---|
| 67 |
|
|---|
| 68 |
- flow-packet.[ch] |
|---|
| 69 |
- flow-packet-queue.[ch] |
|---|
| 70 |
|
|---|
| 71 |
The basic packet structure used to pass stream data and events among |
|---|
| 72 |
elements, and an object for efficient queuing of such packets. The queue |
|---|
| 73 |
allows for partial-packet data dequeues. |
|---|
| 74 |
|
|---|
| 75 |
- flow-shunt.[ch] |
|---|
| 76 |
- flow-shunt-impl-*.c |
|---|
| 77 |
|
|---|
| 78 |
Asynchronous, platform-agnostic I/O units that map to platform services like |
|---|
| 79 |
files, TCP/UDP sockets, external programs and processes, and worker threads. |
|---|
| 80 |
They communicate through callbacks, using FlowPackets. Shunts cannot be |
|---|
| 81 |
reused once the stream is closed. |
|---|
| 82 |
|
|---|
| 83 |
One of the "impl" files is chosen based on the platform you're compiling |
|---|
| 84 |
for and #included in flow-shunt.c. |
|---|
| 85 |
|
|---|
| 86 |
3) Stream processing: |
|---|
| 87 |
|
|---|
| 88 |
- flow-element.[ch] |
|---|
| 89 |
|
|---|
| 90 |
Abstract class for stream processing elements. A stream consists of |
|---|
| 91 |
FlowPackets. |
|---|
| 92 |
|
|---|
| 93 |
- flow-pad.[ch] |
|---|
| 94 |
- flow-input-pad.[ch] |
|---|
| 95 |
- flow-output-pad.[ch] |
|---|
| 96 |
|
|---|
| 97 |
Connection points for elements. Processing chains are formed by connecting |
|---|
| 98 |
one element's output pad to another's input pad. |
|---|
| 99 |
|
|---|
| 100 |
- flow-emitter.[ch] |
|---|
| 101 |
- flow-collector.[ch] |
|---|
| 102 |
- flow-simplex-element.[ch] |
|---|
| 103 |
- flow-duplex-element.[ch] |
|---|
| 104 |
- flow-joiner.[ch] |
|---|
| 105 |
- flow-splitter.[ch] |
|---|
| 106 |
|
|---|
| 107 |
Abstract classes for various types of element, providing default policies |
|---|
| 108 |
and common ways to address pads. An emitter has a single output pad, a |
|---|
| 109 |
collector has a single input pad, a simplex element has one input and one |
|---|
| 110 |
output pad, etc. |
|---|
| 111 |
|
|---|
| 112 |
- flow-destructor.[ch] |
|---|
| 113 |
|
|---|
| 114 |
A fully implemented collector element that destroys all packets passed to |
|---|
| 115 |
it. Useful for terminating an output pad whose output you're not interested |
|---|
| 116 |
in (if you don't terminate, output can pile up on the pad). |
|---|
| 117 |
|
|---|
| 118 |
- flow-tls-protocol.[ch] |
|---|
| 119 |
|
|---|
| 120 |
A fully implemented duplex element that talks TLS/SSL downstream and |
|---|
| 121 |
plaintext upstream. |
|---|
| 122 |
|
|---|
| 123 |
- flow-connector.[ch] |
|---|
| 124 |
|
|---|
| 125 |
Abstract class for connection-oriented elements. Manages a single connection |
|---|
| 126 |
at a time, and can be reused. |
|---|
| 127 |
|
|---|
| 128 |
- flow-tcp-connector.[ch] |
|---|
| 129 |
|
|---|
| 130 |
Fully implemented connector for TCP/IP streams. |
|---|
| 131 |
|
|---|
| 132 |
- flow-tcp-listener.[ch] |
|---|
| 133 |
|
|---|
| 134 |
Listens for TCP connections, spawning FlowTcpConnectors (above). |
|---|
| 135 |
|
|---|
| 136 |
- flow-event.[ch] |
|---|
| 137 |
|
|---|
| 138 |
Abstract class for events passed in-line in streams. Events carry |
|---|
| 139 |
information like "stream begin", "stream end", "flush", errors, etc. They |
|---|
| 140 |
can generate a human-readable description of themselves for debug, |
|---|
| 141 |
logging and other display purposes. |
|---|
| 142 |
|
|---|
| 143 |
- flow-detailed-event.[ch] |
|---|
| 144 |
|
|---|
| 145 |
Fully implemented event that carries a list of event domains and codes, as |
|---|
| 146 |
well as an (optional) human-readable description of the event. Each event |
|---|
| 147 |
may carry multiple event codes describing the same event with different |
|---|
| 148 |
levels of specificity, so it may match e.g. either "stream end" or "TCP |
|---|
| 149 |
connection closed on remote end". This simplifies element code. |
|---|
| 150 |
|
|---|
| 151 |
- flow-property-event.[ch] |
|---|
| 152 |
|
|---|
| 153 |
Fully implemented event that carries a property to be set on a certain |
|---|
| 154 |
FlowElement instance or class. |
|---|
| 155 |
|
|---|
| 156 |
- flow-anonymous-event.[ch] |
|---|
| 157 |
|
|---|
| 158 |
An event that carries an untyped gpointer and a destroy notification |
|---|
| 159 |
callback, which is called when the event is finalized. Used in connection |
|---|
| 160 |
listener shunts to deliver shunts representing new connections to the |
|---|
| 161 |
stream layer. Avoid using this in your element implementations. |
|---|
| 162 |
|
|---|
| 163 |
- flow-position.[ch] |
|---|
| 164 |
|
|---|
| 165 |
Indicates that the position of the stream has changed, or should change. |
|---|
| 166 |
This translates to a seek on connected files. |
|---|
| 167 |
|
|---|
| 168 |
- flow-segment-request.[ch] |
|---|
| 169 |
|
|---|
| 170 |
Requests that a data segment be read, starting at the current position, from |
|---|
| 171 |
a connected file. |
|---|
| 172 |
|
|---|
| 173 |
- flow-bin.[ch] |
|---|
| 174 |
|
|---|
| 175 |
Contains/manages a number of FlowElements. Similar to GStreamer's GstBin. |
|---|
| 176 |
|
|---|
| 177 |
4) Prefab pipelines: |
|---|
| 178 |
|
|---|
| 179 |
- flow-io.[ch] |
|---|
| 180 |
|
|---|
| 181 |
A bin with external I/O functions, for constructing simple I/O pipelines. |
|---|
| 182 |
Does not do anything out of the box. |
|---|
| 183 |
|
|---|
| 184 |
- flow-tcp-io.[ch] |
|---|
| 185 |
|
|---|
| 186 |
A FlowIO derivate that does TCP connections. |
|---|
| 187 |
|
|---|
| 188 |
- flow-tcp-io-listener.[ch] |
|---|
| 189 |
|
|---|
| 190 |
Listens for TCP connections, spawning FlowTcpIOs (above). |
|---|
| 191 |
|
|---|
| 192 |
- flow-tls-tcp-io.[ch] |
|---|
| 193 |
|
|---|
| 194 |
Derives from FlowTcpIO and adds a FlowTlsProtocol element. |
|---|
| 195 |
|
|---|
| 196 |
- flow-tls-tcp-io-listener.[ch] |
|---|
| 197 |
|
|---|
| 198 |
Listens for TCP connections, spawning FlowTlsTcpIOs (above). |
|---|
| 199 |
|
|---|
| 200 |
Unit Tests |
|---|
| 201 |
---------- |
|---|
| 202 |
|
|---|
| 203 |
Unit tests reside in the "test" directory, and are named "test-*", where * |
|---|
| 204 |
represents an element or aspect of the library. A notable exception is |
|---|
| 205 |
"test-common.c" which contains common utilities for the tests and should be |
|---|
| 206 |
#included in every test. |
|---|
| 207 |
|
|---|
| 208 |
Tests are self-documenting: You can pass --help to any test and get a list of |
|---|
| 209 |
the arguments it takes. |
|---|
| 210 |
|
|---|
| 211 |
Tests are uniform: All tests take the same arguments. |
|---|
| 212 |
|
|---|
| 213 |
There is also a script, "stress.sh", which runs the tests listed in |
|---|
| 214 |
"tests.list" repeatedly, until interrupted by user. Any tests that failed have |
|---|
| 215 |
their verbose output saved to a log file called "stress-failure-N.log", where |
|---|
| 216 |
N is a number starting at 0. This can usefully be left running overnight (or |
|---|
| 217 |
longer!) to detect rare bugs caused by race conditions or memory corruption. |
|---|