All Projects → Dridi → cashpack

Dridi / cashpack

Licence: other
A stateless event-driven HPACK codec

Programming Languages

c
50402 projects - #5 most used programming language
shell
77523 projects
M4
1887 projects
Makefile
30231 projects
go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to cashpack

restio
HTTP Client for Dart inspired by OkHttp
Stars: ✭ 46 (+84%)
Mutual labels:  http2
nghttp2-alpine
Minimal nghttp2 docker image with ALPN support
Stars: ✭ 14 (-44%)
Mutual labels:  http2
next.js-boilerplate
next.js bolierplate, next.js 的开发模板
Stars: ✭ 28 (+12%)
Mutual labels:  http2
docker-varnish
Docker image for Varnish Cache (caching HTTP reverse proxy)
Stars: ✭ 46 (+84%)
Mutual labels:  varnish
libmicrohttpd-http2
HTTP/2 support for libmicrohttpd
Stars: ✭ 21 (-16%)
Mutual labels:  http2
http2-examples-empireconf
HTTP2 examples for EmpireConf talk
Stars: ✭ 15 (-40%)
Mutual labels:  http2
pusher
golang : HTTP2 Push Handler collection
Stars: ✭ 15 (-40%)
Mutual labels:  http2
awacs
Next-gen mobile first analytics server (think Mixpanel, Google Analytics) with built-in encryption supporting HTTP2 and gRPC. Node.js, headless, API-only, horizontally scaleable.
Stars: ✭ 52 (+108%)
Mutual labels:  http2
Ghost-over-Caddy
This repo/script will install Ghost blog over Caddy web server as a reverse proxy.
Stars: ✭ 20 (-20%)
Mutual labels:  http2
docker-symfony
Docker Symfony SOA oriented with NGINX, PHP7-FPM, MySQL, Redis, ELK (Elasticsearch Logstash and Kibana), Varnish and CouchDB
Stars: ✭ 47 (+88%)
Mutual labels:  varnish
alprbd
Automated Bangla License Plate Detection and Recognition - Implementation. For thesis report visit- https://github.com/dipu-bd/thesis-report
Stars: ✭ 16 (-36%)
Mutual labels:  research-project
phorklift
Phorklift is an HTTP server and proxy daemon, with clear, powerful and dynamic configuration.
Stars: ✭ 43 (+72%)
Mutual labels:  http2
th2c
Tornado HTTP/2 Client
Stars: ✭ 79 (+216%)
Mutual labels:  http2
caffe-simnets
The SimNets Architecture's Implementation in Caffe
Stars: ✭ 13 (-48%)
Mutual labels:  research-project
3dub
www dev server with livereload, file watching, http2, https, self signed cert generation
Stars: ✭ 28 (+12%)
Mutual labels:  http2
Espresso
☕ Bridge your C# soul to the power of Javascript (V8 Javascript Engine / NodeJs)
Stars: ✭ 54 (+116%)
Mutual labels:  http2
jetty-load-generator
jetty-project.github.io/jetty-load-generator/
Stars: ✭ 62 (+148%)
Mutual labels:  http2
varnish
Varnish docker container image
Stars: ✭ 55 (+120%)
Mutual labels:  varnish
varnish-operator
Run and manage Varnish clusters on Kubernetes
Stars: ✭ 47 (+88%)
Mutual labels:  varnish
django-http2-middleware
⚡️Django middleware to automatically send preload headers before views runs, enabling faster HTTP2 server-push (with CSP support).
Stars: ✭ 65 (+160%)
Mutual labels:  http2

CASHPACK - The C Anti-State HPACK library

cashpack logo

cashpack is a stateless event-driven HPACK codec aimed at embedded systems, or more specifically memory-constrained systems.

It is meant to work with HTTP/2 or similar protocols in the sense that some assumptions made by the library would not work in all situations. For example, HTTP/2 doesn't allow upper-case characters in header names, neither does cashpack.

Coverity Scan badge Codecov badge

It started as a research project and became the basis for Varnish Cache's HPACK implementation, it is now a test bed for Varnish and Hitch TLS. To learn more about its origins, you can watch this talk from the first edition of VarnishCon.

How to use

Grab the latest release archive, and once inside the source directory follow these steps:

$ ./configure --disable-docs
$ make
$ make check # optional but recommended
$ sudo make install

Once installed, you will find comprehensive documentation and also examples in the manual. You can use the cashpack(3) manual as an entry point:

$ man cashpack

Hacking

cashpack relies on autotools for building, and a range of tools for testing and code coverage. The basic usage is as follows:

$ path/to/cashpack/bootstrap \
>        [--with-memcheck]   \
>        [--with-asan]       \
>        [--with-msan]       \
>        [--with-ubsan]      \
>        [--with-lcov]
$ make check

The first command will reveal the missing bits, and the second the potential failures. Code coverage MUST be turned off when the test suite is used for checking because it turns off assertions.

The bootstrap script needs to be run only once. In order to reconfigure the build tree, you can use autoconf's configure script. Command-line arguments to the bootstrap script are passed to configure.

For code coverage, the simplest way to get a report is as follows:

$ path/to/cashpack/bootsrap --with-lcov
$ make lcov
$ xdg-open lcov/index.html

Despite a paranoid coding style, insane code coverage and the benefits of open-source [1] it may not be exempt of security flaws. You can learn more from the test suite's README file too. The build system portability is limited mostly to GNU/Linux systems. Building the project should work fine on other systems except for dist archives that may ship with a broken header file.

Design goals

  1. Code clarity

This goal overrides all the others. Code clarity prevails over other goals unless numbers show that optimizations are required. Because of the natural indirection created by an event-driven approach (it leads to the fifth circle of the callback hell) accidental complexity should be kept to a minimum.

  1. Stateless event drivers

An HPACK implementation cannot be completely stateless, because a dynamic table needs to be maintained. There is also the need to be able to decode partial HPACK blocks incrementally. The event-driven API on the other hand is completely stateless, and can carry user-defined state.

  1. Single allocation

An HPACK instance requires a single allocation, and it is possible to plug your own allocator. An update of the dynamic table size will require (at most) a single reallocation too.

By default cashpack relies on malloc(3), realloc(3) and free(3).

  1. Single-copy in the library code

Except when a field needs to be inserted in the dynamic table, cashpack may copy, decode, or encode data exactly once. The goal used to be zero-copy but proved to be harder to implement and less efficient. Insertions in the dynamic tables copy data a second "single" time, but contents need to be moved prior to that. Under certain circumstances, data may need to be moved in several steps, but only during encoding. This is no longer a DoS vector for decoding.

Evictions from the dynamic table on the other hand are very cheap.

  1. Self-contained

Besides the standard C library, cashpack doesn't pull anything at run time.

It can be verified by looking at the shared object:

$ make
$ nm -D lib/.libs/libhpack.so |           # list dynamic symbols
> awk 'NF == 2 && $1 == "U" {print $2}' | # keep undefined symbols
> grep -v '^_'                            # drop __weak symbols
free
malloc
memcpy
memmove
memset
realloc
strchr
strlen
  1. No system calls

cashpack is not responsible for writing or reading HPACK blocks, it will only send events during decoding or encoding.

  1. No locking

Assuming an HTTP/2 or similar usage, no locking is required. The decoding or encoding should happen in the HTTP/2 RX or TX loop, which is ordered. Being designed for single allocation, there is also no hidden locking after the initialization completes. It is also possible to achieve no locking at all by using a different allocator.

  1. Decoding as a state machine

Events are triggered following deterministic finite state machines, which hopefully should help better understand the decoding flow.

  1. Tight API

The HPACK state is opaque to the library user. It is however possible to inspect the dynamic table in order to know its contents. This is done with the decoder's event driver, but in a simpler state machine.

  1. A human-friendly test suite

It is possible to just copy/paste hexdumps and other bits from the HPACK specification in order to write tests. All examples from RFC 7541 are already covered by the test suite.

There are no unit tests, instead C programs are written to interact with the library with a Bourne Shell test suite on top of them.

  1. Abuse 3-letters abbreviations and acronyms

Function names are actually made up using proper words, but the rest is a collection of 3-letter symbols. 4-letter symbols are tolerated as long as enough 2-letter symbols restore the balance.

[1]Having many eyes not reviewing the code
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].