| 1 |
# Examples |
| 2 |
|
| 3 |
- `reader`: Example of reading DNSTAP from a file and printing it's content, using `dnswire_reader` (unidirectional mode) |
| 4 |
- `writer`: Example of constructing a DNSTAP message and writing it to a file, using `dnswire_writer` (unidirectional mode) |
| 5 |
- `receiver`: Example of receiving a DNSTAP message over a TCP connection and printing it's content, using `dnswire_reader` (bidirectional mode) |
| 6 |
- `sender`: Example of constructing a DNSTAP message and sending it over a TCP connection, using `dnswire_writer` (bidirectional mode) |
| 7 |
- `daemon_sender_uv`: Example of a daemon that will continuously send DNSTAP messages to connected clients (unidirectional mode), using the event engine `libuv` and `dnstap_encode_protobuf` along with `tinyframe` to encode once and send to many |
| 8 |
- `client_receiver_uv`: Example of a client that will receive DNSTAP message from the daemon (unidirectional mode), using the event engine `libuv` and `dnswire_reader` with the buffer push interface |
| 9 |
- `reader_sender`: Example of a reader that read DNSTAP from a file (unidirectional mode) and then sends the DNSTAP messages over a TCP connection (bidirectional mode) |
| 10 |
|
| 11 |
## receiver and sender |
| 12 |
|
| 13 |
These examples uses the way of connecting as implemented in the `fstrm` |
| 14 |
library, the receiver listens for connections by the sender and the sender |
| 15 |
connects to the receiver. |
| 16 |
|
| 17 |
``` |
| 18 |
$ ./receiver 127.0.0.1 5353 |
| 19 |
socket |
| 20 |
bind |
| 21 |
listen |
| 22 |
accept |
| 23 |
receiving... |
| 24 |
---- dnstap |
| 25 |
identity: sender |
| 26 |
version: 0.1.0 |
| 27 |
message: |
| 28 |
type: MESSAGE |
| 29 |
query_time: 1574765731.199945162 |
| 30 |
response_time: 1574765731.199945362 |
| 31 |
socket_family: INET |
| 32 |
socket_protocol: UDP |
| 33 |
query_address: 127.0.0.1 |
| 34 |
query_port: 12345 |
| 35 |
response_address: 127.0.0.1 |
| 36 |
response_port: 53 |
| 37 |
query_message_length: 27 |
| 38 |
query_message: dns_wire_format_placeholder |
| 39 |
response_message_length: 27 |
| 40 |
response_message: dns_wire_format_placeholder |
| 41 |
---- |
| 42 |
stopped |
| 43 |
``` |
| 44 |
|
| 45 |
``` |
| 46 |
$ ./sender 127.0.0.1 5353 |
| 47 |
socket |
| 48 |
connect |
| 49 |
sending... |
| 50 |
sent, stopping... |
| 51 |
stopped |
| 52 |
``` |
| 53 |
|
| 54 |
## daemon_sender_uv and client_receiver_uv |
| 55 |
|
| 56 |
These examples works in the reverse way compared to `receiver` and `sender`, |
| 57 |
and maybe a more traditional way, the daemon listens and accepts connections |
| 58 |
from new clients, and will continuously send messages to established clients |
| 59 |
that are ready to receive them. |
| 60 |
|
| 61 |
``` |
| 62 |
$ ./daemon_sender_uv 127.0.0.1 5353 |
| 63 |
client 1 connected |
| 64 |
client 1: sending control start and content type |
| 65 |
client 1: sending DNSTAP |
| 66 |
client 1: sending DNSTAP |
| 67 |
client 1 disconnected |
| 68 |
``` |
| 69 |
|
| 70 |
``` |
| 71 |
$ ./client_receiver_uv 127.0.0.1 5353 |
| 72 |
received 42 bytes |
| 73 |
got control start |
| 74 |
got content type DNSTAP |
| 75 |
received 133 bytes |
| 76 |
---- dnstap |
| 77 |
identity: daemon_sender_uv |
| 78 |
version: 0.1.0 |
| 79 |
message: |
| 80 |
type: MESSAGE |
| 81 |
query_time: 1574257180.95619354 |
| 82 |
response_time: 1574257180.95619490 |
| 83 |
socket_family: INET |
| 84 |
socket_protocol: UDP |
| 85 |
query_address: 127.0.0.1 |
| 86 |
query_port: 12345 |
| 87 |
response_address: 127.0.0.1 |
| 88 |
response_port: 53 |
| 89 |
query_message_length: 27 |
| 90 |
query_message: dns_wire_format_placeholder |
| 91 |
response_message_length: 27 |
| 92 |
response_message: dns_wire_format_placeholder |
| 93 |
---- |
| 94 |
received 133 bytes |
| 95 |
---- dnstap |
| 96 |
identity: daemon_sender_uv |
| 97 |
version: 0.1.0 |
| 98 |
message: |
| 99 |
type: MESSAGE |
| 100 |
query_time: 1574257181.96381443 |
| 101 |
response_time: 1574257181.96381557 |
| 102 |
socket_family: INET |
| 103 |
socket_protocol: UDP |
| 104 |
query_address: 127.0.0.1 |
| 105 |
query_port: 12345 |
| 106 |
response_address: 127.0.0.1 |
| 107 |
response_port: 53 |
| 108 |
query_message_length: 27 |
| 109 |
query_message: dns_wire_format_placeholder |
| 110 |
response_message_length: 27 |
| 111 |
response_message: dns_wire_format_placeholder |
| 112 |
---- |
| 113 |
^C |
| 114 |
``` |