DTN2-BPQ/BPQ Patch to be applied to DTNRG changeset 3509:b0407e525e08 default tip
authoraidan
Fri, 24 Jun 2011 18:05:04 +0100
changeset 2d508c4d9ea48
parent 1 9d3b0f90208b
DTN2-BPQ/BPQ Patch to be applied to DTNRG changeset 3509:b0407e525e08
n4c-dtn2-patch-3
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/n4c-dtn2-patch-3	Fri Jun 24 18:05:04 2011 +0100
     1.3 @@ -0,0 +1,165 @@
     1.4 +# HG changeset patch
     1.5 +# User aidan
     1.6 +# Date 1308850830 -3600
     1.7 +# Node ID 65e62bd13efd31a51aa5e11da972db45478d0c75
     1.8 +# Parent  06512deddac4e22d36cb163789aa07c5efb5957d
     1.9 +segfault fix in BPQResponse.cc
    1.10 +
    1.11 +diff -r 06512deddac4 -r 65e62bd13efd servlib/bundling/BPQResponse.cc
    1.12 +--- a/servlib/bundling/BPQResponse.cc	Wed Jun 22 15:06:06 2011 +0100
    1.13 ++++ b/servlib/bundling/BPQResponse.cc	Thu Jun 23 18:40:30 2011 +0100
    1.14 +@@ -69,102 +69,51 @@
    1.15 +         BlockProcessor* new_bp = BundleProtocol::find_processor(
    1.16 +                                     current_bi.owner()->block_type());
    1.17 + 
    1.18 ++        // take a pointer to the data in the buffer
    1.19 ++        // making sure the buffer is big enough
    1.20 ++        const u_char* data = current_bi.writable_contents()->
    1.21 ++                             buf(current_bi.full_length())
    1.22 ++                           + current_bi.data_offset();
    1.23 ++
    1.24 +         BlockInfo* new_bi = new_response->api_blocks()->append_block(new_bp);
    1.25 +         new_bp->init_block( new_bi,
    1.26 +                             new_response->api_blocks(),
    1.27 +                             current_bi.type(),
    1.28 +                             current_bi.flags(),
    1.29 +-                            (const u_char*)current_bi.data(),
    1.30 ++                            data,
    1.31 +                             current_bi.full_length() );
    1.32 +-/*
    1.33 +-        BlockInfo* new_bi = new BlockInfo(current);
    1.34 +-        new_bi->set_flag(current.flags());
    1.35 +-
    1.36 +-        new_response->api_blocks()->append_block(current.owner(), new_bi);
    1.37 +-*/
    1.38 +     }
    1.39 + 
    1.40 +     // copy RECV blocks
    1.41 +     BlockInfoVec* recv_blocks = cached_response->mutable_recv_blocks();
    1.42 + 
    1.43 ++    int n=0;
    1.44 +     for (BlockInfoVec::iterator iter = recv_blocks->begin();
    1.45 +          iter != recv_blocks->end();
    1.46 +          ++iter)
    1.47 +     {
    1.48 +         BlockInfo current_bi = *iter;       
    1.49 ++        log_debug_p(LOG, "RECV Block[%d] is of type: %d", 
    1.50 ++                    n++, current_bi.owner()->block_type());
    1.51 ++
    1.52 +         BlockProcessor* new_bp = BundleProtocol::find_processor(
    1.53 +                                     current_bi.owner()->block_type());
    1.54 + 
    1.55 ++        // take a pointer to the data in the buffer
    1.56 ++        // making sure the buffer is big enough
    1.57 ++        const u_char* data = current_bi.writable_contents()->
    1.58 ++                             buf(current_bi.full_length())
    1.59 ++                           + current_bi.data_offset();
    1.60 ++
    1.61 +         BlockInfo* new_bi = new_response->mutable_recv_blocks()->append_block(new_bp);
    1.62 +         new_bp->init_block( new_bi,
    1.63 +                             new_response->mutable_recv_blocks(),
    1.64 +                             current_bi.type(),
    1.65 +                             current_bi.flags(),
    1.66 +-                            (const u_char*)current_bi.data(),
    1.67 ++                            data,
    1.68 +                             current_bi.data_length() );
    1.69 +-
    1.70 +-
    1.71 +-/*
    1.72 +-        BlockInfo* new_bi = new BlockInfo(current);
    1.73 +-        new_bi->set_flag(current.flags());
    1.74 +-
    1.75 +-        new_response->mutable_recv_blocks()->append_block(current.owner(), new_bi);
    1.76 +-        if (new_bi->type() == 200) {
    1.77 +-            BPQBlock bpq(new_bi);
    1.78 +-            log_debug_p(LOG, "_COPY_  kind(%d) query_len(%d) query(%s)",
    1.79 +-                     bpq.kind(), bpq.query_len(), bpq.query_val());
    1.80 +-        }
    1.81 +-*/
    1.82 +     }
    1.83 +     
    1.84 +-//   new_response->xmit_blocks()
    1.85 +-   return true;
    1.86 +-}
    1.87 +-
    1.88 +-bool
    1.89 +-BPQResponse::copy_bpq_response(Bundle*     new_response,
    1.90 +-                               Bundle*     response)
    1.91 +-{
    1.92 +-    log_debug_p(LOG, "BPQResponse::copy_bpq_response");
    1.93 +-
    1.94 +-    // init metadata
    1.95 +-    response->copy_metadata(new_response);
    1.96 +-    
    1.97 +-    // set payload
    1.98 +-    log_debug_p(LOG, "Copy response payload");
    1.99 +-    new_response->mutable_payload()->
   1.100 +-        replace_with_file(response->payload().filename().c_str());
   1.101 +-
   1.102 +-    // copy API blocks
   1.103 +-    BlockInfoVec* api_blocks = response->api_blocks();
   1.104 +-
   1.105 +-    for (BlockInfoVec::iterator iter = api_blocks->begin();
   1.106 +-         iter != api_blocks->end();
   1.107 +-         ++iter)
   1.108 +-    {
   1.109 +-        BlockInfo current = *iter;
   1.110 +-
   1.111 +-        BlockInfo* new_bi = new BlockInfo(current);
   1.112 +-        new_bi->set_flag(current.flags());
   1.113 +-
   1.114 +-        new_response->api_blocks()->append_block(current.owner(), new_bi);
   1.115 +-    }
   1.116 +-
   1.117 +-    // copy RECV blocks
   1.118 +-    BlockInfoVec* recv_blocks = response->mutable_recv_blocks();
   1.119 +-
   1.120 +-    for (BlockInfoVec::iterator iter = recv_blocks->begin();
   1.121 +-         iter != recv_blocks->end();
   1.122 +-         ++iter)
   1.123 +-    {
   1.124 +-        BlockInfo current = *iter;
   1.125 +-
   1.126 +-        BlockInfo* new_bi = new BlockInfo(current);
   1.127 +-        new_bi->set_flag(current.flags());
   1.128 +-
   1.129 +-        new_response->mutable_recv_blocks()->append_block(current.owner(), new_bi);
   1.130 +-    }
   1.131 +-
   1.132 +    return true;
   1.133 + }
   1.134 + 
   1.135 +diff -r 06512deddac4 -r 65e62bd13efd servlib/bundling/BundleDaemon.cc
   1.136 +--- a/servlib/bundling/BundleDaemon.cc	Wed Jun 22 15:06:06 2011 +0100
   1.137 ++++ b/servlib/bundling/BundleDaemon.cc	Thu Jun 23 18:40:30 2011 +0100
   1.138 +@@ -457,6 +457,30 @@
   1.139 + 
   1.140 +         // add bundle to cache and store
   1.141 +         bundle->set_in_bpq_cache(true);
   1.142 ++
   1.143 ++        /**********************************************
   1.144 ++        // DEBUG Code - remove
   1.145 ++
   1.146 ++        if (bundle->recv_blocks().has_block(1)) {
   1.147 ++            BlockInfo* payload = const_cast<BlockInfo*> 
   1.148 ++                                 (bundle->recv_blocks().find_block(1));
   1.149 ++    
   1.150 ++            size_t length = payload->data_length();
   1.151 ++            size_t offset = payload->data_offset();
   1.152 ++            size_t buf_len = payload->writable_contents()->buf_len();
   1.153 ++
   1.154 ++            log_info("payload->data_length(): %d", payload->data_length());
   1.155 ++            log_info("payload->data_offset(): %d", payload->data_offset());
   1.156 ++            log_info("payload->full_length(): %d", payload->full_length());
   1.157 ++            log_info("payload->writable_contents()->buf_len(): %d",
   1.158 ++                      payload->writable_contents()->buf_len());
   1.159 ++
   1.160 ++            ASSERT (buf_len >= length + offset);
   1.161 ++            
   1.162 ++            memset(payload->writable_contents()->buf() + offset,
   1.163 ++                   0, length);
   1.164 ++        }
   1.165 ++        **********************************************/
   1.166 +         bpq_bundles_->push_back(bundle);
   1.167 + 
   1.168 +         if (add_to_store) {