| ︙ | | | ︙ | |
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
int nIGotSent; /* Number of "igot" cards sent */
int nGimmeSent; /* Number of gimme cards sent */
int nFileSent; /* Number of files sent */
int nDeltaSent; /* Number of deltas sent */
int nFileRcvd; /* Number of files received */
int nDeltaRcvd; /* Number of deltas received */
int nDanglingFile; /* Number of dangling deltas received */
int mxSend; /* Stop sending "file" with pOut reaches this size */
u8 syncPrivate; /* True to enable syncing private content */
u8 nextIsPrivate; /* If true, next "file" received is a private */
time_t maxTime; /* Time when this transfer should be finished */
};
/*
|
|
>
|
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
int nIGotSent; /* Number of "igot" cards sent */
int nGimmeSent; /* Number of gimme cards sent */
int nFileSent; /* Number of files sent */
int nDeltaSent; /* Number of deltas sent */
int nFileRcvd; /* Number of files received */
int nDeltaRcvd; /* Number of deltas received */
int nDanglingFile; /* Number of dangling deltas received */
int mxSend; /* Stop sending "file" when pOut reaches this size */
int resync; /* Send igot cards for all holdings */
u8 syncPrivate; /* True to enable syncing private content */
u8 nextIsPrivate; /* If true, next "file" received is a private */
time_t maxTime; /* Time when this transfer should be finished */
};
/*
|
| ︙ | | | ︙ | |
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
|
/*
** Send an igot message for every entry in unclustered table.
** Return the number of cards sent.
*/
static int send_unclustered(Xfer *pXfer){
Stmt q;
int cnt = 0;
db_prepare(&q,
"SELECT uuid FROM unclustered JOIN blob USING(rid)"
" WHERE NOT EXISTS(SELECT 1 FROM shun WHERE uuid=blob.uuid)"
" AND NOT EXISTS(SELECT 1 FROM phantom WHERE rid=blob.rid)"
" AND NOT EXISTS(SELECT 1 FROM private WHERE rid=blob.rid)"
);
while( db_step(&q)==SQLITE_ROW ){
blob_appendf(pXfer->pOut, "igot %s\n", db_column_text(&q, 0));
cnt++;
}
db_finalize(&q);
return cnt;
}
/*
** Send an igot message for every artifact.
*/
static void send_all(Xfer *pXfer){
|
>
|
>
>
>
>
>
>
>
>
>
>
|
|
|
|
|
>
>
>
|
>
>
|
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
|
/*
** Send an igot message for every entry in unclustered table.
** Return the number of cards sent.
*/
static int send_unclustered(Xfer *pXfer){
Stmt q;
int cnt = 0;
if( pXfer->resync ){
db_prepare(&q,
"SELECT uuid, rid FROM blob"
" WHERE NOT EXISTS(SELECT 1 FROM shun WHERE uuid=blob.uuid)"
" AND NOT EXISTS(SELECT 1 FROM phantom WHERE rid=blob.rid)"
" AND NOT EXISTS(SELECT 1 FROM private WHERE rid=blob.rid)"
" AND blob.rid<=%d"
" ORDER BY blob.rid DESC",
pXfer->resync
);
}else{
db_prepare(&q,
"SELECT uuid FROM unclustered JOIN blob USING(rid)"
" WHERE NOT EXISTS(SELECT 1 FROM shun WHERE uuid=blob.uuid)"
" AND NOT EXISTS(SELECT 1 FROM phantom WHERE rid=blob.rid)"
" AND NOT EXISTS(SELECT 1 FROM private WHERE rid=blob.rid)"
);
}
while( db_step(&q)==SQLITE_ROW ){
blob_appendf(pXfer->pOut, "igot %s\n", db_column_text(&q, 0));
cnt++;
if( pXfer->resync && pXfer->mxSend<blob_size(pXfer->pOut) ){
pXfer->resync = db_column_int(&q, 1)-1;
}
}
db_finalize(&q);
if( cnt==0 ) pXfer->resync = 0;
return cnt;
}
/*
** Send an igot message for every artifact.
*/
static void send_all(Xfer *pXfer){
|
| ︙ | | | ︙ | |
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
|
/*
** Run the pre-transfer TH1 script, if any, and returns the return code.
** Prepare the "http" command for use in other hook scripts.
*/
int run_common_script(void){
int result = 0;
if( !commonScriptRan ){
Th_FossilInit(0, 0); /* Make sure TH1 is ready. */
commonScriptRan = 1; /* enable run_script to do something */
result = run_script("xfer-common-script", 0);
Th_CreateCommand(g.interp, "http", httpCmd, 0, 0);
}
return result;
}
|
|
|
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
|
/*
** Run the pre-transfer TH1 script, if any, and returns the return code.
** Prepare the "http" command for use in other hook scripts.
*/
int run_common_script(void){
int result = 0;
if( !commonScriptRan ){
Th_FossilInit(TH_INIT_DEFAULT); /* Make sure TH1 is ready. */
commonScriptRan = 1; /* enable run_script to do something */
result = run_script("xfer-common-script", 0);
Th_CreateCommand(g.interp, "http", httpCmd, 0, 0);
}
return result;
}
|
| ︙ | | | ︙ | |
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
|
login_check_credentials();
if( !g.perm.Private ){
server_private_xfer_not_authorized();
}else{
xfer.syncPrivate = 1;
}
}
}else
/* Unknown message
*/
{
cgi_reset_content();
@ error bad\scommand:\s%F(blob_str(&xfer.line))
|
>
>
>
>
>
>
>
|
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
|
login_check_credentials();
if( !g.perm.Private ){
server_private_xfer_not_authorized();
}else{
xfer.syncPrivate = 1;
}
}
/* pragma send-catalog
**
** Send igot cards for all known artifacts.
*/
if( blob_eq(&xfer.aToken[1], "send-catalog") ){
xfer.resync = 0x7fffffff;
}
}else
/* Unknown message
*/
{
cgi_reset_content();
@ error bad\scommand:\s%F(blob_str(&xfer.line))
|
| ︙ | | | ︙ | |
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
|
** Flag options for controlling client_sync()
*/
#define SYNC_PUSH 0x0001
#define SYNC_PULL 0x0002
#define SYNC_CLONE 0x0004
#define SYNC_PRIVATE 0x0008
#define SYNC_VERBOSE 0x0010
#endif
/*
** Sync to the host identified in g.urlName and g.urlPath. This
** routine is called by the client.
**
** Records are pushed to the server if pushFlag is true. Records
** are pulled if pullFlag is true. A full sync occurs if both are
|
>
>
>
>
>
>
>
>
|
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
|
** Flag options for controlling client_sync()
*/
#define SYNC_PUSH 0x0001
#define SYNC_PULL 0x0002
#define SYNC_CLONE 0x0004
#define SYNC_PRIVATE 0x0008
#define SYNC_VERBOSE 0x0010
#define SYNC_RESYNC 0x0020
#endif
/*
** Floating-point absolute value
*/
static double fossil_fabs(double x){
return x>0.0 ? x : -x;
}
/*
** Sync to the host identified in g.urlName and g.urlPath. This
** routine is called by the client.
**
** Records are pushed to the server if pushFlag is true. Records
** are pulled if pullFlag is true. A full sync occurs if both are
|
| ︙ | | | ︙ | |
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
|
const char *zSCode = db_get("server-code", "x");
const char *zPCode = db_get("project-code", 0);
int nErr = 0; /* Number of errors */
int nRoundtrip= 0; /* Number of HTTP requests */
int nArtifactSent = 0; /* Total artifacts sent */
int nArtifactRcvd = 0; /* Total artifacts received */
const char *zOpType = 0;/* Push, Pull, Sync, Clone */
if( db_get_boolean("dont-push", 0) ) syncFlags &= ~SYNC_PUSH;
if( (syncFlags & (SYNC_PUSH|SYNC_PULL|SYNC_CLONE))==0
&& configRcvMask==0 && configSendMask==0 ) return 0;
transport_stats(0, 0, 1);
socket_global_init();
|
>
|
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
|
const char *zSCode = db_get("server-code", "x");
const char *zPCode = db_get("project-code", 0);
int nErr = 0; /* Number of errors */
int nRoundtrip= 0; /* Number of HTTP requests */
int nArtifactSent = 0; /* Total artifacts sent */
int nArtifactRcvd = 0; /* Total artifacts received */
const char *zOpType = 0;/* Push, Pull, Sync, Clone */
double rSkew = 0.0; /* Maximum time skew */
if( db_get_boolean("dont-push", 0) ) syncFlags &= ~SYNC_PUSH;
if( (syncFlags & (SYNC_PUSH|SYNC_PULL|SYNC_CLONE))==0
&& configRcvMask==0 && configSendMask==0 ) return 0;
transport_stats(0, 0, 1);
socket_global_init();
|
| ︙ | | | ︙ | |
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
|
/* TBD: Request all transferable configuration values */
content_enable_dephantomize(0);
zOpType = "Clone";
}else if( syncFlags & SYNC_PULL ){
blob_appendf(&send, "pull %s %s\n", zSCode, zPCode);
nCardSent++;
zOpType = (syncFlags & SYNC_PUSH)?"Sync":"Pull";
}
if( syncFlags & SYNC_PUSH ){
blob_appendf(&send, "push %s %s\n", zSCode, zPCode);
nCardSent++;
if( (syncFlags & SYNC_PULL)==0 ) zOpType = "Push";
}
manifest_crosslink_begin();
transport_global_startup();
if( syncFlags & SYNC_VERBOSE ){
fossil_print(zLabelFormat, "", "Bytes", "Cards", "Artifacts", "Deltas");
}
|
>
>
>
>
>
|
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
|
/* TBD: Request all transferable configuration values */
content_enable_dephantomize(0);
zOpType = "Clone";
}else if( syncFlags & SYNC_PULL ){
blob_appendf(&send, "pull %s %s\n", zSCode, zPCode);
nCardSent++;
zOpType = (syncFlags & SYNC_PUSH)?"Sync":"Pull";
if( (syncFlags & SYNC_RESYNC)!=0 && nCycle<2 ){
blob_appendf(&send, "pragma send-catalog\n");
nCardSent++;
}
}
if( syncFlags & SYNC_PUSH ){
blob_appendf(&send, "push %s %s\n", zSCode, zPCode);
nCardSent++;
if( (syncFlags & SYNC_PULL)==0 ) zOpType = "Push";
if( (syncFlags & SYNC_RESYNC)!=0 ) xfer.resync = 0x7fffffff;
}
manifest_crosslink_begin();
transport_global_startup();
if( syncFlags & SYNC_VERBOSE ){
fossil_print(zLabelFormat, "", "Bytes", "Cards", "Artifacts", "Deltas");
}
|
| ︙ | | | ︙ | |
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
|
if( memcmp(zLine, "# timestamp ", 12)==0 ){
char zTime[20];
double rDiff;
sqlite3_snprintf(sizeof(zTime), zTime, "%.19s", &zLine[12]);
rDiff = db_double(9e99, "SELECT julianday('%q') - %.17g",
zTime, rArrivalTime);
if( rDiff>9e98 || rDiff<-9e98 ) rDiff = 0.0;
if( (rDiff*24.0*3600.0) > 10.0 ){
fossil_warning("*** time skew *** server is fast by %s",
db_timespan_name(rDiff));
g.clockSkewSeen = 1;
}else if( rDiff*24.0*3600.0 < -(blob_size(&recv)/5000.0 + 20.0) ){
fossil_warning("*** time skew *** server is slow by %s",
db_timespan_name(-rDiff));
g.clockSkewSeen = 1;
}
}
nCardRcvd++;
continue;
}
xfer.nToken = blob_tokenize(&xfer.line, xfer.aToken, count(xfer.aToken));
nCardRcvd++;
if( (syncFlags & SYNC_VERBOSE)!=0 && recv.nUsed>0 ){
|
<
<
<
<
|
<
|
<
<
|
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
|
if( memcmp(zLine, "# timestamp ", 12)==0 ){
char zTime[20];
double rDiff;
sqlite3_snprintf(sizeof(zTime), zTime, "%.19s", &zLine[12]);
rDiff = db_double(9e99, "SELECT julianday('%q') - %.17g",
zTime, rArrivalTime);
if( rDiff>9e98 || rDiff<-9e98 ) rDiff = 0.0;
if( rDiff*24.0*3600.0 >= -(blob_size(&recv)/5000.0 + 20) ) rDiff = 0.0;
if( fossil_fabs(rDiff)>fossil_fabs(rSkew) ) rSkew = rDiff;
}
nCardRcvd++;
continue;
}
xfer.nToken = blob_tokenize(&xfer.line, xfer.aToken, count(xfer.aToken));
nCardRcvd++;
if( (syncFlags & SYNC_VERBOSE)!=0 && recv.nUsed>0 ){
|
| ︙ | | | ︙ | |
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
|
** we have gone at least two rounds. Always go at least two rounds
** on a clone in order to be sure to retrieve the configuration
** information which is only sent on the second round.
*/
if( cloneSeqno<=0 && nCycle>1 ) go = 0;
};
transport_stats(&nSent, &nRcvd, 1);
fossil_force_newline();
fossil_print(
"%s finished with %lld bytes sent, %lld bytes received\n",
zOpType, nSent, nRcvd);
transport_close();
transport_global_shutdown();
db_multi_exec("DROP TABLE onremote");
manifest_crosslink_end();
content_enable_dephantomize(1);
db_end_transaction(0);
return nErr;
}
|
>
>
>
>
>
>
>
>
>
>
|
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
|
** we have gone at least two rounds. Always go at least two rounds
** on a clone in order to be sure to retrieve the configuration
** information which is only sent on the second round.
*/
if( cloneSeqno<=0 && nCycle>1 ) go = 0;
};
transport_stats(&nSent, &nRcvd, 1);
if( (rSkew*24.0*3600.0) > 10.0 ){
fossil_warning("*** time skew *** server is fast by %s",
db_timespan_name(rSkew));
g.clockSkewSeen = 1;
}else if( rSkew*24.0*3600.0 < -10.0 ){
fossil_warning("*** time skew *** server is slow by %s",
db_timespan_name(-rSkew));
g.clockSkewSeen = 1;
}
fossil_force_newline();
fossil_print(
"%s finished with %lld bytes sent, %lld bytes received\n",
zOpType, nSent, nRcvd);
transport_close();
transport_global_shutdown();
db_multi_exec("DROP TABLE onremote");
manifest_crosslink_end();
content_enable_dephantomize(1);
db_end_transaction(0);
return nErr;
}
|