Check-in [75c476ccd1]
Not logged in
Overview

SHA1 Hash:75c476ccd178dca0d970b2c5e6718c6eacaf149e
Date: 2007-07-23 20:33:04
User: drh
Comment:Work on network synchronization
Timelines: ancestors | descendants | both | trunk
Other Links: files | ZIP archive | manifest

Tags And Properties
Changes
[hide diffs]

Modified src/blob.c from [98f347f72a] to [8ec1e279a6].

@@ -209,10 +209,14 @@
 /*
 ** Return a pointer to a null-terminated string for a blob.
 */
 char *blob_str(Blob *p){
   blob_is_init(p);
+  if( p->nUsed==0 ){
+    blob_append(p, "", 1);
+    p->nUsed = 0;
+  }
   if( p->aData[p->nUsed]!=0 ){
     blob_materialize(p);
   }
   return p->aData;
 }

Modified src/content.c from [d3786bb3e7] to [fa624bb975].

@@ -191,11 +191,11 @@
   if( rid>0 ){
     /* We are just adding data to a phantom */
     assert( pBlob!=0 );
     db_prepare(&s1,
       "UPDATE blob SET rcvid=%d, size=%d, content=:data WHERE rid=%d",
-       g.rcvid, size, blob_str(&hash)
+       g.rcvid, size, rid
     );
     blob_compress(pBlob, &cmpr);
     db_bind_blob(&s1, ":data", &cmpr);
     db_exec(&s1);
   }else{

Modified src/verify.c from [f52a353f94] to [7995bb74af].

@@ -42,13 +42,15 @@
   if( blob_size(&uuid)!=UUID_SIZE ){
     fossil_panic("not a valid rid: %d", rid);
   }
   content_get(rid, &content);
   sha1sum_blob(&content, &hash);
-  blob_reset(&content);
+/*  blob_reset(&content); */
   if( blob_compare(&uuid, &hash) ){
-    fossil_panic("hash of rid %d does not match its uuid", rid);
+printf("content=[%s]\n", blob_str(&content));
+    fossil_panic("hash of rid %d (%b) does not match its uuid (%b)",
+                  rid, &hash, &uuid);
   }
   blob_reset(&uuid);
   blob_reset(&hash);
 }
 

Modified src/xfer.c from [00d4a363f4] to [72dbb42503].

@@ -67,11 +67,11 @@
     content_get(srcid, &src);
     blob_delta_apply(&src, &content, &content);
     blob_reset(&src);
   }
   sha1sum_blob(&content, &hash);
-  if( !blob_eq_str(&aToken[1], blob_str(&content), -1) ){
+  if( !blob_eq_str(&aToken[1], blob_str(&hash), -1) ){
     blob_appendf(pErr, "content does not match sha1 hash");
   }
   blob_reset(&hash);
   rid = content_put(&content, 0);
   manifest_crosslink(rid, &content);
@@ -128,12 +128,13 @@
 
 
 /*
 ** Send all pending files.
 */
-static void send_all_pending(Blob *pOut){
+static int send_all_pending(Blob *pOut){
   int sent = 0;
+  int nSent = 0;
   int maxSize = db_get_int("http-msg-size", 1000000);
   Stmt q;
 #if 0
   db_multi_exec(
     "CREATE TEMP TABLE priority(rid INTEGER PRIMARY KEY);"
@@ -160,10 +161,11 @@
   db_prepare(&q, "SELECT rid FROM pending");
   while( db_step(&q)==SQLITE_ROW ){
     int rid = db_column_int(&q, 0);
     if( sent<maxSize ){
       sent += send_file(rid, pOut);
+      nSent++;
     }else{
       char *zUuid = db_text(0,
                       "SELECT uuid FROM blob WHERE rid=%d AND size>=0", rid);
       if( zUuid ){
         if( pOut ){
@@ -178,10 +180,11 @@
   db_finalize(&q);
 
 #if 0
   db_multi_exec("DROP TABLE priority");
 #endif
+  return nSent;
 }
 
 
 /*
 ** Check the signature on an application/x-fossil payload received by
@@ -480,10 +483,13 @@
 void client_sync(int pushFlag, int pullFlag, int cloneFlag){
   int go = 1;        /* Loop until zero */
   int nToken;
   const char *zSCode = db_get("server-code", "x");
   const char *zPCode = db_get("project-code", 0);
+  int nSent = 0;
+  int nRcvd = 0;
+  int nCycle = 0;
   Blob send;        /* Text we are sending to the server */
   Blob recv;        /* Reply we got back from the server */
   Blob line;        /* A single line of the reply */
   Blob aToken[5];   /* A tokenization of line */
   Blob errmsg;      /* Error message */
@@ -533,11 +539,11 @@
       db_finalize(&q);
     }
 
     if( pushFlag ){
       /* Send the server any files that the server has requested */
-      send_all_pending(&send);
+      nSent += send_all_pending(&send);
     }
 
     if( pullFlag || pushFlag ){
       /* Always send our leaves */
       Stmt q;
@@ -551,10 +557,11 @@
       }
       db_finalize(&q);
     }
 
     /* Exchange messages with the server */
+    printf("Sending %d files to server\n", nSent);
     http_exchange(&send, &recv);
     blob_reset(&send);
 
     /* Process the reply that came back from the server */
     while( blob_line(&recv, &line) ){
@@ -565,10 +572,11 @@
       **
       ** Receive a file transmitted from the other side
       */
       if( blob_eq(&aToken[0],"file") ){
         xfer_accept_file(&recv, aToken, nToken, &errmsg);
+        nRcvd++;
       }else
 
       /*   gimme UUID
       **
       ** Server is requesting a file
@@ -618,19 +626,19 @@
 
       /*   push  SERVERCODE  PRODUCTCODE
       **
       ** Should only happen in response to a clone.
       */
-      if( blob_eq(&aToken[0],"push") && nToken==2 && cloneFlag
+      if( blob_eq(&aToken[0],"push") && nToken==3 && cloneFlag
               && blob_is_uuid(&aToken[1]) && blob_is_uuid(&aToken[2]) ){
 
         if( blob_eq_str(&aToken[1], zSCode, -1) ){
           fossil_fatal("server loop");
         }
         if( zPCode==0 ){
           zPCode = mprintf("%b", &aToken[2]);
-          db_set("product-code", zPCode);
+          db_set("project-code", zPCode);
         }
         cloneFlag = 0;
         pullFlag = 1;
       }else
 
@@ -653,13 +661,15 @@
         fossil_fatal("%b", &errmsg);
       }
       blobarray_reset(aToken, nToken);
     }
     blob_reset(&recv);
+    printf("Received %d files from server\n", nRcvd);
+    nSent = nRcvd = 0;
   };
   http_close();
   db_end_transaction(0);
   db_multi_exec(
     "DROP TABLE onremote;"
     "DROP TABLE pending;"
   );
 }