<commit_before># damper
Linux userspace traffic shaper

Utility for shaping network traffic. `damper` uses NFQUEUE mechanism for capture traffic and raw sockets for re-injecting. All processing occurs in user space as opposed to traditional kernel space Linux traffic shaping.

### Compiling

(netfilter-queue library required)

```sh
$ cc -Wall -pedantic damper.c modules.conf.c -o damper -lnetfilter_queue -pthread -lrt -lm
```

### Shaping and modules

`damper` works approximately in this way: at startup two threads are created. First thread captures network packets (via NFQUEUE), calculate "weight" or priority for each one and put it in priority queue. Whet queue is full, packets with low priority replaced with high-priority packets. Second thread selects packets with high weight and sends (resends in fact) them. Resending happens with limited speed, and thus it shapes traffic.

Packet weight is assigned in "modules", there is 4 out of box.

- inhibit_big_flows - suppresses big flows. The more bytes transmitted between two IP addresses, the less weight of a packet in this flow.

- bymark - packet weight is set by iptables mark. See damper.conf for details and example.

- entropy - Shannon entropy calculated for each flow and used as weight. Flow identified by IP addresses, protocol number and source/destination ports in case of TCP or UDP. The more random is traffic (encrypted, compressed), the less weight is set to packet.

- random - generates a random weight (as in classic RED shaping algorithm)

To enable or disable module edit `modules.conf.c` file

Weight from each module multiplied by module coefficient and summarized to get the final value.

### Running on local box<commit_msg>README update<commit_after># damper
Linux userspace traffic shaper

Utility for shaping network traffic. `damper` uses NFQUEUE mechanism for capture traffic and raw sockets for re-injecting. All processing occurs in user space as opposed to traditional kernel space Linux traffic shaping.

### Compiling

(netfilter-queue library required)

```sh
$ cc -Wall -pedantic damper.c modules.conf.c -o damper -lnetfilter_queue -pthread -lrt -lm
```

### Shaping and modules

`damper` works approximately in this way: at startup two threads are created. First thread captures network packets (via NFQUEUE), calculate "weight" (or priority) for each one and put it in priority queue. Wheh queue is full, packets with low priority replaced with high-priority ones. Second thread selects packets with high weight and sends (resends in fact) them. Resending happens with limited speed, and thus it shapes traffic.

Packet weight is assigned in "modules", there is 4 out of box.

- inhibit_big_flows - suppresses big flows. The more bytes transmitted between two IP addresses, the less weight of a packet in this flow.

- bymark - packet weight is set by iptables mark. See `damper.conf` for details and example.

- entropy - Shannon entropy calculated for each flow and used as weight. Flow identified by IP addresses, protocol number and source/destination ports in case of TCP or UDP. The more random is traffic (encrypted, compressed or multimedia traffic gets higher entropy values), the less weight is set to packet.

- random - generates a random weight (when this module is used alone, we get the classic RED shaping algorithm)

To enable or disable module edit `modules.conf.c` file

Weight from each module multiplied by module coefficient and summarized to get the final value.

### Running on local box
{'fraction_non_alphanumeric': 0.053200568990042676, 'fraction_numerical': 0.0005689900426742532, 'mean_word_length': 4.392638036809816, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4054126', 'n_tokens_mistral': 881, 'n_tokens_neox': 839, 'n_words': 514}