1 /*****************************************************************************\
3 * Name : file_transfer_tentacle *
4 * Author : Chris Koeritz *
6 *******************************************************************************
7 * Copyright (c) 2005-$now By Author. This program is free software; you can *
8 * redistribute it and/or modify it under the terms of the GNU General Public *
9 * License as published by the Free Software Foundation; either version 2 of *
10 * the License or (at your option) any later version. This is online at: *
11 * http://www.fsf.org/copyleft/gpl.html *
12 * Please send any updates to: fred@gruntose.com *
13 \*****************************************************************************/
15 #include "file_transfer_tentacle.h"
17 #include <basis/mutex.h>
18 #include <filesystem/directory_tree.h>
19 #include <filesystem/filename.h>
20 #include <filesystem/filename_list.h>
21 #include <filesystem/heavy_file_ops.h>
22 #include <loggers/program_wide_logger.h>
23 #include <octopus/entity_defs.h>
24 #include <octopus/entity_data_bin.h>
25 #include <octopus/unhandled_request.h>
26 #include <processes/ethread.h>
27 #include <textual/parser_bits.h>
29 using namespace basis;
30 using namespace filesystem;
31 using namespace loggers;
32 using namespace octopi;
33 using namespace processes;
34 using namespace structures;
35 using namespace textual;
36 using namespace timely;
41 #define AUTO_LOCK auto_synchronizer loc(*_lock);
42 // protects our lists.
44 const int FTT_CLEANING_INTERVAL = 30 * SECOND_ms;
45 // this is how frequently we clean up the list to remove outdated transfers.
47 const int TRANSFER_TIMEOUT = 10 * MINUTE_ms;
48 // if it hasn't been touched in this long, it's out of there.
50 #define DEBUG_FILE_TRANSFER_TENTACLE
51 // uncomment for noisier version.
54 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s)
58 class file_transfer_record
61 // valid for both transfers and correspondences.
62 astring _src_root; // where the info is on the data provider.
63 time_stamp _last_active; // when this was last used.
65 // valid for file transfers only.
66 octopus_entity _ent; // the entity requesting this service.
67 astring _dest_root; // where the info is on the data sink.
68 filename_list *_diffs; // the differences to be transferred.
69 file_transfer_header _last_sent; // the last chunk that was sent.
70 bool _done; // true if the transfer is finished.
71 string_array _includes; // the set to include.
73 // valid for correspondence records only.
74 directory_tree *_local_dir; // our local information about the transfer.
75 astring _source_mapping; // valid for a correspondence record.
76 int _refresh_interval; // the rate of refreshing the source tree.
78 file_transfer_record() : _diffs(NIL), _last_sent(file_time()),
79 _done(false), _local_dir(NIL)
82 ~file_transfer_record() {
87 astring text_form() const {
89 to_return += astring("src=") + _src_root + astring(" last act=")
90 + _last_active.text_form();
91 if (_ent.blank()) to_return += astring(" ent=") + _ent.text_form();
93 to_return += astring(" dest=") + _dest_root;
94 to_return += astring(" last_sent=") + _last_sent.text_form();
102 // this implementation assumes that the same entity will never simultaneously
103 // transfer the same source to the same destination. that assumption holds
104 // up fine for different clients, since they should have different entities.
105 // when there is a collision on the entity/src/dest, then the default action
106 // is to assume that the transfer is just being started over.
108 class file_transfer_status : public amorph<file_transfer_record>
111 // find a transfer record by the key fields.
112 file_transfer_record *find(const octopus_entity &ent, const astring &src,
113 const astring &dest) {
114 for (int i = 0; i < elements(); i++) {
115 const file_transfer_record *rec = get(i);
116 if (rec && (rec->_ent == ent) && (rec->_src_root == src)
117 && (rec->_dest_root == dest) ) {
124 virtual ~file_transfer_status() {}
126 DEFINE_CLASS_NAME("file_transfer_status");
128 // find a file correspondence record by the mapping name.
129 file_transfer_record *find_mapping(const astring &source_mapping) {
130 for (int i = 0; i < elements(); i++) {
131 const file_transfer_record *rec = get(i);
132 if (rec && (rec->_source_mapping == source_mapping) )
138 // turns a source mapping into the location that it corresponds to.
139 astring translate(const astring &source_path) const {
140 FUNCDEF("translate");
143 filename(source_path).separate(rooted, pieces);
144 astring source_mapping = pieces[0];
145 pieces.zap(0, 0); // remove source part.
147 for (int i = 0; i < elements(); i++) {
148 const file_transfer_record *rec = get(i);
149 if (rec && (rec->_source_mapping == source_mapping) ) {
150 return rec->_src_root;
153 return astring::empty_string();
156 // removes a file transfer record by the key fields.
157 bool whack(const octopus_entity &ent, const astring &src,
158 const astring &dest) {
159 for (int i = 0; i < elements(); i++) {
160 const file_transfer_record *rec = get(i);
161 if (rec && (rec->_ent == ent) && (rec->_src_root == src)
162 && (rec->_dest_root == dest) ) {
170 // clean all records for the entity "ent".
171 void whack_all(const octopus_entity &ent) {
172 for (int i = elements() - 1; i >= 0; i--) {
173 const file_transfer_record *rec = get(i);
174 if (rec && (rec->_ent == ent) )
179 // removes a file transfer correspondence.
180 bool whack_mapping(const astring &source_mapping) {
181 for (int i = elements() - 1; i >= 0; i--) {
182 const file_transfer_record *rec = get(i);
183 if (rec && (rec->_source_mapping == source_mapping) ) {
191 // returns a string dump of the fields in this list.
192 astring text_form() const {
194 for (int i = 0; i < elements(); i++) {
195 const file_transfer_record *rec = get(i);
197 to_return += rec->text_form() + parser_bits::platform_eol_to_chars();
205 class file_transfer_cleaner : public ethread
208 file_transfer_cleaner(file_transfer_tentacle &parent)
209 : ethread(FTT_CLEANING_INTERVAL, SLACK_INTERVAL), _parent(parent) {}
211 virtual void perform_activity(void *formal(ptr)) { _parent.periodic_actions(); }
214 file_transfer_tentacle &_parent;
219 file_transfer_tentacle::file_transfer_tentacle(int maximum_transfer,
220 file_transfer_tentacle::transfer_modes mode_of_transfer)
221 : tentacle_helper<file_transfer_infoton>
222 (file_transfer_infoton::file_transfer_classifier(), false),
223 _maximum_transfer(maximum_transfer),
224 _transfers(new file_transfer_status),
225 _correspondences(new file_transfer_status),
227 _cleaner(new file_transfer_cleaner(*this)),
228 _mode(mode_of_transfer)
230 _cleaner->start(NIL);
233 file_transfer_tentacle::~file_transfer_tentacle()
237 WHACK(_correspondences);
242 astring file_transfer_tentacle::text_form() const
245 return _transfers->text_form();
248 void file_transfer_tentacle::expunge(const octopus_entity &to_remove)
251 _transfers->whack_all(to_remove);
254 outcome file_transfer_tentacle::add_correspondence
255 (const astring &source_mapping, const astring &source_root,
256 int refresh_interval)
258 FUNCDEF("add_correspondence");
261 remove_correspondence(source_mapping); // clean the old one out first.
263 // create new file transfer record to hold this correspondence.
264 file_transfer_record *new_record = new file_transfer_record;
265 new_record->_source_mapping = source_mapping;
266 new_record->_src_root = source_root;
267 new_record->_refresh_interval = refresh_interval;
268 new_record->_local_dir = new directory_tree(source_root);
269 //hmmm: doesn't say anything about a pattern. do we need to worry about that?
271 // check that the directory looked healthy.
272 if (!new_record->_local_dir->good()) {
274 return common::ACCESS_DENIED;
276 #ifdef DEBUG_FILE_TRANSFER_TENTACLE
277 LOG(astring("adding tree for: ent=") + new_record->_ent.text_form()
278 + " src=" + new_record->_src_root);
280 // calculate size and checksum info for the directory.
281 new_record->_local_dir->calculate( !(_mode & COMPARE_CONTENT_SAMPLE) );
283 #ifdef DEBUG_FILE_TRANSFER_TENTACLE
284 LOG(astring("done adding tree for: ent=") + new_record->_ent.text_form()
285 + " src=" + new_record->_src_root);
288 _correspondences->append(new_record);
293 outcome file_transfer_tentacle::remove_correspondence
294 (const astring &source_mapping)
297 if (!_correspondences->whack_mapping(source_mapping))
302 bool file_transfer_tentacle::get_differences(const octopus_entity &ent,
303 const astring &src, const astring &dest, filename_list &diffs)
305 FUNCDEF("get_differences");
308 file_transfer_record *the_rec = _transfers->find(ent, src, dest);
309 if (!the_rec) return false;
310 if (!the_rec->_diffs) return false; // no diffs listed.
311 diffs = *the_rec->_diffs;
315 bool file_transfer_tentacle::status(const octopus_entity &ent,
316 const astring &src, const astring &dest, double &total_size,
317 int &total_files, double ¤t_size, int ¤t_files, bool &done,
318 time_stamp &last_active)
326 file_transfer_record *the_rec = _transfers->find(ent, src, dest);
327 if (!the_rec) return false;
328 done = the_rec->_done;
329 last_active = the_rec->_last_active;
331 if (the_rec->_diffs) {
332 the_rec->_diffs->calculate_progress(the_rec->_last_sent._filename,
333 the_rec->_last_sent._byte_start + the_rec->_last_sent._length,
334 current_files, current_size);
335 total_files = the_rec->_diffs->total_files();
336 total_size = the_rec->_diffs->total_size();
342 outcome file_transfer_tentacle::register_file_transfer
343 (const octopus_entity &ent, const astring &src_root,
344 const astring &dest_root, const string_array &includes)
346 FUNCDEF("register_file_transfer");
348 // make sure that this isn't an existing transfer. if so, we just update
350 file_transfer_record *the_rec = _transfers->find(ent, src_root, dest_root);
352 the_rec = new file_transfer_record;
353 the_rec->_src_root = src_root;
354 the_rec->_dest_root = dest_root;
356 the_rec->_includes = includes;
357 _transfers->append(the_rec); // add the new record.
359 the_rec->_done = false;
360 the_rec->_includes = includes;
361 the_rec->_last_active.reset(); // freshen up the last activity time.
366 outcome file_transfer_tentacle::cancel_file_transfer(const octopus_entity &ent,
367 const astring &src_root, const astring &dest_root)
370 return _transfers->whack(ent, src_root, dest_root)? OKAY : NOT_FOUND;
373 directory_tree *file_transfer_tentacle::lock_directory(const astring &key)
376 file_transfer_record *the_rec = _correspondences->find_mapping(key);
377 if (!the_rec || !the_rec->_local_dir) {
379 return NIL; // unknown transfer.
381 return the_rec->_local_dir;
384 void file_transfer_tentacle::unlock_directory()
389 bool file_transfer_tentacle::add_path(const astring &key,
390 const astring &new_path)
393 file_transfer_record *the_rec = _correspondences->find_mapping(key);
394 if (!the_rec) return false; // unknown transfer.
395 if (!the_rec->_local_dir) return false; // not right type.
396 return the_rec->_local_dir->add_path(new_path) == common::OKAY;
399 bool file_transfer_tentacle::remove_path(const astring &key,
400 const astring &old_path)
403 file_transfer_record *the_rec = _correspondences->find_mapping(key);
404 if (!the_rec) return false; // unknown transfer.
405 if (!the_rec->_local_dir) return false; // not right type.
406 return the_rec->_local_dir->remove_path(old_path) == common::OKAY;
409 void file_transfer_tentacle::periodic_actions()
411 FUNCDEF("periodic_actions");
414 // first, we'll clean out old transfers.
415 time_stamp oldest_allowed(-TRANSFER_TIMEOUT);
416 // nothing older than this should be kept.
417 for (int i = _transfers->elements() - 1; i >= 0; i--) {
418 const file_transfer_record *curr = _transfers->get(i);
419 if (curr->_last_active < oldest_allowed) {
420 #ifdef DEBUG_FILE_TRANSFER_TENTACLE
421 LOG(astring("cleaning record for: ent=") + curr->_ent.text_form()
422 + " src=" + curr->_src_root + " dest=" + curr->_dest_root);
424 _transfers->zap(i, i);
428 // then we'll rescan any trees that are ready for it.
429 for (int i = 0; i < _correspondences->elements(); i++) {
430 file_transfer_record *curr = _correspondences->borrow(i);
431 if (curr->_last_active < time_stamp(-curr->_refresh_interval)) {
432 if (curr->_local_dir) {
433 #ifdef DEBUG_FILE_TRANSFER_TENTACLE
434 LOG(astring("refreshing tree for: ent=") + curr->_ent.text_form()
435 + " src=" + curr->_src_root + " dest=" + curr->_dest_root);
437 WHACK(curr->_local_dir);
438 curr->_local_dir = new directory_tree(curr->_src_root);
439 curr->_local_dir->calculate( !(_mode & COMPARE_CONTENT_SAMPLE) );
440 #ifdef DEBUG_FILE_TRANSFER_TENTACLE
441 LOG(astring("done refreshing tree for: ent=") + curr->_ent.text_form()
442 + " src=" + curr->_src_root + " dest=" + curr->_dest_root);
445 curr->_last_active.reset(); // reset our action time.
450 outcome file_transfer_tentacle::reconstitute(const string_array &classifier,
451 byte_array &packed_form, infoton * &reformed)
453 // this method doesn't use the lists, so it doesn't need locking.
454 if (classifier != file_transfer_infoton::file_transfer_classifier())
456 return reconstituter(classifier, packed_form, reformed,
457 (file_transfer_infoton *)NIL);
460 // the "handle_" and "conclude_" methods are thread-safe because the mutex is locked before
461 // their invocations.
463 outcome file_transfer_tentacle::handle_tree_compare_request
464 (file_transfer_infoton &req, const octopus_request_id &item_id)
466 FUNCDEF("handle_tree_compare_request");
468 // get the mapping from the specified location on this side.
469 filename splitting(req._src_root);
472 splitting.separate(rooted, pieces);
473 astring source_mapping = pieces[0];
475 // patch the name up to find the sub_path for the source.
476 filename source_start;
478 source_start.join(rooted, pieces);
480 // locate the allowed transfer depot for the mapping they provided.
481 file_transfer_record *mapping_record
482 = _correspondences->find_mapping(source_mapping);
483 if (!mapping_record) {
484 LOG(astring("could not find source mapping of ") + source_mapping);
488 // unpack the tree that they sent us which describes their local area.
489 directory_tree *dest_tree = new directory_tree;
490 if (!dest_tree->unpack(req._packed_data)) {
491 LOG(astring("could not unpack requester's directory tree"));
496 string_array requested_names;
497 if (!requested_names.unpack(req._packed_data)) {
498 LOG(astring("could not unpack requester's filename includes"));
503 // look up to see if this is about something that has already been seen.
504 // we don't want to add a new transfer record if they're already working on
505 // this. that also lets them do a new tree compare to restart the transfer.
506 file_transfer_record *the_rec = _transfers->find(item_id._entity,
507 req._src_root, req._dest_root);
509 // there was no existing record; we'll create a new one.
510 the_rec = new file_transfer_record;
511 the_rec->_ent = item_id._entity;
512 the_rec->_src_root = req._src_root;
513 the_rec->_dest_root = req._dest_root;
514 _transfers->append(the_rec);
516 // record some activity on this record.
517 the_rec->_done = false;
518 the_rec->_last_active.reset();
521 the_rec->_diffs = new filename_list;
523 int how_comp = file_info::EQUAL_NAME; // the prize for doing nothing.
524 if (_mode & COMPARE_SIZE_AND_TIME)
525 how_comp |= file_info::EQUAL_FILESIZE | file_info::EQUAL_TIMESTAMP;
526 if (_mode & COMPARE_CONTENT_SAMPLE)
527 how_comp |= file_info::EQUAL_CHECKSUM;
529 // compare the two trees of files.
530 directory_tree::compare_trees(*mapping_record->_local_dir,
531 source_start.raw(), *dest_tree, astring::empty_string(),
532 *the_rec->_diffs, (file_info::file_similarity)how_comp);
534 //LOG(astring("filenames decided as different:\n") + the_rec->_diffs->text_form());
536 // now prune the diffs to accord with what they claim they want.
537 if (requested_names.length()) {
538 for (int i = the_rec->_diffs->elements() - 1; i >= 0; i--) {
539 filename diff_curr = *the_rec->_diffs->get(i);
541 for (int j = 0; j < requested_names.length(); j++) {
542 filename req_curr(requested_names[j]);
543 if (req_curr.compare_suffix(diff_curr)) {
545 //LOG(astring("will use: ") + req_curr);
549 if (!found) the_rec->_diffs->zap(i, i);
553 req._packed_data.reset(); // clear out existing stuff before cloning.
554 file_transfer_infoton *reply = dynamic_cast<file_transfer_infoton *>(req.clone());
555 the_rec->_diffs->pack(reply->_packed_data);
557 //hmmm: does the other side really need the list of filenames? i guess we
558 // could check validity of what's transferred or check space available
559 // before the client starts the transfer.
561 reply->_request = false; // it's a response now.
562 LOG("storing product from transfer processing");
563 store_product(reply, item_id);
564 // send back the comparison list.
566 LOG("now showing bin before return:");
567 LOG(get_storage()->text_form());
572 outcome file_transfer_tentacle::handle_tree_compare_response
573 (file_transfer_infoton &resp, const octopus_request_id &item_id)
575 FUNCDEF("handle_tree_compare_response");
576 file_transfer_record *the_rec = _transfers->find(item_id._entity,
577 resp._src_root, resp._dest_root);
579 LOG(astring("could not find the record for this transfer: item=")
580 + item_id.text_form() + " src=" + resp._src_root + " dest="
582 return NOT_FOUND; // not registered, so reject it.
585 the_rec->_last_active.reset(); // record some activity on this record.
587 filename_list *flist = new filename_list;
588 if (!flist->unpack(resp._packed_data)) {
593 //hmmm: verify space on device?
595 the_rec->_diffs = flist; // set the list of differences.
599 outcome file_transfer_tentacle::handle_storage_request
600 (file_transfer_infoton &req, const octopus_request_id &item_id)
602 FUNCDEF("handle_storage_request");
603 if (_mode & ONLY_REPORT_DIFFS) {
604 // store an unhandled infoton.
605 unhandled_request *deny = new unhandled_request(item_id, req.classifier(), NO_HANDLER);
606 store_product(deny, item_id);
610 // look up the transfer record.
611 file_transfer_record *the_rec = _transfers->find(item_id._entity,
612 req._src_root, req._dest_root);
614 LOG(astring("could not find the record for this transfer: item=")
615 + item_id.text_form() + " src=" + req._src_root + " dest="
617 return NOT_FOUND; // not registered, so reject it.
620 the_rec->_last_active.reset(); // mark it as still active.
622 file_transfer_infoton *resp = dynamic_cast<file_transfer_infoton *>(req.clone());
624 if (!the_rec->_diffs) return BAD_INPUT; // wrong type of object.
626 outcome bufret = heavy_file_operations::buffer_files
627 (_correspondences->translate(the_rec->_src_root), *the_rec->_diffs,
628 the_rec->_last_sent, resp->_packed_data, _maximum_transfer);
629 if (bufret == heavy_file_operations::FINISHED) {
630 bufret = OKAY; // in either case, we don't emit a finished outcome; handled elsewhere.
631 if (!resp->_packed_data.length()) {
632 // blank packages, so finish by setting command to be a conclude marker.
633 the_rec->_done = true;
634 resp->_command = file_transfer_infoton::CONCLUDE_TRANSFER_MARKER;
636 } else if (bufret != OKAY) {
637 // complain, but still send.
638 LOG(astring("buffer files returned an error on item=")
639 + item_id.text_form() + " src=" + req._src_root + " dest="
643 //can remove this block if stops saying it.
644 if ((bufret == OKAY) && !resp->_packed_data.length() ) {
645 LOG("marking empty transfer as done; why not caught above at FINISHED check?");
646 the_rec->_done = true;
647 resp->_command = file_transfer_infoton::CONCLUDE_TRANSFER_MARKER;
651 resp->_request = false; // it's a response now.
652 store_product(resp, item_id);
656 outcome file_transfer_tentacle::handle_storage_response
657 (file_transfer_infoton &resp, const octopus_request_id &item_id)
659 FUNCDEF("handle_storage_response");
660 if (_mode & ONLY_REPORT_DIFFS) {
665 // look up the transfer record.
666 file_transfer_record *the_rec = _transfers->find(item_id._entity,
667 resp._src_root, resp._dest_root);
668 if (!the_rec) return NOT_FOUND; // not registered, so reject it.
670 the_rec->_last_active.reset(); // mark it as still active.
672 if (!resp._packed_data.length()) {
673 // mark that we're done now.
674 the_rec->_done = true;
677 // chew on all the things they sent us.
678 while (resp._packed_data.length()) {
680 file_transfer_header found(empty);
681 if (!found.unpack(resp._packed_data)) {
683 LOG(astring("corruption seen on item=") + item_id.text_form()
684 + " src=" + resp._src_root + " dest=" + resp._dest_root);
687 the_rec->_last_sent = found;
689 if (found._length > resp._packed_data.length()) {
690 // another case for leaving--not enough data left in the buffer.
691 LOG(astring("data underflow seen on item=") + item_id.text_form()
692 + " src=" + resp._src_root + " dest=" + resp._dest_root);
695 byte_array to_write = resp._packed_data.subarray(0, found._length - 1);
696 resp._packed_data.zap(0, found._length - 1);
698 if (!the_rec->_diffs) return BAD_INPUT;
700 const file_info *recorded_info = the_rec->_diffs->find(found._filename);
701 if (!recorded_info) {
702 LOG(astring("unrequested file seen: ") + found._filename);
703 continue; // maybe there are others that aren't confused.
706 astring full_file = resp._dest_root + filename::default_separator()
707 + recorded_info->secondary();
708 LOG(astring("telling it to write to fullfile: ") + full_file);
710 outcome ret = heavy_file_operations::write_file_chunk(full_file,
711 found._byte_start, to_write);
713 LOG(astring("failed to write file chunk: error=")
714 + heavy_file_operations::outcome_name(ret) + " file=" + full_file
715 + a_sprintf(" start=%d len=%d", found._byte_start, found._length));
717 found._time.set_time(full_file);
720 // there is no response product to store.
724 outcome file_transfer_tentacle::conclude_storage_request
725 (file_transfer_infoton &req, const octopus_request_id &item_id)
727 FUNCDEF("conclude_storage_request");
728 if (_mode & ONLY_REPORT_DIFFS) {
729 // store an unhandled infoton.
730 unhandled_request *deny = new unhandled_request(item_id, req.classifier(), NO_HANDLER);
731 store_product(deny, item_id);
735 // look up the transfer record.
736 file_transfer_record *the_rec = _transfers->find(item_id._entity,
737 req._src_root, req._dest_root);
739 LOG(astring("could not find the record for this transfer: item=")
740 + item_id.text_form() + " src=" + req._src_root + " dest="
742 return NOT_FOUND; // not registered, so reject it.
745 the_rec->_last_active.reset(); // mark it as still active.
747 file_transfer_infoton *resp = dynamic_cast<file_transfer_infoton *>(req.clone());
749 if (!the_rec->_diffs) return BAD_INPUT; // wrong type of object.
751 the_rec->_done = true; // we're concluding the transfer, so that's that.
752 resp->_request = false; // it's a response now.
753 store_product(resp, item_id);
755 LOG(astring("concluding transfer request on src=") + req._src_root + " dest="
761 outcome file_transfer_tentacle::conclude_storage_response
762 (file_transfer_infoton &resp, const octopus_request_id &item_id)
764 FUNCDEF("conclude_storage_response");
765 if (_mode & ONLY_REPORT_DIFFS) {
770 // look up the transfer record.
771 file_transfer_record *the_rec = _transfers->find(item_id._entity,
772 resp._src_root, resp._dest_root);
773 if (!the_rec) return NOT_FOUND; // not registered, so reject it.
775 the_rec->_last_active.reset(); // mark it as still active.
777 // mark that we're done now.
778 the_rec->_done = true;
780 LOG(astring("concluding transfer response on src=") + resp._src_root + " dest="
783 // there is no response product to store.
787 // consume() is the only method that is allowed to invoke the "handle_X" methods
788 // and it must lock the object beforehand.
790 outcome file_transfer_tentacle::consume(infoton &to_chow,
791 const octopus_request_id &item_id, byte_array &transformed)
795 file_transfer_infoton *inf = dynamic_cast<file_transfer_infoton *>(&to_chow);
796 if (!inf) return DISALLOWED; // not for us.
798 AUTO_LOCK; // protect our lists while we're working on them.
800 switch (inf->_command) {
801 case file_transfer_infoton::TREE_COMPARISON: {
802 if (inf->_request) return handle_tree_compare_request(*inf, item_id);
803 else return handle_tree_compare_response(*inf, item_id);
805 case file_transfer_infoton::PLACE_FILE_CHUNKS: {
806 if (inf->_request) return handle_storage_request(*inf, item_id);
807 else return handle_storage_response(*inf, item_id);
809 case file_transfer_infoton::CONCLUDE_TRANSFER_MARKER: {
810 if (inf->_request) return conclude_storage_request(*inf, item_id);
811 else return conclude_storage_response(*inf, item_id);
814 return BAD_INPUT; // not a recognized command.
817 outcome file_transfer_tentacle::refresh_now(const astring &source_mapping)
819 FUNCDEF("refresh_now");
821 for (int i = 0; i < _correspondences->elements(); i++) {
822 file_transfer_record *curr = _correspondences->borrow(i);
824 if (curr->_source_mapping != source_mapping) continue;
825 if (curr->_local_dir) {
826 #ifdef DEBUG_FILE_TRANSFER_TENTACLE
827 LOG(astring("refreshing tree for: ent=") + curr->_ent.text_form()
828 + " src=" + curr->_src_root + " dest=" + curr->_dest_root);
830 WHACK(curr->_local_dir);
831 curr->_local_dir = new directory_tree(curr->_src_root);
832 curr->_local_dir->calculate( !(_mode & COMPARE_CONTENT_SAMPLE) );
833 #ifdef DEBUG_FILE_TRANSFER_TENTACLE
834 LOG(astring("done refreshing tree for: ent=") + curr->_ent.text_form()
835 + " src=" + curr->_src_root + " dest=" + curr->_dest_root);
838 curr->_last_active.reset(); // reset our action time.