Exemple #1
0
void rlwe_kex_compute_key_bob(const uint32_t b[1024], const uint32_t s[1024], uint64_t c[16], uint64_t k[16], FFT_CTX *ctx) {
	uint32_t v[1024];
	uint32_t eprimeprime[1024];
	RAND_CTX rand_ctx;
	if (!RAND_CTX_init(&rand_ctx)) {
		fprintf(stderr, "Randomness allocation error.");
		return;
	}
#if CONSTANT_TIME
	sample_ct(eprimeprime, &rand_ctx);
#else
	sample(eprimeprime, &rand_ctx);
#endif
	key_gen(v, b, s, eprimeprime, ctx);
#if CONSTANT_TIME
	crossround2_ct(c, v, &rand_ctx`);
	round2_ct(k, v);
#else
	crossround2(c, v, &rand_ctx);
	round2(k, v);
#endif
	memset((char *) v, 0, 1024 * sizeof(uint32_t));
	memset((char *) eprimeprime, 0, 1024 * sizeof(uint32_t));
	RAND_CTX_cleanup(&rand_ctx);
}
Exemple #2
0
/*
 * col_remove --
 *	Remove a row from a column-store file.
 */
static void
col_remove(WT_CURSOR *cursor, WT_ITEM *key, uint64_t keyno, int *notfoundp)
{
	WT_SESSION *session;
	int notfound, ret;

	session = cursor->session;

	/* Log the operation */
	if (g.logging == LOG_OPS)
		(void)session->msg_printf(
		    session, "%-10s%" PRIu64, "remove", keyno);

	cursor->set_key(cursor, keyno);
	ret = cursor->remove(cursor);
	if (ret != 0 && ret != WT_NOTFOUND)
		die(ret, "col_remove: remove %" PRIu64 " by key", keyno);
	*notfoundp = ret == WT_NOTFOUND;

	if (!SINGLETHREADED)
		return;

	/*
	 * Deleting a fixed-length item is the same as setting the bits to 0;
	 * do the same thing for the BDB store.
	 */
	if (g.c_file_type == FIX) {
		key_gen((uint8_t *)key->data, &key->size, keyno, 0);
		bdb_update(key->data, key->size, "\0", 1, &notfound);
	} else
		bdb_remove(keyno, &notfound);

	(void)notfound_chk("col_remove", ret, notfound, keyno);
}
Exemple #3
0
damgard_jurik::damgard_jurik(unsigned long s, int bitsmodule, damgard_jurik_get_rand_t rand_func) {
    pubkey = new damgard_jurik_pubkey_t();
    prvkey = new damgard_jurik_prvkey_t();
    this->s_max = s;
    this->rand_func = rand_func;
    key_gen(bitsmodule);
}
Exemple #4
0
void
bdb_remove(uint64_t keyno, int *notfoundp)
{
	DBC *dbc = g.dbc;
	size_t size;
	int ret;

	size = 0;
	key_gen(&keyitem, keyno);
	key.data = (void *)keyitem.data;
	key.size = (u_int32_t)keyitem.size;

	bdb_read(keyno, &value.data, &size, notfoundp);
	value.size = (u_int32_t)size;
	if (*notfoundp)
		return;

	/* Deleting a fixed-length item is the same as setting the bits to 0. */
	if (g.type == FIX)
		bdb_update(key.data, key.size, "", 1);
	else
		if ((ret = dbc->del(dbc, 0)) != 0) {
			if (ret != DB_NOTFOUND)
				bdb_die(ret, "dbc.del: {%.*s}",
				    (int)key.size, (char *)key.data);
			*notfoundp = 1;
		}
}
Exemple #5
0
/*
 * row_remove --
 *	Remove an row from a row-store file.
 */
static int
row_remove(WT_CURSOR *cursor, WT_ITEM *key, uint64_t keyno, int *notfoundp)
{
	WT_SESSION *session;
	int notfound, ret;

	session = cursor->session;

	key_gen((uint8_t *)key->data, &key->size, keyno, 0);

	/* Log the operation */
	if (g.logging == LOG_OPS)
		(void)g.wt_api->msg_printf(
		    g.wt_api, session, "%-10s%" PRIu64, "remove", keyno);

	cursor->set_key(cursor, key);
	/* We use the cursor in overwrite mode, check for existence. */
	if ((ret = cursor->search(cursor)) == 0)
		ret = cursor->remove(cursor);
	if (ret == WT_DEADLOCK)
		return (WT_DEADLOCK);
	if (ret != 0 && ret != WT_NOTFOUND)
		die(ret, "row_remove: remove %" PRIu64 " by key", keyno);
	*notfoundp = (ret == WT_NOTFOUND);

	if (!SINGLETHREADED)
		return (0);

	bdb_remove(keyno, &notfound);
	(void)notfound_chk("row_remove", ret, notfound, keyno);
	return (0);
}
Exemple #6
0
/*
 * row_insert --
 *	Insert a row in a row-store file.
 */
static int
row_insert(
    WT_CURSOR *cursor, WT_ITEM *key, WT_ITEM *value, uint64_t keyno)
{
	WT_SESSION *session;
	int notfound, ret;

	session = cursor->session;

	key_gen((uint8_t *)key->data, &key->size, keyno, 1);
	value_gen((uint8_t *)value->data, &value->size, keyno);

	/* Log the operation */
	if (g.logging == LOG_OPS)
		(void)g.wt_api->msg_printf(g.wt_api, session,
		    "%-10s{%.*s}\n%-10s{%.*s}",
		    "insertK", (int)key->size, (char *)key->data,
		    "insertV", (int)value->size, (char *)value->data);

	cursor->set_key(cursor, key);
	cursor->set_value(cursor, value);
	ret = cursor->insert(cursor);
	if (ret == WT_DEADLOCK)
		return (WT_DEADLOCK);
	if (ret != 0 && ret != WT_NOTFOUND)
		die(ret, "row_insert: insert row %" PRIu64 " by key", keyno);

	if (!SINGLETHREADED)
		return (0);

	bdb_update(key->data, key->size, value->data, value->size, &notfound);
	(void)notfound_chk("row_insert", ret, notfound, keyno);
	return (0);
}
Exemple #7
0
/*
 * row_remove --
 *	Remove an row from a row-store file.
 */
static void
row_remove(WT_CURSOR *cursor, WT_ITEM *key, uint64_t keyno, int *notfoundp)
{
	WT_SESSION *session;
	int notfound, ret;

	session = cursor->session;

	key_gen((uint8_t *)key->data, &key->size, keyno, 0);

	/* Log the operation */
	if (g.logging == LOG_OPS)
		(void)session->msg_printf(
		    session, "%-10s%" PRIu64, "remove", keyno);

	cursor->set_key(cursor, key);
	ret = cursor->remove(cursor);
	if (ret != 0 && ret != WT_NOTFOUND)
		die(ret, "row_remove: remove %" PRIu64 " by key", keyno);
	*notfoundp = ret == WT_NOTFOUND;

	if (!SINGLETHREADED)
		return;

	bdb_remove(keyno, &notfound);
	(void)notfound_chk("row_remove", ret, notfound, keyno);
}
Exemple #8
0
/*
 * row_update --
 *	Update a row in a row-store file.
 */
static void
row_update(
    WT_CURSOR *cursor, WT_ITEM *key, WT_ITEM *value, uint64_t keyno, int insert)
{
	WT_SESSION *session;
	int notfound, ret;

	session = cursor->session;

	key_gen((uint8_t *)key->data, &key->size, keyno, insert);
	value_gen((uint8_t *)value->data, &value->size, keyno);

	/* Log the operation */
	if (g.logging == LOG_OPS)
		(void)session->msg_printf(session, "%-10s{%.*s}\n%-10s{%.*s}",
		    insert ? "insertK" : "putK",
		    (int)key->size, (char *)key->data,
		    insert ? "insertV" : "putV",
		    (int)value->size, (char *)value->data);

	cursor->set_key(cursor, key);
	cursor->set_value(cursor, value);
	ret = cursor->insert(cursor);
	if (ret != 0 && ret != WT_NOTFOUND)
		die(ret,
		    "row_update: %s row %" PRIu64 " by key",
		    insert ? "insert" : "update", keyno);

	if (!SINGLETHREADED)
		return;

	bdb_update(key->data, key->size, value->data, value->size, &notfound);
	(void)notfound_chk("row_update", ret, notfound, keyno);
}
Exemple #9
0
/*
 * col_insert --
 *	Insert an element in a column-store file.
 */
static int
col_insert(TINFO *tinfo,
    WT_CURSOR *cursor, WT_ITEM *key, WT_ITEM *value, uint64_t *keynop)
{
	WT_SESSION *session;
	uint64_t keyno;
	int ret;

	session = cursor->session;

	val_gen(&tinfo->rnd, (uint8_t *)value->data, &value->size, g.rows + 1);

	if (g.type == FIX)
		cursor->set_value(cursor, *(uint8_t *)value->data);
	else
		cursor->set_value(cursor, value);
	if ((ret = cursor->insert(cursor)) != 0) {
		if (ret == WT_ROLLBACK)
			return (WT_ROLLBACK);
		die(ret, "cursor.insert");
	}
	if ((ret = cursor->get_key(cursor, &keyno)) != 0)
		die(ret, "cursor.get_key");
	*keynop = (uint32_t)keyno;

	table_append(keyno);			/* Extend the object. */

	if (g.logging == LOG_OPS) {
		if (g.type == FIX)
			(void)g.wt_api->msg_printf(g.wt_api, session,
			    "%-10s%" PRIu64 " {0x%02" PRIx8 "}",
			    "insert", keyno,
			    ((uint8_t *)value->data)[0]);
		else
			(void)g.wt_api->msg_printf(g.wt_api, session,
			    "%-10s%" PRIu64 " {%.*s}",
			    "insert", keyno,
			    (int)value->size, (char *)value->data);
	}

#ifdef HAVE_BERKELEY_DB
	if (!SINGLETHREADED)
		return (0);

	{
	int notfound;

	key_gen((uint8_t *)key->data, &key->size, keyno);
	bdb_update(key->data, key->size, value->data, value->size, &notfound);
	}
#else
	(void)key;				/* [-Wunused-variable] */
#endif
	return (0);
}
Exemple #10
0
/*
 * col_update --
 *	Update a row in a column-store file.
 */
static int
col_update(TINFO *tinfo,
    WT_CURSOR *cursor, WT_ITEM *key, WT_ITEM *value, uint64_t keyno)
{
	WT_SESSION *session;
	int ret;

	session = cursor->session;

	val_gen(&tinfo->rnd, (uint8_t *)value->data, &value->size, keyno);

	/* Log the operation */
	if (g.logging == LOG_OPS) {
		if (g.type == FIX)
			(void)g.wt_api->msg_printf(g.wt_api, session,
			    "%-10s%" PRIu64 " {0x%02" PRIx8 "}",
			    "update", keyno,
			    ((uint8_t *)value->data)[0]);
		else
			(void)g.wt_api->msg_printf(g.wt_api, session,
			    "%-10s%" PRIu64 " {%.*s}",
			    "update", keyno,
			    (int)value->size, (char *)value->data);
	}

	cursor->set_key(cursor, keyno);
	if (g.type == FIX)
		cursor->set_value(cursor, *(uint8_t *)value->data);
	else
		cursor->set_value(cursor, value);
	ret = cursor->update(cursor);
	if (ret == WT_ROLLBACK)
		return (WT_ROLLBACK);
	if (ret != 0 && ret != WT_NOTFOUND)
		die(ret, "col_update: %" PRIu64, keyno);

#ifdef HAVE_BERKELEY_DB
	if (!SINGLETHREADED)
		return (0);

	{
	int notfound;

	key_gen((uint8_t *)key->data, &key->size, keyno);
	bdb_update(key->data, key->size, value->data, value->size, &notfound);
	(void)notfound_chk("col_update", ret, notfound, keyno);
	}
#else
	(void)key;				/* [-Wunused-variable] */
#endif
	return (0);
}
Exemple #11
0
/*
 * col_insert --
 *	Insert an element in a column-store file.
 */
static void
col_insert(WT_CURSOR *cursor, WT_ITEM *key, WT_ITEM *value, uint64_t *keynop)
{
	WT_SESSION *session;
	uint64_t keyno;
	int notfound, ret;

	session = cursor->session;

	value_gen((uint8_t *)value->data, &value->size, g.rows + 1);

	if (g.c_file_type == FIX)
		cursor->set_value(cursor, *(uint8_t *)value->data);
	else
		cursor->set_value(cursor, value);
	if ((ret = cursor->insert(cursor)) != 0)
		die(ret, "cursor.insert");
	if ((ret = cursor->get_key(cursor, &keyno)) != 0)
		die(ret, "cursor.get_key");
	*keynop = (uint32_t)keyno;

	/*
	 * Assign the maximum number of rows to the returned key: that key may
	 * not be the current maximum value, if we race with another thread,
	 * but that's OK, we just want it to keep increasing so we don't ignore
	 * records at the end of the table.
	 */
	g.rows = (uint32_t)keyno;

	if (g.logging == LOG_OPS) {
		if (g.c_file_type == FIX)
			(void)session->msg_printf(session,
			    "%-10s%" PRIu64 " {0x%02" PRIx8 "}",
			    "insert", keyno,
			    ((uint8_t *)value->data)[0]);
		else
			(void)session->msg_printf(session,
			    "%-10s%" PRIu64 " {%.*s}",
			    "insert", keyno,
			    (int)value->size, (char *)value->data);
	}

	if (!SINGLETHREADED)
		return;

	key_gen((uint8_t *)key->data, &key->size, keyno, 0);
	bdb_update(key->data, key->size, value->data, value->size, &notfound);
}
/*
 * col_remove --
 *	Remove a row from a column-store file.
 */
static int
col_remove(WT_CURSOR *cursor, WT_ITEM *key, uint64_t keyno, int *notfoundp)
{
    WT_SESSION *session;
    int ret;

    session = cursor->session;

    /* Log the operation */
    if (g.logging == LOG_OPS)
        (void)g.wt_api->msg_printf(
            g.wt_api, session, "%-10s%" PRIu64, "remove", keyno);

    cursor->set_key(cursor, keyno);
    /* We use the cursor in overwrite mode, check for existence. */
    if ((ret = cursor->search(cursor)) == 0)
        ret = cursor->remove(cursor);
    if (ret == WT_ROLLBACK)
        return (WT_ROLLBACK);
    if (ret != 0 && ret != WT_NOTFOUND)
        testutil_die(ret,
                     "col_remove: remove %" PRIu64 " by key", keyno);
    *notfoundp = (ret == WT_NOTFOUND);

#ifdef HAVE_BERKELEY_DB
    if (!SINGLETHREADED)
        return (0);

    {
        int notfound;

        /*
         * Deleting a fixed-length item is the same as setting the bits to 0;
         * do the same thing for the BDB store.
         */
        if (g.type == FIX) {
            key_gen((uint8_t *)key->data, &key->size, keyno);
            bdb_update(key->data, key->size, "\0", 1, &notfound);
        } else
            bdb_remove(keyno, &notfound);
        (void)notfound_chk("col_remove", ret, notfound, keyno);
    }
#else
    (void)key;				/* [-Wunused-variable] */
#endif
    return (0);
}
Exemple #13
0
void rlwe_kex_generate_keypair(const uint32_t *a, uint32_t s[1024], uint32_t b[1024], FFT_CTX *ctx) {
	uint32_t e[1024];
	RAND_CTX rand_ctx;
	if (!RAND_CTX_init(&rand_ctx)) {
		fprintf(stderr, "Randomness allocation error.");
		return;
	}
#if CONSTANT_TIME
	sample_ct(s, &rand_ctx);
	sample_ct(e, &rand_ctx);
#else
	sample(s, &rand_ctx);
	sample(e, &rand_ctx);
#endif
	key_gen(b, a, s, e, ctx);
	memset((char *) e, 0, 1024 * sizeof(uint32_t));
	RAND_CTX_cleanup(&rand_ctx);
}
Exemple #14
0
/*
 * col_update --
 *	Update a row in a column-store file.
 */
static int
col_update(WT_CURSOR *cursor, WT_ITEM *key, WT_ITEM *value, uint64_t keyno)
{
	WT_SESSION *session;
	int notfound, ret;

	session = cursor->session;

	value_gen((uint8_t *)value->data, &value->size, keyno);

	/* Log the operation */
	if (g.logging == LOG_OPS) {
		if (g.type == FIX)
			(void)g.wt_api->msg_printf(g.wt_api, session,
			    "%-10s%" PRIu64 " {0x%02" PRIx8 "}",
			    "update", keyno,
			    ((uint8_t *)value->data)[0]);
		else
			(void)g.wt_api->msg_printf(g.wt_api, session,
			    "%-10s%" PRIu64 " {%.*s}",
			    "update", keyno,
			    (int)value->size, (char *)value->data);
	}

	cursor->set_key(cursor, keyno);
	if (g.type == FIX)
		cursor->set_value(cursor, *(uint8_t *)value->data);
	else
		cursor->set_value(cursor, value);
	ret = cursor->update(cursor);
	if (ret == WT_DEADLOCK)
		return (WT_DEADLOCK);
	if (ret != 0 && ret != WT_NOTFOUND)
		die(ret, "col_update: %" PRIu64, keyno);

	if (!SINGLETHREADED)
		return (0);

	key_gen((uint8_t *)key->data, &key->size, keyno, 0);
	bdb_update(key->data, key->size, value->data, value->size, &notfound);
	(void)notfound_chk("col_update", ret, notfound, keyno);
	return (0);
}
Exemple #15
0
void
bdb_remove(uint64_t keyno, int *notfoundp)
{
	DBC *dbc = g.dbc;
	int ret;

	key.data = keybuf;
	key_gen(key.data, &key.size, keyno, 0);

	bdb_read(keyno, &value.data, &value.size, notfoundp);
	if (*notfoundp)
		return;

	if ((ret = dbc->del(dbc, 0)) != 0) {
		if (ret != DB_NOTFOUND)
			die(ret, "dbc.del: {%.*s}",
			    (int)key.size, (char *)key.data);
		*notfoundp = 1;
	}
}
Exemple #16
0
void
bdb_read(uint64_t keyno, void *valuep, uint32_t *valuesizep, int *notfoundp)
{
	DBC *dbc = g.dbc;
	int ret;

	key.data = keybuf;
	key_gen(key.data, &key.size, keyno, 0);

	*notfoundp = 0;
	if ((ret = dbc->get(dbc, &key, &value, DB_SET)) != 0) {
		if (ret != DB_NOTFOUND)
			die(ret, "dbc.get: DB_SET: {%.*s}",
			    (int)key.size, (char *)key.data);
		*notfoundp = 1;
	} else {
		*(void **)valuep = value.data;
		*valuesizep = value.size;
	}
}
/*
 * row_update --
 *	Update a row in a row-store file.
 */
static int
row_update(TINFO *tinfo,
           WT_CURSOR *cursor, WT_ITEM *key, WT_ITEM *value, uint64_t keyno)
{
    WT_SESSION *session;
    int ret;

    session = cursor->session;

    key_gen((uint8_t *)key->data, &key->size, keyno);
    val_gen(&tinfo->rnd, (uint8_t *)value->data, &value->size, keyno);

    /* Log the operation */
    if (g.logging == LOG_OPS)
        (void)g.wt_api->msg_printf(g.wt_api, session,
                                   "%-10s{%.*s}\n%-10s{%.*s}",
                                   "putK", (int)key->size, (char *)key->data,
                                   "putV", (int)value->size, (char *)value->data);

    cursor->set_key(cursor, key);
    cursor->set_value(cursor, value);
    ret = cursor->update(cursor);
    if (ret == WT_ROLLBACK)
        return (WT_ROLLBACK);
    if (ret != 0 && ret != WT_NOTFOUND)
        testutil_die(ret,
                     "row_update: update row %" PRIu64 " by key", keyno);

#ifdef HAVE_BERKELEY_DB
    if (!SINGLETHREADED)
        return (0);

    {
        int notfound;

        bdb_update(key->data, key->size, value->data, value->size, &notfound);
        (void)notfound_chk("row_update", ret, notfound, keyno);
    }
#endif
    return (0);
}
Exemple #18
0
/*
 * read_row --
 *	Read and verify a single element in a row- or column-store file.
 */
static int
read_row(WT_CURSOR *cursor, WT_ITEM *key, uint64_t keyno)
{
	static int sn = 0;
	WT_ITEM value;
	WT_SESSION *session;
	int exact, ret;
	uint8_t bitfield;

	session = cursor->session;

	/* Log the operation */
	if (g.logging == LOG_OPS)
		(void)g.wt_api->msg_printf(g.wt_api,
		    session, "%-10s%" PRIu64, "read", keyno);

	/* Retrieve the key/value pair by key. */
	switch (g.type) {
	case FIX:
	case VAR:
		cursor->set_key(cursor, keyno);
		break;
	case ROW:
		key_gen((uint8_t *)key->data, &key->size, keyno);
		cursor->set_key(cursor, key);
		break;
	}

	if (sn) {
		ret = cursor->search_near(cursor, &exact);
		if (ret == 0 && exact != 0)
			ret = WT_NOTFOUND;
		sn = 0;
	} else {
		ret = cursor->search(cursor);
		sn = 1;
	}
	if (ret == 0) {
		if (g.type == FIX) {
			ret = cursor->get_value(cursor, &bitfield);
			value.data = &bitfield;
			value.size = 1;
		} else {
			ret = cursor->get_value(cursor, &value);
		}
	}
	if (ret == WT_ROLLBACK)
		return (WT_ROLLBACK);
	if (ret != 0 && ret != WT_NOTFOUND)
		die(ret, "read_row: read row %" PRIu64, keyno);

#ifdef HAVE_BERKELEY_DB
	if (!SINGLETHREADED)
		return (0);

	/*
	 * In fixed length stores, zero values at the end of the key space are
	 * returned as not found.  Treat this the same as a zero value in the
	 * key space, to match BDB's behavior.
	 */
	if (ret == WT_NOTFOUND && g.type == FIX) {
		bitfield = 0;
		value.data = &bitfield;
		value.size = 1;
		ret = 0;
	}

	/* Retrieve the BDB value. */
	{
	WT_ITEM bdb_value;
	int notfound;

	bdb_read(keyno, &bdb_value.data, &bdb_value.size, &notfound);

	/* Check for not-found status. */
	if (notfound_chk("read_row", ret, notfound, keyno))
		return (0);

	/* Compare the two. */
	if (value.size != bdb_value.size ||
	    memcmp(value.data, bdb_value.data, value.size) != 0) {
		fprintf(stderr,
		    "read_row: value mismatch %" PRIu64 ":\n", keyno);
		print_item("bdb", &bdb_value);
		print_item(" wt", &value);
		die(0, NULL);
	}
	}
#endif
	return (0);
}
Exemple #19
0
int main(int argc,char *argv[]){
	FILE *file;
	int lines,i;
	char *pos;
	int split=':';
	char buf[512];
	float alpha=0.5;
	float mean;
	float sv;
	int *lset,*sset,*ka;
	//socket part variable statement
	struct sockaddr_in serv;
	int sd;
	if(argc<2)
	{
		printf("usage:./a.out servaddr\n");
		return -1;
	}
	if((file=fopen(PATH,"r"))==NULL)	
	{
		printf("open file error\n");
		return -1;
	}
	lines=getlines(file);	
	int *h=malloc(lines*sizeof(int));
	//int *h=malloc(8000*sizeof(int));
	int line=0;
	if(h==NULL)
	{
		printf("malloc h error\n");
		return -1;
	}
	//reset the file point
	fseek(file,0L,SEEK_SET);
	//printf("current file offset:%d\n",(int)ftello(file));
	while(fgets(buf,sizeof(buf),file)){
		pos=strrchr(buf,split);
		if(pos==NULL)
		{
			printf("wrong format\n");
			return -1;
		}
		buf[strlen(buf)-3]='\0';
		pos+=2;
		h[line++]=atoi(pos);
		printf("%d\n",h[line-1]);
	}
	mean=c_mean(h,lines);
	sv=c_sig(h,lines,mean);	
	printf("%.2f\n",mean);
	printf("%.2f\n",sv);
	qp=mean+alpha*sv;
	qs=mean-alpha*sv;
	printf("%.2f\n",qp);
	printf("%.2f\n",qs);
	if(seq(h,lines,&lset)<0)
	{
		printf("seq error\n");
		return -1;
	}
	//test lset
	printf("lset size:%d\n",lset[0]);
	for(i=1;i<=lset[0];i++)
	{
		printf("%d ",lset[i]);	
	}
	//socket logic to send L,so you had better check forward logic;
	//sockaddr init
	bzero(&serv,sizeof(struct sockaddr_in));	
	serv.sin_family=AF_INET;
	serv.sin_port=htons(PORT);
	serv.sin_addr.s_addr=inet_addr(argv[1]);
	if((sd=socket(AF_INET,SOCK_STREAM,0))<0)
	{
		printf("socket error\n");
		return -1;
	}
	if(connect(sd,(const struct sockaddr *)&serv,sizeof(struct sockaddr))<0)
	{
		printf("connect error\n");
		return -1;
	}
	//send lset,the algorithm select a random subset of lset,we set lset directly here 
	write(sd,lset,(lset[0]+1)*sizeof(int));
	int len;
	printf("wait for sset from bob\n");
	read(sd,&len,sizeof(int));
	printf("sset from bob comes\n");
	printf("sset len:%d\n",len);
	sset=malloc((len+1)*sizeof(int));
	sset[0]=len;
	if(sset==NULL){
		printf("malloc sset error\n");
		return -1;
	}
	read(sd,sset+1,len*sizeof(int));
	//sset test
	for(i=1;i<=len;i++)
	{
		printf("%d ",sset[i]);
	}
	printf("\n");
	close(sd);
	//generate key
	if(key_gen(h,sset,&ka)==-1)
	{
		printf("key_gen error\n");
		return -1;
	}
	for(i=0;i<sset[0];i++){
		printf("%d",ka[i]);
	}
	printf("\n");
	return 0;
}
Exemple #20
0
void
bdb_truncate(uint64_t start, uint64_t stop)
{
	DBC *dbc = g.dbc;
	size_t len;
	int cmp, ret, notfound;

	/* Deleting a fixed-length item is the same as setting the bits to 0. */
	if (g.type == FIX) {
		/*
		 * If we're deleting from/to the start/end of the database,
		 * correct for the number of records we have.
		 */
		if (start == 0)
			start = 1;
		if (stop == 0)
			stop = g.rows;
		for (; start <= stop; ++start)
			bdb_remove(start, &notfound);
		return;
	}

	if (start == 0) {
		ret = dbc->get(dbc, &key, &value, DB_FIRST);
		if (ret != 0 && ret != DB_NOTFOUND)
			bdb_die(ret, "%s", "dbc.get: DB_FIRST");
	} else {
		key_gen(&keyitem, start);
		key.data = (void *)keyitem.data;
		key.size = (u_int32_t)keyitem.size;
		ret = dbc->get(dbc, &key, &value, DB_SET_RANGE);
		if (ret != 0 && ret != DB_NOTFOUND)
			bdb_die(ret, "dbc.get: DB_SET: {%.*s}",
			    (int)key.size, (char *)key.data);
	}
	if (ret == DB_NOTFOUND)
		return;

	if (stop == 0) {
		do {
			ret = dbc->del(dbc, 0);
			if (ret != 0 && ret != DB_NOTFOUND)
				bdb_die(ret, "dbc.del: {%.*s}",
				    (int)key.size, (char *)key.data);
		} while ((ret = dbc->get(dbc, &key, &value, DB_NEXT)) == 0);
	} else {
		key_gen(&keyitem, stop);
		do {
			len = WT_MIN(key.size, keyitem.size);
			cmp = memcmp(key.data, keyitem.data, len);
			if (g.c_reverse) {
				if (cmp < 0 ||
				    (cmp == 0 && key.size < keyitem.size))
					break;
			} else
				if (cmp > 0 ||
				    (cmp == 0 && key.size > keyitem.size))
					break;
			ret = dbc->del(dbc, 0);
			if (ret != 0 && ret != DB_NOTFOUND)
				bdb_die(ret, "dbc.del: {%.*s}",
				    (int)key.size, (char *)key.data);
		} while ((ret = dbc->get(dbc, &key, &value, DB_NEXT)) == 0);
	}
	if (ret != 0 && ret != DB_NOTFOUND)
		bdb_die(ret, "%s", "dbc.get: DB_NEXT");
}
Exemple #21
0
void
wts_load(void)
{
	WT_CONNECTION *conn;
	WT_CURSOR *cursor;
	WT_DECL_RET;
	WT_ITEM key, value;
	WT_SESSION *session;
	bool is_bulk;

	conn = g.wts_conn;

	testutil_check(conn->open_session(conn, NULL, NULL, &session));

	if (g.logging != 0)
		(void)g.wt_api->msg_printf(g.wt_api, session,
		    "=============== bulk load start ===============");

	/*
	 * No bulk load with data-sources.
	 *
	 * No bulk load with custom collators, the order of insertion will not
	 * match the collation order.
	 */
	is_bulk = true;
	if (DATASOURCE("kvsbdb"))
		is_bulk = false;
	if (g.c_reverse)
		is_bulk = false;

	/*
	 * open_cursor can return EBUSY if concurrent with a metadata
	 * operation, retry in that case.
	 */
	while ((ret = session->open_cursor(session, g.uri, NULL,
	    is_bulk ? "bulk,append" : NULL, &cursor)) == EBUSY)
		__wt_yield();
	testutil_check(ret);

	/* Set up the key/value buffers. */
	key_gen_init(&key);
	val_gen_init(&value);

	for (;;) {
		if (++g.key_cnt > g.c_rows) {
			g.key_cnt = g.rows = g.c_rows;
			break;
		}

		/* Report on progress every 100 inserts. */
		if (g.key_cnt % 1000 == 0)
			track("bulk load", g.key_cnt, NULL);

		key_gen(&key, g.key_cnt);
		val_gen(NULL, &value, g.key_cnt);

		switch (g.type) {
		case FIX:
			if (!is_bulk)
				cursor->set_key(cursor, g.key_cnt);
			cursor->set_value(cursor, *(uint8_t *)value.data);
			if (g.logging == LOG_OPS)
				(void)g.wt_api->msg_printf(g.wt_api, session,
				    "%-10s %" PRIu64 " {0x%02" PRIx8 "}",
				    "bulk V",
				    g.key_cnt, ((uint8_t *)value.data)[0]);
			break;
		case VAR:
			if (!is_bulk)
				cursor->set_key(cursor, g.key_cnt);
			cursor->set_value(cursor, &value);
			if (g.logging == LOG_OPS)
				(void)g.wt_api->msg_printf(g.wt_api, session,
				    "%-10s %" PRIu64 " {%.*s}", "bulk V",
				    g.key_cnt,
				    (int)value.size, (char *)value.data);
			break;
		case ROW:
			cursor->set_key(cursor, &key);
			if (g.logging == LOG_OPS)
				(void)g.wt_api->msg_printf(g.wt_api, session,
				    "%-10s %" PRIu64 " {%.*s}", "bulk K",
				    g.key_cnt, (int)key.size, (char *)key.data);
			cursor->set_value(cursor, &value);
			if (g.logging == LOG_OPS)
				(void)g.wt_api->msg_printf(g.wt_api, session,
				    "%-10s %" PRIu64 " {%.*s}", "bulk V",
				    g.key_cnt,
				    (int)value.size, (char *)value.data);
			break;
		}

		/*
		 * We don't want to size the cache to ensure the initial data
		 * set can load in the in-memory case, guaranteeing the load
		 * succeeds probably means future updates are also guaranteed
		 * to succeed, which isn't what we want. If we run out of space
		 * in the initial load, reset the row counter and continue.
		 *
		 * Decrease inserts, they can't be successful if we're at the
		 * cache limit, and increase the delete percentage to get some
		 * extra space once the run starts.
		 */
		if ((ret = cursor->insert(cursor)) != 0) {
			if (ret != WT_CACHE_FULL)
				testutil_die(ret, "cursor.insert");
			g.rows = --g.key_cnt;
			g.c_rows = (uint32_t)g.key_cnt;

			if (g.c_insert_pct > 5)
				g.c_insert_pct = 5;
			if (g.c_delete_pct < 20)
				g.c_delete_pct += 20;
			break;
		}

#ifdef HAVE_BERKELEY_DB
		if (SINGLETHREADED)
			bdb_insert(key.data, key.size, value.data, value.size);
#endif
	}

	testutil_check(cursor->close(cursor));

	if (g.logging != 0)
		(void)g.wt_api->msg_printf(g.wt_api, session,
		    "=============== bulk load stop ===============");

	testutil_check(session->close(session, NULL));

	key_gen_teardown(&key);
	val_gen_teardown(&value);
}
Exemple #22
0
void
wts_load(void)
{
	WT_CONNECTION *conn;
	WT_CURSOR *cursor;
	WT_ITEM key, value;
	WT_SESSION *session;
	uint8_t *keybuf, *valbuf;
	int is_bulk, ret;

	conn = g.wts_conn;

	if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0)
		die(ret, "connection.open_session");

	if (g.logging != 0)
		(void)g.wt_api->msg_printf(g.wt_api, session,
		    "=============== bulk load start ===============");

	/*
	 * Avoid bulk load with KVS (there's no bulk load support for a
	 * data-source); avoid bulk load with a custom collator, because
	 * the order of insertion will not match the collation order.
	 */
	is_bulk = !g.c_reverse &&
	    !DATASOURCE("kvsbdb") && !DATASOURCE("helium");
	if ((ret = session->open_cursor(session, g.uri, NULL,
	    is_bulk ? "bulk" : NULL, &cursor)) != 0)
		die(ret, "session.open_cursor");

	/* Set up the default key buffer. */
	key_gen_setup(&keybuf);
	val_gen_setup(&valbuf);

	for (;;) {
		if (++g.key_cnt > g.c_rows) {
			g.key_cnt = g.rows = g.c_rows;
			break;
		}

		/* Report on progress every 100 inserts. */
		if (g.key_cnt % 100 == 0)
			track("bulk load", g.key_cnt, NULL);

		key_gen(keybuf, &key.size, (uint64_t)g.key_cnt, 0);
		key.data = keybuf;
		value_gen(valbuf, &value.size, (uint64_t)g.key_cnt);
		value.data = valbuf;

		switch (g.type) {
		case FIX:
			if (!is_bulk)
				cursor->set_key(cursor, g.key_cnt);
			cursor->set_value(cursor, *(uint8_t *)value.data);
			if (g.logging == LOG_OPS)
				(void)g.wt_api->msg_printf(g.wt_api, session,
				    "%-10s %" PRIu32 " {0x%02" PRIx8 "}",
				    "bulk V",
				    g.key_cnt, ((uint8_t *)value.data)[0]);
			break;
		case VAR:
			if (!is_bulk)
				cursor->set_key(cursor, g.key_cnt);
			cursor->set_value(cursor, &value);
			if (g.logging == LOG_OPS)
				(void)g.wt_api->msg_printf(g.wt_api, session,
				    "%-10s %" PRIu32 " {%.*s}", "bulk V",
				    g.key_cnt,
				    (int)value.size, (char *)value.data);
			break;
		case ROW:
			cursor->set_key(cursor, &key);
			if (g.logging == LOG_OPS)
				(void)g.wt_api->msg_printf(g.wt_api, session,
				    "%-10s %" PRIu32 " {%.*s}", "bulk K",
				    g.key_cnt, (int)key.size, (char *)key.data);
			cursor->set_value(cursor, &value);
			if (g.logging == LOG_OPS)
				(void)g.wt_api->msg_printf(g.wt_api, session,
				    "%-10s %" PRIu32 " {%.*s}", "bulk V",
				    g.key_cnt,
				    (int)value.size, (char *)value.data);
			break;
		}

		if ((ret = cursor->insert(cursor)) != 0)
			die(ret, "cursor.insert");

		if (!SINGLETHREADED)
			continue;

		/* Insert the item into BDB. */
		bdb_insert(key.data, key.size, value.data, value.size);
	}

	if ((ret = cursor->close(cursor)) != 0)
		die(ret, "cursor.close");

	if (g.logging != 0)
		(void)g.wt_api->msg_printf(g.wt_api, session,
		    "=============== bulk load stop ===============");

	if ((ret = session->close(session, NULL)) != 0)
		die(ret, "session.close");

	free(keybuf);
	free(valbuf);
}
Exemple #23
0
/*
 * read_row --
 *	Read and verify a single element in a row- or column-store file.
 */
static void
read_row(WT_CURSOR *cursor, WT_ITEM *key, uint64_t keyno)
{
	WT_ITEM bdb_value, value;
	WT_SESSION *session;
	int notfound, ret;
	uint8_t bitfield;

	session = cursor->session;

	/* Log the operation */
	if (g.logging == LOG_OPS)
		(void)session->msg_printf(
		    session, "%-10s%" PRIu64, "read", keyno);

	/* Retrieve the key/value pair by key. */
	switch (g.c_file_type) {
	case FIX:
	case VAR:
		cursor->set_key(cursor, keyno);
		break;
	case ROW:
		key_gen((uint8_t *)key->data, &key->size, keyno, 0);
		cursor->set_key(cursor, key);
		break;
	}

	if ((ret = cursor->search(cursor)) == 0) {
		if (g.c_file_type == FIX) {
			ret = cursor->get_value(cursor, &bitfield);
			value.data = &bitfield;
			value.size = 1;
		} else {
			memset(&value, 0, sizeof(value));
			ret = cursor->get_value(cursor, &value);
		}
	}
	if (ret != 0 && ret != WT_NOTFOUND)
		die(ret, "read_row: read row %" PRIu64, keyno);

	if (!SINGLETHREADED)
		return;

	/* Retrieve the BDB value. */
	memset(&bdb_value, 0, sizeof(bdb_value));
	bdb_read(keyno, &bdb_value.data, &bdb_value.size, &notfound);

	/*
	 * Check for not-found status.
	 *
	 * In fixed length stores, zero values at the end of the key space
	 * are treated as not found.  Treat this the same as a zero value
	 * in the key space, to match BDB's behavior.
	 */
	if (g.c_file_type == FIX && ret == WT_NOTFOUND) {
		bitfield = 0;
		ret = 0;
	}

	if (notfound_chk("read_row", ret, notfound, keyno))
		return;

	/* Compare the two. */
	if (value.size != bdb_value.size ||
	    memcmp(value.data, bdb_value.data, value.size) != 0) {
		fprintf(stderr,
		    "read_row: read row value mismatch %" PRIu64 ":\n", keyno);
		print_item("bdb", &bdb_value);
		print_item(" wt", &value);
		die(0, NULL);
	}
}