Fossil SCM

Work on network synchronization

drh 2007-07-23 20:33 trunk
Commit 75c476ccd178dca0d970b2c5e6718c6eacaf149e
+4
--- src/blob.c
+++ src/blob.c
@@ -209,10 +209,14 @@
209209
/*
210210
** Return a pointer to a null-terminated string for a blob.
211211
*/
212212
char *blob_str(Blob *p){
213213
blob_is_init(p);
214
+ if( p->nUsed==0 ){
215
+ blob_append(p, "", 1);
216
+ p->nUsed = 0;
217
+ }
214218
if( p->aData[p->nUsed]!=0 ){
215219
blob_materialize(p);
216220
}
217221
return p->aData;
218222
}
219223
--- src/blob.c
+++ src/blob.c
@@ -209,10 +209,14 @@
209 /*
210 ** Return a pointer to a null-terminated string for a blob.
211 */
212 char *blob_str(Blob *p){
213 blob_is_init(p);
 
 
 
 
214 if( p->aData[p->nUsed]!=0 ){
215 blob_materialize(p);
216 }
217 return p->aData;
218 }
219
--- src/blob.c
+++ src/blob.c
@@ -209,10 +209,14 @@
209 /*
210 ** Return a pointer to a null-terminated string for a blob.
211 */
212 char *blob_str(Blob *p){
213 blob_is_init(p);
214 if( p->nUsed==0 ){
215 blob_append(p, "", 1);
216 p->nUsed = 0;
217 }
218 if( p->aData[p->nUsed]!=0 ){
219 blob_materialize(p);
220 }
221 return p->aData;
222 }
223
+1 -1
--- src/content.c
+++ src/content.c
@@ -191,11 +191,11 @@
191191
if( rid>0 ){
192192
/* We are just adding data to a phantom */
193193
assert( pBlob!=0 );
194194
db_prepare(&s1,
195195
"UPDATE blob SET rcvid=%d, size=%d, content=:data WHERE rid=%d",
196
- g.rcvid, size, blob_str(&hash)
196
+ g.rcvid, size, rid
197197
);
198198
blob_compress(pBlob, &cmpr);
199199
db_bind_blob(&s1, ":data", &cmpr);
200200
db_exec(&s1);
201201
}else{
202202
--- src/content.c
+++ src/content.c
@@ -191,11 +191,11 @@
191 if( rid>0 ){
192 /* We are just adding data to a phantom */
193 assert( pBlob!=0 );
194 db_prepare(&s1,
195 "UPDATE blob SET rcvid=%d, size=%d, content=:data WHERE rid=%d",
196 g.rcvid, size, blob_str(&hash)
197 );
198 blob_compress(pBlob, &cmpr);
199 db_bind_blob(&s1, ":data", &cmpr);
200 db_exec(&s1);
201 }else{
202
--- src/content.c
+++ src/content.c
@@ -191,11 +191,11 @@
191 if( rid>0 ){
192 /* We are just adding data to a phantom */
193 assert( pBlob!=0 );
194 db_prepare(&s1,
195 "UPDATE blob SET rcvid=%d, size=%d, content=:data WHERE rid=%d",
196 g.rcvid, size, rid
197 );
198 blob_compress(pBlob, &cmpr);
199 db_bind_blob(&s1, ":data", &cmpr);
200 db_exec(&s1);
201 }else{
202
+4 -2
--- src/verify.c
+++ src/verify.c
@@ -42,13 +42,15 @@
4242
if( blob_size(&uuid)!=UUID_SIZE ){
4343
fossil_panic("not a valid rid: %d", rid);
4444
}
4545
content_get(rid, &content);
4646
sha1sum_blob(&content, &hash);
47
- blob_reset(&content);
47
+/* blob_reset(&content); */
4848
if( blob_compare(&uuid, &hash) ){
49
- fossil_panic("hash of rid %d does not match its uuid", rid);
49
+printf("content=[%s]\n", blob_str(&content));
50
+ fossil_panic("hash of rid %d (%b) does not match its uuid (%b)",
51
+ rid, &hash, &uuid);
5052
}
5153
blob_reset(&uuid);
5254
blob_reset(&hash);
5355
}
5456
5557
--- src/verify.c
+++ src/verify.c
@@ -42,13 +42,15 @@
42 if( blob_size(&uuid)!=UUID_SIZE ){
43 fossil_panic("not a valid rid: %d", rid);
44 }
45 content_get(rid, &content);
46 sha1sum_blob(&content, &hash);
47 blob_reset(&content);
48 if( blob_compare(&uuid, &hash) ){
49 fossil_panic("hash of rid %d does not match its uuid", rid);
 
 
50 }
51 blob_reset(&uuid);
52 blob_reset(&hash);
53 }
54
55
--- src/verify.c
+++ src/verify.c
@@ -42,13 +42,15 @@
42 if( blob_size(&uuid)!=UUID_SIZE ){
43 fossil_panic("not a valid rid: %d", rid);
44 }
45 content_get(rid, &content);
46 sha1sum_blob(&content, &hash);
47 /* blob_reset(&content); */
48 if( blob_compare(&uuid, &hash) ){
49 printf("content=[%s]\n", blob_str(&content));
50 fossil_panic("hash of rid %d (%b) does not match its uuid (%b)",
51 rid, &hash, &uuid);
52 }
53 blob_reset(&uuid);
54 blob_reset(&hash);
55 }
56
57
+15 -5
--- src/xfer.c
+++ src/xfer.c
@@ -67,11 +67,11 @@
6767
content_get(srcid, &src);
6868
blob_delta_apply(&src, &content, &content);
6969
blob_reset(&src);
7070
}
7171
sha1sum_blob(&content, &hash);
72
- if( !blob_eq_str(&aToken[1], blob_str(&content), -1) ){
72
+ if( !blob_eq_str(&aToken[1], blob_str(&hash), -1) ){
7373
blob_appendf(pErr, "content does not match sha1 hash");
7474
}
7575
blob_reset(&hash);
7676
rid = content_put(&content, 0);
7777
manifest_crosslink(rid, &content);
@@ -128,12 +128,13 @@
128128
129129
130130
/*
131131
** Send all pending files.
132132
*/
133
-static void send_all_pending(Blob *pOut){
133
+static int send_all_pending(Blob *pOut){
134134
int sent = 0;
135
+ int nSent = 0;
135136
int maxSize = db_get_int("http-msg-size", 1000000);
136137
Stmt q;
137138
#if 0
138139
db_multi_exec(
139140
"CREATE TEMP TABLE priority(rid INTEGER PRIMARY KEY);"
@@ -160,10 +161,11 @@
160161
db_prepare(&q, "SELECT rid FROM pending");
161162
while( db_step(&q)==SQLITE_ROW ){
162163
int rid = db_column_int(&q, 0);
163164
if( sent<maxSize ){
164165
sent += send_file(rid, pOut);
166
+ nSent++;
165167
}else{
166168
char *zUuid = db_text(0,
167169
"SELECT uuid FROM blob WHERE rid=%d AND size>=0", rid);
168170
if( zUuid ){
169171
if( pOut ){
@@ -178,10 +180,11 @@
178180
db_finalize(&q);
179181
180182
#if 0
181183
db_multi_exec("DROP TABLE priority");
182184
#endif
185
+ return nSent;
183186
}
184187
185188
186189
/*
187190
** Check the signature on an application/x-fossil payload received by
@@ -480,10 +483,13 @@
480483
void client_sync(int pushFlag, int pullFlag, int cloneFlag){
481484
int go = 1; /* Loop until zero */
482485
int nToken;
483486
const char *zSCode = db_get("server-code", "x");
484487
const char *zPCode = db_get("project-code", 0);
488
+ int nSent = 0;
489
+ int nRcvd = 0;
490
+ int nCycle = 0;
485491
Blob send; /* Text we are sending to the server */
486492
Blob recv; /* Reply we got back from the server */
487493
Blob line; /* A single line of the reply */
488494
Blob aToken[5]; /* A tokenization of line */
489495
Blob errmsg; /* Error message */
@@ -533,11 +539,11 @@
533539
db_finalize(&q);
534540
}
535541
536542
if( pushFlag ){
537543
/* Send the server any files that the server has requested */
538
- send_all_pending(&send);
544
+ nSent += send_all_pending(&send);
539545
}
540546
541547
if( pullFlag || pushFlag ){
542548
/* Always send our leaves */
543549
Stmt q;
@@ -551,10 +557,11 @@
551557
}
552558
db_finalize(&q);
553559
}
554560
555561
/* Exchange messages with the server */
562
+ printf("Sending %d files to server\n", nSent);
556563
http_exchange(&send, &recv);
557564
blob_reset(&send);
558565
559566
/* Process the reply that came back from the server */
560567
while( blob_line(&recv, &line) ){
@@ -565,10 +572,11 @@
565572
**
566573
** Receive a file transmitted from the other side
567574
*/
568575
if( blob_eq(&aToken[0],"file") ){
569576
xfer_accept_file(&recv, aToken, nToken, &errmsg);
577
+ nRcvd++;
570578
}else
571579
572580
/* gimme UUID
573581
**
574582
** Server is requesting a file
@@ -618,19 +626,19 @@
618626
619627
/* push SERVERCODE PRODUCTCODE
620628
**
621629
** Should only happen in response to a clone.
622630
*/
623
- if( blob_eq(&aToken[0],"push") && nToken==2 && cloneFlag
631
+ if( blob_eq(&aToken[0],"push") && nToken==3 && cloneFlag
624632
&& blob_is_uuid(&aToken[1]) && blob_is_uuid(&aToken[2]) ){
625633
626634
if( blob_eq_str(&aToken[1], zSCode, -1) ){
627635
fossil_fatal("server loop");
628636
}
629637
if( zPCode==0 ){
630638
zPCode = mprintf("%b", &aToken[2]);
631
- db_set("product-code", zPCode);
639
+ db_set("project-code", zPCode);
632640
}
633641
cloneFlag = 0;
634642
pullFlag = 1;
635643
}else
636644
@@ -653,13 +661,15 @@
653661
fossil_fatal("%b", &errmsg);
654662
}
655663
blobarray_reset(aToken, nToken);
656664
}
657665
blob_reset(&recv);
666
+ printf("Received %d files from server\n", nRcvd);
667
+ nSent = nRcvd = 0;
658668
};
659669
http_close();
660670
db_end_transaction(0);
661671
db_multi_exec(
662672
"DROP TABLE onremote;"
663673
"DROP TABLE pending;"
664674
);
665675
}
666676
--- src/xfer.c
+++ src/xfer.c
@@ -67,11 +67,11 @@
67 content_get(srcid, &src);
68 blob_delta_apply(&src, &content, &content);
69 blob_reset(&src);
70 }
71 sha1sum_blob(&content, &hash);
72 if( !blob_eq_str(&aToken[1], blob_str(&content), -1) ){
73 blob_appendf(pErr, "content does not match sha1 hash");
74 }
75 blob_reset(&hash);
76 rid = content_put(&content, 0);
77 manifest_crosslink(rid, &content);
@@ -128,12 +128,13 @@
128
129
130 /*
131 ** Send all pending files.
132 */
133 static void send_all_pending(Blob *pOut){
134 int sent = 0;
 
135 int maxSize = db_get_int("http-msg-size", 1000000);
136 Stmt q;
137 #if 0
138 db_multi_exec(
139 "CREATE TEMP TABLE priority(rid INTEGER PRIMARY KEY);"
@@ -160,10 +161,11 @@
160 db_prepare(&q, "SELECT rid FROM pending");
161 while( db_step(&q)==SQLITE_ROW ){
162 int rid = db_column_int(&q, 0);
163 if( sent<maxSize ){
164 sent += send_file(rid, pOut);
 
165 }else{
166 char *zUuid = db_text(0,
167 "SELECT uuid FROM blob WHERE rid=%d AND size>=0", rid);
168 if( zUuid ){
169 if( pOut ){
@@ -178,10 +180,11 @@
178 db_finalize(&q);
179
180 #if 0
181 db_multi_exec("DROP TABLE priority");
182 #endif
 
183 }
184
185
186 /*
187 ** Check the signature on an application/x-fossil payload received by
@@ -480,10 +483,13 @@
480 void client_sync(int pushFlag, int pullFlag, int cloneFlag){
481 int go = 1; /* Loop until zero */
482 int nToken;
483 const char *zSCode = db_get("server-code", "x");
484 const char *zPCode = db_get("project-code", 0);
 
 
 
485 Blob send; /* Text we are sending to the server */
486 Blob recv; /* Reply we got back from the server */
487 Blob line; /* A single line of the reply */
488 Blob aToken[5]; /* A tokenization of line */
489 Blob errmsg; /* Error message */
@@ -533,11 +539,11 @@
533 db_finalize(&q);
534 }
535
536 if( pushFlag ){
537 /* Send the server any files that the server has requested */
538 send_all_pending(&send);
539 }
540
541 if( pullFlag || pushFlag ){
542 /* Always send our leaves */
543 Stmt q;
@@ -551,10 +557,11 @@
551 }
552 db_finalize(&q);
553 }
554
555 /* Exchange messages with the server */
 
556 http_exchange(&send, &recv);
557 blob_reset(&send);
558
559 /* Process the reply that came back from the server */
560 while( blob_line(&recv, &line) ){
@@ -565,10 +572,11 @@
565 **
566 ** Receive a file transmitted from the other side
567 */
568 if( blob_eq(&aToken[0],"file") ){
569 xfer_accept_file(&recv, aToken, nToken, &errmsg);
 
570 }else
571
572 /* gimme UUID
573 **
574 ** Server is requesting a file
@@ -618,19 +626,19 @@
618
619 /* push SERVERCODE PRODUCTCODE
620 **
621 ** Should only happen in response to a clone.
622 */
623 if( blob_eq(&aToken[0],"push") && nToken==2 && cloneFlag
624 && blob_is_uuid(&aToken[1]) && blob_is_uuid(&aToken[2]) ){
625
626 if( blob_eq_str(&aToken[1], zSCode, -1) ){
627 fossil_fatal("server loop");
628 }
629 if( zPCode==0 ){
630 zPCode = mprintf("%b", &aToken[2]);
631 db_set("product-code", zPCode);
632 }
633 cloneFlag = 0;
634 pullFlag = 1;
635 }else
636
@@ -653,13 +661,15 @@
653 fossil_fatal("%b", &errmsg);
654 }
655 blobarray_reset(aToken, nToken);
656 }
657 blob_reset(&recv);
 
 
658 };
659 http_close();
660 db_end_transaction(0);
661 db_multi_exec(
662 "DROP TABLE onremote;"
663 "DROP TABLE pending;"
664 );
665 }
666
--- src/xfer.c
+++ src/xfer.c
@@ -67,11 +67,11 @@
67 content_get(srcid, &src);
68 blob_delta_apply(&src, &content, &content);
69 blob_reset(&src);
70 }
71 sha1sum_blob(&content, &hash);
72 if( !blob_eq_str(&aToken[1], blob_str(&hash), -1) ){
73 blob_appendf(pErr, "content does not match sha1 hash");
74 }
75 blob_reset(&hash);
76 rid = content_put(&content, 0);
77 manifest_crosslink(rid, &content);
@@ -128,12 +128,13 @@
128
129
130 /*
131 ** Send all pending files.
132 */
133 static int send_all_pending(Blob *pOut){
134 int sent = 0;
135 int nSent = 0;
136 int maxSize = db_get_int("http-msg-size", 1000000);
137 Stmt q;
138 #if 0
139 db_multi_exec(
140 "CREATE TEMP TABLE priority(rid INTEGER PRIMARY KEY);"
@@ -160,10 +161,11 @@
161 db_prepare(&q, "SELECT rid FROM pending");
162 while( db_step(&q)==SQLITE_ROW ){
163 int rid = db_column_int(&q, 0);
164 if( sent<maxSize ){
165 sent += send_file(rid, pOut);
166 nSent++;
167 }else{
168 char *zUuid = db_text(0,
169 "SELECT uuid FROM blob WHERE rid=%d AND size>=0", rid);
170 if( zUuid ){
171 if( pOut ){
@@ -178,10 +180,11 @@
180 db_finalize(&q);
181
182 #if 0
183 db_multi_exec("DROP TABLE priority");
184 #endif
185 return nSent;
186 }
187
188
189 /*
190 ** Check the signature on an application/x-fossil payload received by
@@ -480,10 +483,13 @@
483 void client_sync(int pushFlag, int pullFlag, int cloneFlag){
484 int go = 1; /* Loop until zero */
485 int nToken;
486 const char *zSCode = db_get("server-code", "x");
487 const char *zPCode = db_get("project-code", 0);
488 int nSent = 0;
489 int nRcvd = 0;
490 int nCycle = 0;
491 Blob send; /* Text we are sending to the server */
492 Blob recv; /* Reply we got back from the server */
493 Blob line; /* A single line of the reply */
494 Blob aToken[5]; /* A tokenization of line */
495 Blob errmsg; /* Error message */
@@ -533,11 +539,11 @@
539 db_finalize(&q);
540 }
541
542 if( pushFlag ){
543 /* Send the server any files that the server has requested */
544 nSent += send_all_pending(&send);
545 }
546
547 if( pullFlag || pushFlag ){
548 /* Always send our leaves */
549 Stmt q;
@@ -551,10 +557,11 @@
557 }
558 db_finalize(&q);
559 }
560
561 /* Exchange messages with the server */
562 printf("Sending %d files to server\n", nSent);
563 http_exchange(&send, &recv);
564 blob_reset(&send);
565
566 /* Process the reply that came back from the server */
567 while( blob_line(&recv, &line) ){
@@ -565,10 +572,11 @@
572 **
573 ** Receive a file transmitted from the other side
574 */
575 if( blob_eq(&aToken[0],"file") ){
576 xfer_accept_file(&recv, aToken, nToken, &errmsg);
577 nRcvd++;
578 }else
579
580 /* gimme UUID
581 **
582 ** Server is requesting a file
@@ -618,19 +626,19 @@
626
627 /* push SERVERCODE PRODUCTCODE
628 **
629 ** Should only happen in response to a clone.
630 */
631 if( blob_eq(&aToken[0],"push") && nToken==3 && cloneFlag
632 && blob_is_uuid(&aToken[1]) && blob_is_uuid(&aToken[2]) ){
633
634 if( blob_eq_str(&aToken[1], zSCode, -1) ){
635 fossil_fatal("server loop");
636 }
637 if( zPCode==0 ){
638 zPCode = mprintf("%b", &aToken[2]);
639 db_set("project-code", zPCode);
640 }
641 cloneFlag = 0;
642 pullFlag = 1;
643 }else
644
@@ -653,13 +661,15 @@
661 fossil_fatal("%b", &errmsg);
662 }
663 blobarray_reset(aToken, nToken);
664 }
665 blob_reset(&recv);
666 printf("Received %d files from server\n", nRcvd);
667 nSent = nRcvd = 0;
668 };
669 http_close();
670 db_end_transaction(0);
671 db_multi_exec(
672 "DROP TABLE onremote;"
673 "DROP TABLE pending;"
674 );
675 }
676

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button