int ZeroState::Find(const Sha1Hash &root_hash) { //fprintf(stderr,"swift: zero: Got request for %s\n",root_hash.hex().c_str() ); //std::string file_name = "content.avi"; std::string file_name = contentdir_+FILE_SEP+root_hash.hex(); uint32_t chunk_size=SWIFT_DEFAULT_CHUNK_SIZE; dprintf("%s #0 zero find %s from %s\n",tintstr(),file_name.c_str(), getcwd_utf8().c_str() ); std::string reqfilename = file_name; int ret = file_exists_utf8(reqfilename); if (ret < 0 || ret == 0 || ret == 2) return -1; reqfilename = file_name+".mbinmap"; ret = file_exists_utf8(reqfilename); if (ret < 0 || ret == 0 || ret == 2) return -1; reqfilename = file_name+".mhash"; ret = file_exists_utf8(reqfilename); if (ret < 0 || ret == 0 || ret == 2) return -1; // Open as ZeroState SwarmID swarmid(root_hash); return swift::Open(file_name, swarmid, "", false, POPT_CONT_INT_PROT_MERKLE, true); }
void CmdGwSendINFOHashChecking(cmd_gw_t* req, Sha1Hash root_hash) { // Send INFO DLSTATUS_HASHCHECKING message. char cmd[MAX_CMD_MESSAGE]; sprintf(cmd,"INFO %s %d %lli/%lli %lf %lf %u %u\r\n",root_hash.hex().c_str(),DLSTATUS_HASHCHECKING,(uint64_t)0,(uint64_t)0,0.0,0.0,0,0); //fprintf(stderr,"cmd: SendINFO: %s", cmd); send(req->cmdsock,cmd,strlen(cmd),0); }
void CmdGwGotMAXSPEED(Sha1Hash &want_hash, data_direction_t ddir, double speed) { // Set maximum speed on the specified download fprintf(stderr,"cmd: GotMAXSPEED: %s %d %lf\n",want_hash.hex().c_str(),ddir,speed); cmd_gw_t* req = CmdGwFindRequestByRootHash(want_hash); if (req == NULL) return; FileTransfer *ft = FileTransfer::file(req->transfer); ft->SetMaxSpeed(ddir,speed); }
FileTransfer::FileTransfer(int td, std::string filename, const Sha1Hash& root_hash, bool force_check_diskvshash, popt_cont_int_prot_t cipm, uint32_t chunk_size, bool zerostate) : ContentTransfer(FILE_TRANSFER), availability_(NULL), zerostate_(zerostate) { td_ = td; Handshake hs; hs.cont_int_prot_ = cipm; SetDefaultHandshake(hs); std::string destdir; int ret = file_exists_utf8(filename); if (ret == 2 && root_hash != Sha1Hash::ZERO) { // Filename is a directory, download root_hash there destdir = filename; filename = destdir+FILE_SEP+root_hash.hex(); } else { destdir = dirname_utf8(filename); if (destdir == "") destdir = "."; } // MULTIFILE storage_ = new Storage(filename,destdir,td_,0); std::string hash_filename; hash_filename.assign(filename); hash_filename.append(".mhash"); std::string binmap_filename; binmap_filename.assign(filename); binmap_filename.append(".mbinmap"); // Arno, 2013-02-25: Create HashTree even when PROT_NONE to enable // automatic size determination via peak hashes. if (!zerostate_) { hashtree_ = (HashTree *)new MmapHashTree(storage_,root_hash,chunk_size,hash_filename,force_check_diskvshash,binmap_filename); availability_ = new Availability(SWIFT_MAX_OUTGOING_CONNECTIONS); if (ENABLE_VOD_PIECEPICKER) picker_ = new VodPiecePicker(this); else picker_ = new RFPiecePicker(this); picker_->Randomize(rand()&63); } else { // ZEROHASH hashtree_ = (HashTree *)new ZeroHashTree(storage_,root_hash,chunk_size,hash_filename,binmap_filename); } UpdateOperational(); }
void CmdGwGotREMOVE(Sha1Hash &want_hash, bool removestate, bool removecontent) { // Remove the specified download fprintf(stderr,"cmd: GotREMOVE: %s %d %d\n",want_hash.hex().c_str(),removestate,removecontent); cmd_gw_t* req = CmdGwFindRequestByRootHash(want_hash); if (req == NULL) return; FileTransfer *ft = FileTransfer::file(req->transfer); fprintf(stderr, "%s @%i remove transfer %i\n",tintstr(),req->id,req->transfer); dprintf("%s @%i remove transfer %i\n",tintstr(),req->id,req->transfer); swift::Close(req->transfer); // Delete content + .mhash from filesystem, if desired if (removecontent) remove(req->contentfilename); if (removestate) { char *mhashfilename = (char *)malloc(strlen(req->contentfilename)+strlen(".mhash")+1); strcpy(mhashfilename,req->contentfilename); strcat(mhashfilename,".mhash"); remove(mhashfilename); free(mhashfilename); // Arno, 2012-01-10: .mbinmap gots to go too. char *mbinmapfilename = (char *)malloc(strlen(req->contentfilename)+strlen(".mbinmap")+1); strcpy(mbinmapfilename,req->contentfilename); strcat(mbinmapfilename,".mbinmap"); remove(mbinmapfilename); free(mbinmapfilename); } CmdGwFreeRequest(req); *req = cmd_requests[--cmd_gw_reqs_open]; }
void CmdGwGotCHECKPOINT(Sha1Hash &want_hash) { // Checkpoint the specified download fprintf(stderr,"cmd: GotCHECKPOINT: %s\n",want_hash.hex().c_str()); cmd_gw_t* req = CmdGwFindRequestByRootHash(want_hash); if (req == NULL) return; FileTransfer *ft = FileTransfer::file(req->transfer); std::string binmap_filename = ft->file().filename(); binmap_filename.append(".mbinmap"); fprintf(stderr,"cmdgw: GotCHECKPOINT: checkpointing to %s\n", binmap_filename.c_str() ); FILE *fp = fopen(binmap_filename.c_str(),"wb"); if (!fp) { print_error("cannot open mbinmap for writing"); return; } if (ft->file().serialize(fp) < 0) print_error("writing to mbinmap"); fclose(fp); }