mirror of
https://github.com/logos-messaging/negentropy.git
synced 2026-01-07 00:13:12 +00:00
chore: optimize initiate and reconcile
This commit is contained in:
parent
1411f20219
commit
f871ff9cd7
@ -81,45 +81,52 @@ int main(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
buffer b4 ;
|
buffer b4 ;
|
||||||
b4.len = 153600;
|
b4.len = 0;
|
||||||
b4.data = (unsigned char*)malloc(153600);
|
b4.data = (unsigned char*)malloc(37*sizeof(unsigned char));
|
||||||
|
|
||||||
printf("storage size of st2 is %d \n",storage_size(st2));
|
printf("storage size of st2 is %d \n",storage_size(st2));
|
||||||
|
result res;
|
||||||
size_t outSize = negentropy_initiate(ngn_inst1, &b4);
|
int ret1 = negentropy_initiate(ngn_inst1, &res);
|
||||||
if(outSize == 0){
|
if(ret1 < 0){
|
||||||
perror("failed to initiate negentropy instance");
|
perror("failed to initiate negentropy instance");
|
||||||
}
|
}
|
||||||
printf("initiated negentropy successfully with output of len %zu \n", outSize);
|
printf("initiated negentropy successfully with output of len %llu \n", res.output.len);
|
||||||
b4.len = outSize;
|
b4.len = res.output.len;
|
||||||
|
memcpy(b4.data, res.output.data, res.output.len);
|
||||||
|
free_result(&res);
|
||||||
|
|
||||||
buffer b3 ;
|
buffer b3 ;
|
||||||
b3.len = 153600;
|
b3.len = 0;
|
||||||
b3.data = (unsigned char*)malloc(153600);
|
b3.data = (unsigned char*)malloc(69*sizeof(unsigned char));
|
||||||
|
|
||||||
outSize = reconcile(ngn_inst2, &b4, &b3);
|
ret1 = reconcile(ngn_inst2, &b4, &res);
|
||||||
if(outSize == 0){
|
if(ret1 < 0){
|
||||||
perror("nothing to reconcile");
|
perror("error from reconcile");
|
||||||
}
|
}
|
||||||
printf("reconcile returned with output of len %zu \n", outSize);
|
if (res.output.len == 0){
|
||||||
b3.len = outSize;
|
perror("nothing to reconcile");
|
||||||
|
}
|
||||||
|
printf("reconcile returned with output of len %llu \n", res.output.len);
|
||||||
|
b3.len = res.output.len;
|
||||||
|
memcpy(b3.data, res.output.data, res.output.len);
|
||||||
|
free_result(&res);
|
||||||
//outSize = reconcile_with_ids(ngn_inst1, &b3, &rec_callback);
|
//outSize = reconcile_with_ids(ngn_inst1, &b3, &rec_callback);
|
||||||
|
|
||||||
result res;
|
result res1;
|
||||||
reconcile_with_ids_no_cbk(ngn_inst1, &b3, &res);
|
reconcile_with_ids_no_cbk(ngn_inst1, &b3, &res1);
|
||||||
printf("needIds count:%llu , haveIds count: %llu \n",res.need_ids_len, res.have_ids_len);
|
printf("needIds count:%llu , haveIds count: %llu \n",res1.need_ids_len, res1.have_ids_len);
|
||||||
|
|
||||||
for (int i=0; i < res.need_ids_len ; i++) {
|
for (int i=0; i < res1.need_ids_len ; i++) {
|
||||||
printf("need ID at %d :", i);
|
printf("need ID at %d :", i);
|
||||||
printHexBuffer(res.need_ids[i]);
|
printHexBuffer(res1.need_ids[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int j=0; j < res.have_ids_len ; j++) {
|
for (int j=0; j < res1.have_ids_len ; j++) {
|
||||||
printf("need ID at %d :", j);
|
printf("need ID at %d :", j);
|
||||||
printHexBuffer(res.have_ids[j]);
|
printHexBuffer(res1.have_ids[j]);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(b3.data);
|
free(b3.data);
|
||||||
free(b4.data);
|
free(b4.data);
|
||||||
|
free_result(&res1);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -65,7 +65,7 @@ void* negentropy_new(void* storage, uint64_t frameSizeLimit){
|
|||||||
return ne;
|
return ne;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t negentropy_initiate(void* negentropy, buffer* out){
|
int negentropy_initiate(void* negentropy, result* result){
|
||||||
Negentropy<negentropy::storage::BTreeMem>* ngn_inst;
|
Negentropy<negentropy::storage::BTreeMem>* ngn_inst;
|
||||||
ngn_inst = reinterpret_cast<Negentropy<negentropy::storage::BTreeMem>*>(negentropy);
|
ngn_inst = reinterpret_cast<Negentropy<negentropy::storage::BTreeMem>*>(negentropy);
|
||||||
|
|
||||||
@ -77,12 +77,18 @@ size_t negentropy_initiate(void* negentropy, buffer* out){
|
|||||||
} catch(negentropy::err e){
|
} catch(negentropy::err e){
|
||||||
std::cout << "Exception raised in initiate " << e.what() << std::endl;
|
std::cout << "Exception raised in initiate " << e.what() << std::endl;
|
||||||
//TODO:Find a way to return this error
|
//TODO:Find a way to return this error
|
||||||
return 0;
|
return -1;
|
||||||
|
}
|
||||||
|
if (output->size() > 0 ){
|
||||||
|
result->output.len = output->size();
|
||||||
|
result->output.data = (unsigned char*)calloc(output->size(), sizeof(unsigned char));
|
||||||
|
memcpy(result->output.data, (unsigned char*)output->c_str(),result->output.len) ;
|
||||||
|
}else {
|
||||||
|
result->output.len = 0;
|
||||||
|
result->output.data = NULL;
|
||||||
}
|
}
|
||||||
memcpy( out->data, output->c_str() ,output->size());
|
|
||||||
size_t outlen = output->size();
|
|
||||||
delete output;
|
delete output;
|
||||||
return outlen;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void negentropy_setinitiator(void* negentropy){
|
void negentropy_setinitiator(void* negentropy){
|
||||||
@ -118,7 +124,7 @@ bool storage_erase(void* storage, uint64_t createdAt, buffer* id){
|
|||||||
return lmdbStorage->erase(createdAt, data);
|
return lmdbStorage->erase(createdAt, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t reconcile(void* negentropy, buffer* query, buffer* output){
|
int reconcile(void* negentropy, buffer* query, result* result){
|
||||||
Negentropy<negentropy::storage::BTreeMem> *ngn_inst;
|
Negentropy<negentropy::storage::BTreeMem> *ngn_inst;
|
||||||
ngn_inst = reinterpret_cast<Negentropy<negentropy::storage::BTreeMem>*>(negentropy);
|
ngn_inst = reinterpret_cast<Negentropy<negentropy::storage::BTreeMem>*>(negentropy);
|
||||||
std::string* out = new std::string();
|
std::string* out = new std::string();
|
||||||
@ -129,10 +135,17 @@ size_t reconcile(void* negentropy, buffer* query, buffer* output){
|
|||||||
} catch(negentropy::err e){
|
} catch(negentropy::err e){
|
||||||
//TODO:Find a way to return this error
|
//TODO:Find a way to return this error
|
||||||
std::cout << "Exception raised in reconcile " << e.what() << std::endl;
|
std::cout << "Exception raised in reconcile " << e.what() << std::endl;
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
memcpy( output->data, out->c_str() ,out->size());
|
if (out->size() > 0 ){
|
||||||
return out->size();
|
result->output.len = out->size();
|
||||||
|
result->output.data = (unsigned char*)calloc(out->size(), sizeof(unsigned char));
|
||||||
|
memcpy(result->output.data, (unsigned char*)out->c_str(),result->output.len) ;
|
||||||
|
}else {
|
||||||
|
result->output.len = 0;
|
||||||
|
result->output.data = NULL;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void transform(std::vector<std::string> &from_ids, buffer* to_ids)
|
void transform(std::vector<std::string> &from_ids, buffer* to_ids)
|
||||||
|
|||||||
@ -34,7 +34,7 @@ EXTERNC void* negentropy_new(void* storage, uint64_t frameSizeLimit);
|
|||||||
|
|
||||||
EXTERNC void negentropy_delete(void* negentropy);
|
EXTERNC void negentropy_delete(void* negentropy);
|
||||||
|
|
||||||
EXTERNC size_t negentropy_initiate(void* negentropy, buffer* output);
|
EXTERNC int negentropy_initiate(void* negentropy, result* result);
|
||||||
|
|
||||||
EXTERNC void negentropy_setinitiator(void* negentropy);
|
EXTERNC void negentropy_setinitiator(void* negentropy);
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ EXTERNC bool storage_insert(void* storage, uint64_t createdAt, buffer* id);
|
|||||||
|
|
||||||
EXTERNC bool storage_erase(void* storage, uint64_t createdAt, buffer* id);
|
EXTERNC bool storage_erase(void* storage, uint64_t createdAt, buffer* id);
|
||||||
|
|
||||||
EXTERNC size_t reconcile(void* negentropy, buffer* query, buffer* output);
|
EXTERNC int reconcile(void* negentropy, buffer* query, result* result);
|
||||||
|
|
||||||
EXTERNC typedef void (*reconcile_cbk)(buffer* have_ids, uint64_t have_ids_len, buffer* need_ids, uint64_t need_ids_len, buffer* output, char* outptr );
|
EXTERNC typedef void (*reconcile_cbk)(buffer* have_ids, uint64_t have_ids_len, buffer* need_ids, uint64_t need_ids_len, buffer* output, char* outptr );
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user