KNET_HANDLE_COMPRESS(3)

πŸ’– KNET_HANDLE_COMPRESS πŸ’–

okay bestie so this is knet_handle_compress, straight out of the Kronosnet Programmer's Manual (that's the KNET_HANDLE_COMPRESS(3) one, section 3, we love a library-call moment) ✨


✨ NAME ✨

knet_handle_compress β€” set up packet compression. that's it, that's the whole vibe πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <libknet.h>

int knet_handle_compress(
    knet_handle_t                      knet_h,
    struct knet_handle_compress_cfg   *knet_handle_compress_cfg
);

🌸 DESCRIPTION 🌸

so knet_handle_compress is the function, and here's what you're handing it:

  • knet_h β€” pointer to knet_handle_t πŸ‘‘
  • knet_handle_compress_cfg β€” pointer to a knet_handle_compress_cfg structure

now let's talk about what's inside that struct, because this is the main character energy part:

  • compress_model holds the model name. for the list of accepted values, go look at compress_level. set it to "none" and compression is disabled, periodt. πŸ™ˆ
  • compress_threshold tells the transmission thread to NOT compress any packets smaller than the value you give it. default is 100 bytes. set it to 0 to reset back to the default. set it to 1 to compress literally everything. the max accepted value is KNET_MAX_PACKET_SIZE. πŸ’…
  • compress_level is the "level" parameter for most models:
    • zlib: 0 (no compression), 1 (minimal) .. 9 (max compression).
    • lz4: 1 (max compression)... 9 (fastest compression).
    • lz4hc: 1 (min compression) ... LZ4HC_MAX_CLEVEL (16) or LZ4HC_CLEVEL_MAX (12) depending on the version of lz4hc libknet was built with.
    • lzma: 0 (minimal) .. 9 (max compression)
    • bzip2: 1 (minimal) .. 9 (max compression)
    • For lzo2 it selects the algorithm to use:
      • 1 : lzo1x_1_compress (default)
      • 11 : lzo1x_1_11_compress
      • 12 : lzo1x_1_12_compress
      • 15 : lzo1x_1_15_compress
      • 999: lzo1x_999_compress
      • Other values select the default algorithm.

please refer to the documentation of the respective compression library for guidance about setting this value 🫢

Implementation notes: it is possible to enable/disable compression at any time.

nodes can be using a different compression algorithm at any time.

knet does NOT implement the compression algorithm directly. it relies on external libraries for this functionality. please read the libraries man pages to figure out which algorithm/compression level is best for the data you are planning to transmit. πŸ”₯


πŸŽ€ STRUCTURES πŸŽ€

structure passed into knet_handle_compress() to tell knet what type of compression to use for this communiction πŸ‘‘

struct knet_handle_compress_cfg {
    char      compress_model[16];  /* Compression library to use, bzip2 etc... */
    /*
     * Threshold. Packets smaller than this will not be compressed
     */
    uint32_t  compress_threshold;
    /*
     * Passed into the compression library as an indication of the level of
     * compression to apply
     */
    int       compress_level;
};

⭐ RETURN VALUE ⭐

knet_handle_compress returns 0 on success, -1 on error, and errno is set. EINVAL means that either the model or the level are not supported. 😭


🌈 SEE ALSO 🌈

the whole friend group, fr fr:


Copyright (C) 2010-2026 Red Hat, Inc. All rights reserved. 🫢


okay that's the whole page, no cap πŸ’– this one's from the kronosnet squad, dated 2026-07-20, and yes it really is KNET_HANDLE_COMPRESS(3) β€” go forth and compress responsibly, bestie βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from