mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-23 15:02:27 +00:00
c35af0617a
- make "debug.h" a private header so that the DEBUG() macro does not interfere with Xcode Debug builds, which set DEBUG=1 - move all #include "debug.h" from headers into .c files - move 'struct idebug' into a new public header "idebug.h" so that "log.h" can be public - move HTTPD port number defs from "httpd.h" to "constants.h", so that "httpd.h" can be private and "conf.h" can be public - add missing nested includes so each header compiles stand-alone without error - #include "sodium.h" instead of <sodium.h> - #include "sqlite3.h" instead of <sqlite3.h> - add header guard to "fifo.h" - fix header guard in "sync_keys.h"
49 lines
1.8 KiB
C
49 lines
1.8 KiB
C
#ifndef __SERVAL_DNA__SYNC_H
|
|
#define __SERVAL_DNA__SYNC_H
|
|
|
|
#include <stdint.h> // for uint8_t
|
|
#include "str.h" // for alloca_tohex()
|
|
|
|
/*
|
|
Synchronize two sets of keys, which are likely to contain many common values
|
|
*/
|
|
|
|
#define KEY_LEN 8
|
|
#define PREFIX_STEP_BITS 1
|
|
#define SYNC_MAX_RETRIES 1
|
|
|
|
typedef struct {
|
|
uint8_t key[KEY_LEN];
|
|
}sync_key_t;
|
|
|
|
#define alloca_sync_key(K) alloca_tohex((K)->key, KEY_LEN)
|
|
|
|
struct sync_state;
|
|
|
|
typedef void (*peer_has) (void *context, void *peer_context, const sync_key_t *key);
|
|
typedef void (*peer_does_not_have) (void *context, void *peer_context, void *key_context, const sync_key_t *key);
|
|
typedef void (*peer_now_has) (void *context, void *peer_context, void *key_context, const sync_key_t *key);
|
|
|
|
struct sync_state* sync_alloc_state(void *context, peer_has has, peer_does_not_have has_not, peer_now_has now_has);
|
|
void sync_free_state(struct sync_state *state);
|
|
|
|
// throw away all state related to peer
|
|
void sync_free_peer_state(struct sync_state *state, void *peer_context);
|
|
|
|
// tell the sync process that we now have key, with callback context
|
|
// if the key is already present, the context will be updated
|
|
void sync_add_key(struct sync_state *state, const sync_key_t *key, void *key_context);
|
|
int sync_key_exists(const struct sync_state *state, const sync_key_t *key);
|
|
int sync_has_transmit_queued(const struct sync_state *state);
|
|
|
|
// ask for a message to be inserted into buff, returns packet length
|
|
size_t sync_build_message(struct sync_state *state, uint8_t *buff, size_t len);
|
|
|
|
// process a message received from a peer.
|
|
int sync_recv_message(struct sync_state *state, void *peer_context, const uint8_t *buff, size_t len);
|
|
|
|
void sync_enum_differences(struct sync_state *state,
|
|
void (*callback)(void *context, void *peer_context, const sync_key_t *key, uint8_t theirs));
|
|
|
|
#endif // __SERVAL_DNA__SYNC_H
|