/* junction/mesh.h — shared response cache across instances, without a service in * between. * * Every node keeps its cache in its own memory and hands it out over a port of its * own. A node that misses locally asks its peers before it pays the provider; a node * that fills a cache entry pushes it to its peers. No Redis, no memcached, no daemon: * the transport is a very small HTTP subset with a binary frame inside. * * Replication is a speedup, never a dependency. A peer that is slow, dead or has a * different key costs the timeout and nothing else — the request goes to the provider * as if the mesh did not exist. That is why the timeouts are short and the push is * fire-and-forget. */ #ifndef J_MESH_H #define J_MESH_H #include #include /* Starts the listener if the configuration names one. Returns 1 when the mesh is * running, 0 when it is off or the port could not be bound. */ int j_mesh_start(void); void j_mesh_stop(void); /* 0 = a peer had it; the buffers are malloc'd and belong to the caller. * Everything else = nobody had it, or nobody answered. */ int j_mesh_lookup(uint64_t key, char **head, size_t *head_len, char **body, size_t *body_len, double *age); /* Hands one filled entry to the peers. Returns immediately; the transfer runs in its * own thread and is dropped when too many are already on their way. */ void j_mesh_store(uint64_t key, const char *head, size_t head_len, const char *body, size_t body_len, double ttl_s); /* Counters for /status and /metrics. Any pointer may be NULL. */ void j_mesh_stats(unsigned long *lookups, unsigned long *hits, unsigned long *pushes, unsigned long *errors, int *peers); #endif /* J_MESH_H */