added checksum seed
authorAndrew Tridgell <tridge@samba.org>
Sun, 30 Jun 1996 04:29:46 +0000 (04:29 +0000)
committerAndrew Tridgell <tridge@samba.org>
Sun, 30 Jun 1996 04:29:46 +0000 (04:29 +0000)
checksum.c
compat.c
main.c
rsync.h

index eac41c4..8e9ad27 100644 (file)
@@ -23,8 +23,7 @@ int csum_length=SUM_LENGTH;
 
 #define CSUM_CHUNK 64
 
-static char *tmpchunk = NULL;
-
+int checksum_seed = 0;
 
 /*
   a simple 32 bit checksum that can be upadted from either end
@@ -63,16 +62,28 @@ void get_checksum2(char *buf,int len,char *sum)
 {
   int i;
   MDstruct MD;
+  static char *buf1 = NULL;
+  static int len1 = 0;
+
+  if (len > len1) {
+    if (buf1) free(buf1);
+    buf1 = (char *)malloc(len+sizeof(checksum_seed));
+    len1 = len;
+    if (!buf1) out_of_memory("get_checksum2");
+  }
 
   MDbegin(&MD);
 
-  for(i = 0; i + CSUM_CHUNK <= len; i += CSUM_CHUNK) {
-    bcopy(buf+i,tmpchunk,CSUM_CHUNK);
-    MDupdate(&MD, tmpchunk, CSUM_CHUNK*8);
+  bcopy(buf,buf1,len);
+  if (checksum_seed) {
+    bcopy((char *)&checksum_seed,buf1+len,sizeof(checksum_seed));
+    len += sizeof(checksum_seed);
   }
 
-  bcopy(buf+i,tmpchunk,len-i);
-  MDupdate(&MD, tmpchunk, (len-i)*8);
+  for(i = 0; i + CSUM_CHUNK <= len; i += CSUM_CHUNK) {
+    MDupdate(&MD, buf1+i, CSUM_CHUNK*8);
+  }
+  MDupdate(&MD, buf1+i, (len-i)*8);
 
   sum_put(&MD,sum);
 }
@@ -85,6 +96,7 @@ void file_checksum(char *fname,char *sum,off_t size)
   char *buf;
   int fd;
   int len = size;
+  char tmpchunk[CSUM_CHUNK];
 
   bzero(sum,csum_length);
 
@@ -112,8 +124,6 @@ void file_checksum(char *fname,char *sum,off_t size)
 
 void checksum_init(void)
 {
-  tmpchunk = (char *)malloc(CSUM_CHUNK);
-  if (!tmpchunk) out_of_memory("checksum_init");
 }
 
 
index 04913c2..293bbc6 100644 (file)
--- a/compat.c
+++ b/compat.c
@@ -21,6 +21,8 @@
 
 #include "rsync.h"
 
+extern int am_server;
+
 extern int csum_length;
 
 extern int preserve_links;
@@ -30,6 +32,7 @@ extern int preserve_uid;
 extern int preserve_gid;
 extern int preserve_times;
 extern int always_checksum;
+extern int checksum_seed;
 
 
 extern int remote_version;
@@ -180,8 +183,24 @@ void receive_file_entry_v10(struct file_struct *file,
 
 
 
-void setup_protocol(void)
+void setup_protocol(int f_out,int f_in)
 {
+  if (am_server) {
+    remote_version = read_int(f_in);
+    write_int(f_out,PROTOCOL_VERSION);
+    write_flush(f_out);
+  } else {
+    write_int(f_out,PROTOCOL_VERSION);
+    write_flush(f_out);
+    remote_version = read_int(f_in);
+  }
+
+  if (remote_version < MIN_PROTOCOL_VERSION ||
+      remote_version > MAX_PROTOCOL_VERSION) {
+    fprintf(FERROR,"protocol version mismatch - is your shell clean?\n");
+    exit_cleanup(1);
+  }    
+
   if (remote_version == 10) {
     send_file_entry = send_file_entry_v10;
     receive_file_entry = receive_file_entry_v10;
@@ -189,5 +208,14 @@ void setup_protocol(void)
     send_file_entry = send_file_entry_v11;
     receive_file_entry = receive_file_entry_v11;
   }
+
+  if (remote_version >= 12) {
+    if (am_server) {
+      checksum_seed = time(NULL);
+      write_int(f_out,checksum_seed);
+    } else {
+      checksum_seed = read_int(f_in);
+    }
+  }
 }
 
diff --git a/main.c b/main.c
index a088720..1619451 100644 (file)
--- a/main.c
+++ b/main.c
@@ -638,16 +638,7 @@ int main(int argc,char *argv[])
       verbose = MAX(verbose,1);
 
     if (am_server) {
-      remote_version = read_int(STDIN_FILENO);
-      if (remote_version < MIN_PROTOCOL_VERSION ||
-         remote_version > MAX_PROTOCOL_VERSION) {
-       fprintf(FERROR,"protocol version mismatch - is your shell clean?\n");
-       exit_cleanup(1);
-      }
-      write_int(STDOUT_FILENO,PROTOCOL_VERSION);
-      write_flush(STDOUT_FILENO);
-
-      setup_protocol();
+      setup_protocol(STDOUT_FILENO,STDIN_FILENO);
        
       if (sender) {
        recv_exclude_list(STDIN_FILENO);
@@ -717,18 +708,7 @@ int main(int argc,char *argv[])
 
     pid = do_cmd(shell_cmd,shell_machine,shell_user,shell_path,&f_in,&f_out);
 
-    write_int(f_out,PROTOCOL_VERSION);
-    write_flush(f_out);
-    {
-      remote_version = read_int(f_in);
-      if (remote_version < MIN_PROTOCOL_VERSION ||
-         remote_version > MAX_PROTOCOL_VERSION) {
-       fprintf(FERROR,"protocol version mismatch - is your shell clean?\n");
-       exit_cleanup(1);
-      }        
-    }
-
-    setup_protocol();
+    setup_protocol(f_out,f_in);
 
     if (verbose > 3) 
       fprintf(FERROR,"parent=%d child=%d sender=%d recurse=%d\n",
diff --git a/rsync.h b/rsync.h
index 45e1e7f..98d801c 100644 (file)
--- a/rsync.h
+++ b/rsync.h
@@ -34,7 +34,7 @@
 #define SAME_TIME (1<<7)
 
 /* update this if you make incompatible changes */
-#define PROTOCOL_VERSION 11
+#define PROTOCOL_VERSION 12
 #define MIN_PROTOCOL_VERSION 10
 #define MAX_PROTOCOL_VERSION 20