32 lines
1.9 KiB
C
32 lines
1.9 KiB
C
/* Модель истории для тестов с заранее заданными участниками, без запуска chat_sync.
|
|
* Общий Merkle настоящий; пустая MEMBERS-модель не реплицирует тестовые удостоверения.
|
|
* Если движок создан фикстурой (!chat_sync), перед destroy ядра вызвать merkle_sync_destroy. */
|
|
#ifndef TEST_DB_SYNC_FIXTURE_H
|
|
#define TEST_DB_SYNC_FIXTURE_H
|
|
#include "../src/utun_instance.h"
|
|
#include "../src/transport_layer/etcp_api.h"
|
|
#include "../src/chat/db_sync.h"
|
|
#include "../src/chat/merkle_sync.h"
|
|
#include <string.h>
|
|
|
|
static int fixture_member_hash(void* ctx, const char* ns, uint8_t level, uint64_t prefix, EVP_MD_CTX* hash) {
|
|
(void)ctx; (void)ns; (void)level; (void)prefix; (void)hash; return 0;
|
|
}
|
|
static int fixture_member_page(void* ctx, const char* ns, uint64_t prefix, int av, const merkle_key_t* after,
|
|
uint8_t* data, size_t* len, merkle_key_t* next, int* more) {
|
|
(void)ctx; (void)ns; (void)prefix; (void)av; (void)after; (void)data;
|
|
*len = 0; *more = 0; memset(next, 0, sizeof(*next)); return 0;
|
|
}
|
|
static int fixture_member_apply(void* ctx, const char* ns, uint64_t peer, const uint8_t* data, size_t len) {
|
|
(void)ctx; (void)ns; (void)peer; (void)data; return len ? -1 : 0;
|
|
}
|
|
/* После init ядра и регистрации таблиц; 0/-1. READY/допуск пира/подписи истории не подменяются. */
|
|
static int setup_history_model(struct UTUN_INSTANCE* inst) {
|
|
static const struct merkle_sync_data_ops ops = {
|
|
.update_bucket_hash = fixture_member_hash, .get_page = fixture_member_page, .apply_items = fixture_member_apply
|
|
};
|
|
if (!inst->msync && merkle_sync_init(inst, ETCP_ID_MEMBER_SYNC, &ops, inst) < 0) return -1;
|
|
return db_sync_register_model(inst);
|
|
}
|
|
#endif
|