| | @@ -67,11 +67,11 @@ |
| 67 | 67 | content_get(srcid, &src); |
| 68 | 68 | blob_delta_apply(&src, &content, &content); |
| 69 | 69 | blob_reset(&src); |
| 70 | 70 | } |
| 71 | 71 | 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) ){ |
| 73 | 73 | blob_appendf(pErr, "content does not match sha1 hash"); |
| 74 | 74 | } |
| 75 | 75 | blob_reset(&hash); |
| 76 | 76 | rid = content_put(&content, 0); |
| 77 | 77 | manifest_crosslink(rid, &content); |
| | @@ -128,12 +128,13 @@ |
| 128 | 128 | |
| 129 | 129 | |
| 130 | 130 | /* |
| 131 | 131 | ** Send all pending files. |
| 132 | 132 | */ |
| 133 | | -static void send_all_pending(Blob *pOut){ |
| 133 | +static int send_all_pending(Blob *pOut){ |
| 134 | 134 | int sent = 0; |
| 135 | + int nSent = 0; |
| 135 | 136 | int maxSize = db_get_int("http-msg-size", 1000000); |
| 136 | 137 | Stmt q; |
| 137 | 138 | #if 0 |
| 138 | 139 | db_multi_exec( |
| 139 | 140 | "CREATE TEMP TABLE priority(rid INTEGER PRIMARY KEY);" |
| | @@ -160,10 +161,11 @@ |
| 160 | 161 | db_prepare(&q, "SELECT rid FROM pending"); |
| 161 | 162 | while( db_step(&q)==SQLITE_ROW ){ |
| 162 | 163 | int rid = db_column_int(&q, 0); |
| 163 | 164 | if( sent<maxSize ){ |
| 164 | 165 | sent += send_file(rid, pOut); |
| 166 | + nSent++; |
| 165 | 167 | }else{ |
| 166 | 168 | char *zUuid = db_text(0, |
| 167 | 169 | "SELECT uuid FROM blob WHERE rid=%d AND size>=0", rid); |
| 168 | 170 | if( zUuid ){ |
| 169 | 171 | if( pOut ){ |
| | @@ -178,10 +180,11 @@ |
| 178 | 180 | db_finalize(&q); |
| 179 | 181 | |
| 180 | 182 | #if 0 |
| 181 | 183 | db_multi_exec("DROP TABLE priority"); |
| 182 | 184 | #endif |
| 185 | + return nSent; |
| 183 | 186 | } |
| 184 | 187 | |
| 185 | 188 | |
| 186 | 189 | /* |
| 187 | 190 | ** Check the signature on an application/x-fossil payload received by |
| | @@ -480,10 +483,13 @@ |
| 480 | 483 | void client_sync(int pushFlag, int pullFlag, int cloneFlag){ |
| 481 | 484 | int go = 1; /* Loop until zero */ |
| 482 | 485 | int nToken; |
| 483 | 486 | const char *zSCode = db_get("server-code", "x"); |
| 484 | 487 | const char *zPCode = db_get("project-code", 0); |
| 488 | + int nSent = 0; |
| 489 | + int nRcvd = 0; |
| 490 | + int nCycle = 0; |
| 485 | 491 | Blob send; /* Text we are sending to the server */ |
| 486 | 492 | Blob recv; /* Reply we got back from the server */ |
| 487 | 493 | Blob line; /* A single line of the reply */ |
| 488 | 494 | Blob aToken[5]; /* A tokenization of line */ |
| 489 | 495 | Blob errmsg; /* Error message */ |
| | @@ -533,11 +539,11 @@ |
| 533 | 539 | db_finalize(&q); |
| 534 | 540 | } |
| 535 | 541 | |
| 536 | 542 | if( pushFlag ){ |
| 537 | 543 | /* Send the server any files that the server has requested */ |
| 538 | | - send_all_pending(&send); |
| 544 | + nSent += send_all_pending(&send); |
| 539 | 545 | } |
| 540 | 546 | |
| 541 | 547 | if( pullFlag || pushFlag ){ |
| 542 | 548 | /* Always send our leaves */ |
| 543 | 549 | Stmt q; |
| | @@ -551,10 +557,11 @@ |
| 551 | 557 | } |
| 552 | 558 | db_finalize(&q); |
| 553 | 559 | } |
| 554 | 560 | |
| 555 | 561 | /* Exchange messages with the server */ |
| 562 | + printf("Sending %d files to server\n", nSent); |
| 556 | 563 | http_exchange(&send, &recv); |
| 557 | 564 | blob_reset(&send); |
| 558 | 565 | |
| 559 | 566 | /* Process the reply that came back from the server */ |
| 560 | 567 | while( blob_line(&recv, &line) ){ |
| | @@ -565,10 +572,11 @@ |
| 565 | 572 | ** |
| 566 | 573 | ** Receive a file transmitted from the other side |
| 567 | 574 | */ |
| 568 | 575 | if( blob_eq(&aToken[0],"file") ){ |
| 569 | 576 | xfer_accept_file(&recv, aToken, nToken, &errmsg); |
| 577 | + nRcvd++; |
| 570 | 578 | }else |
| 571 | 579 | |
| 572 | 580 | /* gimme UUID |
| 573 | 581 | ** |
| 574 | 582 | ** Server is requesting a file |
| | @@ -618,19 +626,19 @@ |
| 618 | 626 | |
| 619 | 627 | /* push SERVERCODE PRODUCTCODE |
| 620 | 628 | ** |
| 621 | 629 | ** Should only happen in response to a clone. |
| 622 | 630 | */ |
| 623 | | - if( blob_eq(&aToken[0],"push") && nToken==2 && cloneFlag |
| 631 | + if( blob_eq(&aToken[0],"push") && nToken==3 && cloneFlag |
| 624 | 632 | && blob_is_uuid(&aToken[1]) && blob_is_uuid(&aToken[2]) ){ |
| 625 | 633 | |
| 626 | 634 | if( blob_eq_str(&aToken[1], zSCode, -1) ){ |
| 627 | 635 | fossil_fatal("server loop"); |
| 628 | 636 | } |
| 629 | 637 | if( zPCode==0 ){ |
| 630 | 638 | zPCode = mprintf("%b", &aToken[2]); |
| 631 | | - db_set("product-code", zPCode); |
| 639 | + db_set("project-code", zPCode); |
| 632 | 640 | } |
| 633 | 641 | cloneFlag = 0; |
| 634 | 642 | pullFlag = 1; |
| 635 | 643 | }else |
| 636 | 644 | |
| | @@ -653,13 +661,15 @@ |
| 653 | 661 | fossil_fatal("%b", &errmsg); |
| 654 | 662 | } |
| 655 | 663 | blobarray_reset(aToken, nToken); |
| 656 | 664 | } |
| 657 | 665 | blob_reset(&recv); |
| 666 | + printf("Received %d files from server\n", nRcvd); |
| 667 | + nSent = nRcvd = 0; |
| 658 | 668 | }; |
| 659 | 669 | http_close(); |
| 660 | 670 | db_end_transaction(0); |
| 661 | 671 | db_multi_exec( |
| 662 | 672 | "DROP TABLE onremote;" |
| 663 | 673 | "DROP TABLE pending;" |
| 664 | 674 | ); |
| 665 | 675 | } |
| 666 | 676 | |