2624 bool |
2624 bool |
2625 BundleDaemon::handle_bpq_block(Bundle* bundle, BundleReceivedEvent* event) |
2625 BundleDaemon::handle_bpq_block(Bundle* bundle, BundleReceivedEvent* event) |
2626 { |
2626 { |
2627 const BlockInfo* block = NULL; |
2627 const BlockInfo* block = NULL; |
2628 |
2628 |
2629 /** |
2629 switch (event->source_) { |
2630 * We are only interested in bundles received from peers or applications |
2630 case EVENTSRC_PEER: |
2631 * and then only if there is a QUERY_EXTENSION_BLOCK in the bundle |
2631 if (bundle->recv_blocks().has_block(BundleProtocol::QUERY_EXTENSION_BLOCK)) { |
2632 * otherwise, return straight away |
2632 block = bundle->recv_blocks(). |
2633 */ |
2633 find_block(BundleProtocol::QUERY_EXTENSION_BLOCK); |
2634 if( event->source_ == EVENTSRC_PEER && |
2634 } |
2635 bundle->recv_blocks().has_block(BundleProtocol::QUERY_EXTENSION_BLOCK)) { |
2635 break; |
2636 |
2636 |
2637 block = bundle->recv_blocks(). |
2637 case EVENTSRC_APP: |
2638 find_block(BundleProtocol::QUERY_EXTENSION_BLOCK); |
2638 if (bundle->api_blocks()->has_block(BundleProtocol::QUERY_EXTENSION_BLOCK)) { |
2639 |
2639 block = bundle->api_blocks()-> |
2640 } else if ( event->source_ == EVENTSRC_APP && |
2640 find_block(BundleProtocol::QUERY_EXTENSION_BLOCK); |
2641 bundle->api_blocks()->has_block(BundleProtocol::QUERY_EXTENSION_BLOCK)) { |
2641 } |
2642 |
2642 break; |
2643 block = bundle->api_blocks()-> |
2643 |
2644 find_block(BundleProtocol::QUERY_EXTENSION_BLOCK); |
2644 case EVENTSRC_STORE: |
2645 |
2645 if (bundle->in_bpq_cache()) { |
2646 } else if ( event->source_ == EVENTSRC_STORE && |
2646 log_info_p("/dtn/daemon/bpq", "handle_bpq_block: cache bundle from STORE"); |
2647 bundle->in_bpq_cache() ) { |
2647 BPQBlock bpq_block(bundle); |
2648 |
2648 accept_bpq_response(bundle, &bpq_block, false); |
2649 log_info_p("/dtn/daemon/bpq", "handle_bpq_block: cache bundle from STORE"); |
2649 return true; |
2650 BPQBlock bpq_block(bundle); |
2650 } |
2651 accept_bpq_response(bundle, &bpq_block, false); |
2651 break; |
2652 return true; |
2652 |
2653 } else { |
2653 case EVENTSRC_FRAGMENTATION: |
2654 |
2654 if (bundle->recv_blocks().has_block(BundleProtocol::QUERY_EXTENSION_BLOCK)) { |
2655 log_debug_p("/dtn/daemon/bpq", "BPQ Block not found in bundle"); |
2655 block = bundle->recv_blocks(). |
2656 return false; |
2656 find_block(BundleProtocol::QUERY_EXTENSION_BLOCK); |
2657 } |
2657 } |
|
2658 else if (bundle->api_blocks()->has_block(BundleProtocol::QUERY_EXTENSION_BLOCK)) { |
|
2659 block = bundle->api_blocks()-> |
|
2660 find_block(BundleProtocol::QUERY_EXTENSION_BLOCK); |
|
2661 } |
|
2662 break; |
|
2663 |
|
2664 default: |
|
2665 log_err_p("/dtn/daemon/bpq", "Handle BPQ Block failed for unknown eventsrc: %s", |
|
2666 source_to_str((event_source_t)event->source_)); |
|
2667 NOTREACHED; |
|
2668 return false; |
|
2669 } |
2658 |
2670 |
2659 /** |
2671 /** |
2660 * At this point the BPQ Block has been found in the bundle |
2672 * At this point the BPQ Block has been found in the bundle |
2661 */ |
2673 */ |
2662 ASSERT ( block != NULL ); |
2674 ASSERT ( block != NULL ); |
2668 |
2680 |
2669 if (bpq_block.kind() == BPQBlock::KIND_QUERY) { |
2681 if (bpq_block.kind() == BPQBlock::KIND_QUERY) { |
2670 if (answer_bpq_query(bundle, &bpq_block)) { |
2682 if (answer_bpq_query(bundle, &bpq_block)) { |
2671 event->daemon_only_ = true; |
2683 event->daemon_only_ = true; |
2672 } |
2684 } |
2673 |
2685 } |
2674 } else if (bpq_block.kind() == BPQBlock::KIND_RESPONSE && |
2686 else if (bpq_block.kind() == BPQBlock::KIND_RESPONSE) { |
2675 event->source_ != EVENTSRC_APP) { //Skip over local responces |
2687 // don't accept local responses |
2676 accept_bpq_response(bundle, &bpq_block, event->source_ != EVENTSRC_STORE); |
2688 if (event->source_ != EVENTSRC_APP) { |
2677 |
2689 accept_bpq_response(bundle, &bpq_block, event->source_ != EVENTSRC_STORE); |
2678 } else { |
2690 } |
|
2691 } |
|
2692 else { |
2679 log_err_p("/dtn/daemon/bpq", "ERROR - BPQ Block: invalid kind %d", |
2693 log_err_p("/dtn/daemon/bpq", "ERROR - BPQ Block: invalid kind %d", |
2680 bpq_block.kind()); |
2694 bpq_block.kind()); |
|
2695 NOTREACHED; |
2681 return false; |
2696 return false; |
2682 } |
2697 } |
2683 |
2698 |
2684 return true; |
2699 return true; |
2685 } |
2700 } |