Exemplo n.º 1
0
static int add_data_to_store(struct cntr *cntr,
	struct slist *slist, struct iobuf *rbuf, struct dpth *dpth)
{
	static struct blk *blk=NULL;

	// Find the first one in the list that was requested.
	// FIX THIS: Going up the list here, and then later
	// when writing to the manifest is not efficient.
	for(blk=slist->blist->head;
		blk && (!blk->requested || blk->got==BLK_GOT); blk=blk->next)
	{
	//	logp("try: %d %d\n", blk->index, blk->got);
	}
	if(!blk)
	{
		logp("Received data but could not find next requested block.\n");
		if(!slist->blist->head)
			logp("and slist->blist->head is null\n");
		else
			logp("head index: %" PRIu64 "\n", slist->blist->head->index);
		return -1;
	}

// FIX THIS
#ifndef UTEST
	if(blk_verify(blk->fingerprint, blk->md5sum, rbuf->buf, rbuf->len)<=0)
	{
		logp("ERROR: Block %" PRIu64 " from client did not verify.\n",
			blk->index);
		return -1;
	}
#endif

	// Add it to the data store straight away.
	if(dpth_protocol2_fwrite(dpth, rbuf, blk)) return -1;

	cntr_add(cntr, CMD_DATA, 0);

	blk->got=BLK_GOT;
	blk=blk->next;

	return 0;
}
Exemplo n.º 2
0
static int send_data(struct asfd *asfd, struct blk *blk,
	enum action act, struct sbuf *need_data, struct cntr *cntr)
{
	struct iobuf wbuf;

	switch(act)
	{
		case ACTION_RESTORE:
			iobuf_set(&wbuf, CMD_DATA, blk->data, blk->length);
			if(asfd->write(asfd, &wbuf)) return -1;
			return 0;
		case ACTION_VERIFY:
			// Need to check that the block has the correct
			// checksums.
			switch(blk_verify(blk))
			{
				case 1:
					iobuf_set(&wbuf, CMD_DATA, (char *)"0", 1);
					if(asfd->write(asfd, &wbuf)) return -1;
					cntr_add(cntr, CMD_DATA, 0);
					break; // All OK.
				case 0:
				{
					char msg[256];
					snprintf(msg, sizeof(msg), "Checksum mismatch in block for %c:%s:%s\n", need_data->path.cmd, need_data->path.buf, uint64_to_savepathstr_with_sig(blk->savepath));
					logw(asfd, cntr, msg);
					break;
		
				}
				default:
				{
					char msg[256];
					snprintf(msg, sizeof(msg), "Error when attempting  to verify block for %c:%s:%s\n", need_data->path.cmd, need_data->path.buf, uint64_to_savepathstr_with_sig(blk->savepath));
					return -1;
				}
			}
			return 0;
		default:
			logp("unknown action in %s: %d\n", __func__, act);
			return -1;
	}
}