moved BPQ block prepair code from BlockProcessor to BPQBlockProcessor
authoraidan
Thu, 18 Aug 2011 11:30:52 +0100
changeset 47 f1d80668861b
parent 46 5832202f8a44
child 48 40c9ff70865a
moved BPQ block prepair code from BlockProcessor to BPQBlockProcessor
servlib/bundling/BPQBlockProcessor.cc
servlib/bundling/BundleProtocol.cc
--- a/servlib/bundling/BPQBlockProcessor.cc	Tue Aug 16 16:08:39 2011 +0100
+++ b/servlib/bundling/BPQBlockProcessor.cc	Thu Aug 18 11:30:52 2011 +0100
@@ -46,11 +46,6 @@
 {
     log_info_p(LOG, "BPQBlockProcessor::consume() start");
 
-    (void)bundle;
-//    (void)block;
-//    (void)buf;
-//    (void)len;
-
     int cc;
 
     if ( (cc = BlockProcessor::consume(bundle, block, buf, len)) < 0) {
@@ -90,17 +85,35 @@
 {
     log_info_p(LOG, "BPQBlockProcessor::prepare()");
 
+    (void)link;
+    (void)list; 
+
+
+    // Received blocks are added to the end of the list (which
+    // maintains the order they arrived in) but API blocks 
+    // are added after the primary block (that is, before the
+    // payload and the received blocks). This places them "outside"
+    // the original blocks.
+
     if ( (const_cast<Bundle*>(bundle))->api_blocks()->
             has_block(BundleProtocol::QUERY_EXTENSION_BLOCK) ) {
 
         log_info_p(LOG, "BPQBlock found in API Block Vec => created locally");
-        return BlockProcessor::prepare(bundle, xmit_blocks, source, link, list);
+
+        ASSERT((*xmit_blocks)[0].type() == BundleProtocol::PRIMARY_BLOCK);
+        xmit_blocks->insert(xmit_blocks->begin() + 1, BlockInfo(this, source));
+
+        return BP_SUCCESS;
 
     } else if ( (const_cast<Bundle*>(bundle))->recv_blocks().
                 has_block(BundleProtocol::QUERY_EXTENSION_BLOCK) ) {
 
         log_info_p(LOG, "BPQBlock found in Recv Block Vec => created remotly");
-        return BlockProcessor::prepare(bundle, xmit_blocks, source, link, list);
+
+        xmit_blocks->append_block(this, source);
+
+        return BP_SUCCESS;
+
 
     } else {
 
--- a/servlib/bundling/BundleProtocol.cc	Tue Aug 16 16:08:39 2011 +0100
+++ b/servlib/bundling/BundleProtocol.cc	Thu Aug 18 11:30:52 2011 +0100
@@ -168,11 +168,12 @@
             continue;
         }
 
-        if (! xmit_blocks->has_block(i) &&
-            i != BundleProtocol::QUERY_EXTENSION_BLOCK) {
+        if (! xmit_blocks->has_block(i)) {
+
             if (i == BundleProtocol::QUERY_EXTENSION_BLOCK)
                 log_debug_p(LOG, "adding extra BPQ block!!!");
-            bp->prepare(bundle, xmit_blocks, NULL, link, BlockInfo::LIST_NONE);
+            else
+                bp->prepare(bundle, xmit_blocks, NULL, link, BlockInfo::LIST_NONE);
         }
     }