static void add_blk(struct blist *blist) { struct blk *blk; fail_unless((blk=blk_alloc())!=NULL); blk->fingerprint=prng_next64(); prng_md5sum(blk->md5sum); blk->savepath=prng_next64(); blist_add_blk(blist, blk); }
static void add_blk_and_data_files(struct blist *blist, uint64_t save_path) { struct blk *blk; fail_unless((blk=blk_alloc())!=NULL); blk->fingerprint=prng_next64(); prng_md5sum(blk->md5sum); blk->savepath=save_path; blist_add_blk(blist, blk); }
static int blk_read_to_list(struct sbuf *sb, struct blist *blist) { if(!blk_read()) return 0; // Got something. if(first) { sb->protocol2->bstart=blk; first=0; } if(!sb->protocol2->bsighead) { sb->protocol2->bsighead=blk; } blist_add_blk(blist, blk); blk=NULL; return 1; }
static #endif int champ_server_deal_with_rbuf_sig(struct asfd *asfd, const char *directory, struct scores *scores) { struct blk *blk; if(!(blk=blk_alloc())) return -1; blist_add_blk(asfd->blist, blk); if(!asfd->blist->blk_to_dedup) asfd->blist->blk_to_dedup=blk; if(blk_set_from_iobuf_sig(blk, asfd->rbuf)) return -1; //logp("Got fingerprint from %d: %lu - %lu\n", // asfd->fd, blk->index, blk->fingerprint); return deduplicate_maybe(asfd, blk, directory, scores); }
static int add_to_sig_list(struct slist *slist, struct iobuf *rbuf) { // Goes on slist->add_sigs_here struct blk *blk; struct protocol2 *protocol2; if(!(blk=blk_alloc())) return -1; blist_add_blk(slist->blist, blk); protocol2=slist->add_sigs_here->protocol2; if(!protocol2->bstart) protocol2->bstart=blk; if(!protocol2->bsighead) protocol2->bsighead=blk; if(blk_set_from_iobuf_sig(blk, rbuf)) return -1; // Need to send sigs to champ chooser, therefore need to point // to the oldest unsent one if nothing is pointed to yet. if(!slist->blist->blk_for_champ_chooser) slist->blist->blk_for_champ_chooser=blk; return 0; }
static int add_to_sig_list(struct slist *slist, struct blist *blist, struct iobuf *rbuf, struct dpth *dpth, struct conf *conf) { // Goes on slist->add_sigs_here struct blk *blk; struct burp2 *burp2; if(!(blk=blk_alloc())) return -1; blist_add_blk(blist, blk); burp2=slist->add_sigs_here->burp2; if(!burp2->bstart) burp2->bstart=blk; if(!burp2->bsighead) burp2->bsighead=blk; if(split_sig(rbuf->buf, rbuf->len, &blk->fingerprint, blk->md5sum)) return -1; // Need to send sigs to champ chooser, therefore need to point // to the oldest unsent one if nothing is pointed to yet. if(!blist->blk_for_champ_chooser) blist->blk_for_champ_chooser=blk; return 0; }
// The client uses this. // Return 0 for OK. 1 for OK, and file ended, -1 for error. int blks_generate(struct asfd *asfd, struct conf **confs, struct sbuf *sb, struct blist *blist, int just_opened) { static ssize_t bytes; first=just_opened; if(!blk && !(blk=blk_alloc_with_data(rconf.blk_max))) return -1; if(gcp<gbuf_end) { // Could have got a fill before buf ran out - // need to resume from the same place in that case. if(blk_read_to_list(sb, blist)) return 0; // Got a block. // Did not get a block. Carry on and read more. } while((bytes=rabin_read(sb, gbuf, rconf.blk_max))) { gcp=gbuf; gbuf_end=gbuf+bytes; sb->protocol2->bytes_read+=bytes; if(blk_read_to_list(sb, blist)) return 0; // Got a block // Did not get a block. Maybe should try again? // If there are async timeouts, look at this! return 0; } // Getting here means there is no more to read from the file. // Make sure to deal with anything left over. if(!sb->protocol2->bytes_read) { // Empty file, set up an empty block so that the server // can skip over it. if(!(sb->protocol2->bstart=blk_alloc())) return -1; sb->protocol2->bsighead=blk; blist_add_blk(blist, blk); blk=NULL; } else if(blk) { if(blk->length) { if(first) { sb->protocol2->bstart=blk; first=0; } if(!sb->protocol2->bsighead) { sb->protocol2->bsighead=blk; } blist_add_blk(blist, blk); } else blk_free(&blk); blk=NULL; } if(blist->tail) sb->protocol2->bend=blist->tail; return 1; }