|
|
|
|
@ -43,7 +43,7 @@ struct DB_SYNC_INSTANCE {
|
|
|
|
|
uint64_t hash; |
|
|
|
|
char table_name[64]; |
|
|
|
|
uint64_t next_id; |
|
|
|
|
uint64_t last_timestamp_us; |
|
|
|
|
uint64_t last_timestamp_ms; |
|
|
|
|
uint8_t enabled; |
|
|
|
|
void* ttl_timer; |
|
|
|
|
struct SI_PEER* peers; |
|
|
|
|
@ -351,8 +351,8 @@ int db_sync_insert_len(struct DB_SYNC_INSTANCE* si, const char* json_data, size_
|
|
|
|
|
|
|
|
|
|
int db_sync_insert_signed(struct DB_SYNC_INSTANCE* si, const char* json_data, size_t len, const uint8_t* sig, size_t sig_len) { |
|
|
|
|
if (!si||!si->enabled||!json_data||len==0) { DEBUG_ERROR(DEBUG_CATEGORY_DB_SYNC,"insert invalid args"); return -1; } |
|
|
|
|
struct timeval tv; utun_gettimeofday(&tv, NULL); uint64_t nu=(uint64_t)tv.tv_sec*1000000ULL+(uint64_t)tv.tv_usec; |
|
|
|
|
if (nu<=si->last_timestamp_us) nu=si->last_timestamp_us+1; si->last_timestamp_us=nu; |
|
|
|
|
struct timeval tv; utun_gettimeofday(&tv, NULL); uint64_t nu=(uint64_t)tv.tv_sec*1000ULL+(uint64_t)tv.tv_usec/1000ULL; |
|
|
|
|
if (nu<=si->last_timestamp_ms) nu=si->last_timestamp_ms+1; si->last_timestamp_ms=nu; |
|
|
|
|
uint64_t dh=db_datahash((const uint8_t*)json_data,len), ts=nu, id=si->next_id; |
|
|
|
|
int ret=db_record_insert(si,id,ts,dh,json_data,len,sig,sig_len); if (ret!=0) return ret; |
|
|
|
|
if (si->on_insert) si->on_insert(si,json_data,len,si->db_sync->inst->node_id,si->on_insert_arg); |
|
|
|
|
@ -372,7 +372,7 @@ uint32_t db_sync_count(struct DB_SYNC_INSTANCE* si) { if (!si||!si->enabled) ret
|
|
|
|
|
|
|
|
|
|
void db_sync_set_insert_cb(struct DB_SYNC_INSTANCE* si, db_sync_insert_cb cb, void* arg) { if (!si) return; si->on_insert=cb; si->on_insert_arg=arg; } |
|
|
|
|
|
|
|
|
|
uint64_t db_sync_get_last_timestamp(struct DB_SYNC_INSTANCE* si) { return si ? si->last_timestamp_us : 0; } |
|
|
|
|
uint64_t db_sync_get_last_timestamp(struct DB_SYNC_INSTANCE* si) { return si ? si->last_timestamp_ms : 0; } |
|
|
|
|
|
|
|
|
|
int db_sync_select(struct DB_SYNC_INSTANCE* si, uint32_t offset, uint32_t limit, db_sync_select_cb cb, void* arg) { |
|
|
|
|
if (!si||!si->enabled||!cb) return 0; sqlite3_stmt* stmt; |
|
|
|
|
|