static void setup_writes_from_slist_blk_requests(struct asfd *asfd, int *aw, struct slist *slist, int number_of_blks, uint64_t interrupt) { struct sbuf *s; struct iobuf iobuf; char req[32]=""; int blk_index=1; uint64_t file_no=1; if(!slist) return; for(s=slist->head; s; s=s->next) { if(sbuf_is_filedata(s) && !sbuf_is_encrypted(s)) // Not working for proto2 yet. { int b; if(interrupt==file_no++) continue; for(b=0; b<number_of_blks; b++) { base64_from_uint64(blk_index++, req); iobuf_from_str(&iobuf, CMD_DATA_REQ, req); asfd_assert_write_iobuf(asfd, aw, 0, &iobuf); } } } }
static int get_wbuf_from_sigs(struct iobuf *wbuf, struct slist *slist, uint8_t *end_flags) { static char req[32]=""; struct sbuf *sb=slist->blks_to_request; while(sb && !(sb->flags & SBUF_NEED_DATA)) sb=sb->next; if(!sb) { slist->blks_to_request=NULL; if((*end_flags)&END_SIGS && !((*end_flags)&END_BLK_REQUESTS)) { iobuf_from_str(wbuf, CMD_GEN, (char *)"blk_requests_end"); (*end_flags)|=END_BLK_REQUESTS; } return 0; } if(!sb->protocol2->bsighead) { // Trying to move onto the next file. // ??? Does this really work? if(sb->protocol2->bend) { slist->blks_to_request=sb->next; printf("move to next\n"); } if((*end_flags)&END_SIGS && !((*end_flags)&END_BLK_REQUESTS)) { iobuf_from_str(wbuf, CMD_GEN, (char *)"blk_requests_end"); (*end_flags)|=END_BLK_REQUESTS; } return 0; } if(sb->protocol2->bsighead->got==BLK_INCOMING) return 0; if(sb->protocol2->bsighead->got==BLK_NOT_GOT) { base64_from_uint64(sb->protocol2->bsighead->index, req); iobuf_from_str(wbuf, CMD_DATA_REQ, req); sb->protocol2->bsighead->requested=1; } // Move on. if(sb->protocol2->bsighead==sb->protocol2->bend) { slist->blks_to_request=sb->next; sb->protocol2->bsighead=sb->protocol2->bstart; } else { sb->protocol2->bsighead=sb->protocol2->bsighead->next; } return 0; }
static int add_to_blks_list(struct asfd *asfd, struct conf **confs, struct slist *slist) { int just_opened=0; struct sbuf *sb=slist->last_requested; if(!sb) return 0; if(sb->protocol2->bfd.mode==BF_CLOSED) { char buf[32]; struct cntr *cntr=NULL; if(confs) cntr=get_cntr(confs); switch(rabin_open_file(sb, asfd, cntr, confs)) { case 1: // All OK. break; case 0: // Could not open file. Tell the server. base64_from_uint64(sb->protocol2->index, buf); if(asfd->write_str(asfd, CMD_INTERRUPT, buf)) return -1; if(slist_del_sbuf(slist, sb)) return -1; sbuf_free(&sb); return 0; default: return -1; } just_opened=1; } switch(blks_generate(sb, slist->blist, just_opened)) { case 0: // All OK. break; case 1: // File ended. if(rabin_close_file(sb, asfd)) { logp("Failed to close file %s\n", iobuf_to_printable(&sb->path)); return -1; } slist->last_requested=sb->next; break; default: return -1; } return 0; }
static void setup_reads_from_slist(struct asfd *asfd, int *ar, struct slist *slist, int number_of_blks, uint64_t interrupt) { int file_no=1; struct sbuf *s; struct blk blk; struct iobuf iobuf; if(!slist) return; for(s=slist->head; s; s=s->next) { if(sbuf_is_filedata(s) && !sbuf_is_encrypted(s)) // Not working for proto2 yet. { int b; s->protocol2->index=file_no++; if(interrupt==s->protocol2->index) { char buf[32]=""; asfd_mock_read(asfd, ar, 0, CMD_WARNING, "path vanished\n"); base64_from_uint64(interrupt, buf); asfd_mock_read(asfd, ar, 0, CMD_INTERRUPT, buf); continue; } iobuf_free_content(&s->attr); attribs_encode(s); asfd_mock_read(asfd, ar, 0, CMD_ATTRIBS_SIGS, s->attr.buf); blk.fingerprint=file_no; memset(&blk.md5sum, file_no, MD5_DIGEST_LENGTH); blk_to_iobuf_sig(&blk, &iobuf); for(b=0; b<number_of_blks; b++) asfd_mock_read_iobuf(asfd, ar, 0, &iobuf); } } }