Browse Source

*** empty log message ***

Joe Shochet 25 years ago
parent
commit
466704c470
2 changed files with 36 additions and 20 deletions
  1. 20 10
      panda/src/downloader/downloadDb.cxx
  2. 16 10
      panda/src/downloader/downloadDb.h

+ 20 - 10
panda/src/downloader/downloadDb.cxx

@@ -177,8 +177,10 @@ client_file_version_correct(string mfname, string filename) const {
 //  Description:
 //  Description:
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 bool DownloadDb::
 bool DownloadDb::
-client_file_crc_correct(string mfname, string filename) const {
-  return true;
+client_file_hash_correct(string mfname, string filename) const {
+  Hash client_hash = get_client_file_hash(mfname, filename);
+  Hash server_hash = get_server_file_hash(mfname, filename);
+  return (client_hash == server_hash);
 }
 }
 
 
 // Operations on multifiles
 // Operations on multifiles
@@ -309,9 +311,9 @@ server_add_multifile(string mfname, Phase phase, Version version, int size, int
 //  Description:
 //  Description:
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void DownloadDb::
 void DownloadDb::
-server_add_file(string mfname, string fname, Version version) {
+server_add_file(string mfname, string fname, Version version, Hash hash) {
   // Make the new file record
   // Make the new file record
-  PT(FileRecord) fr = new FileRecord(fname, version);
+  PT(FileRecord) fr = new FileRecord(fname, version, hash);
 
 
   // Find the multifile with mfname
   // Find the multifile with mfname
   vector<PT(MultifileRecord)>::iterator i = _server_db._mfile_records.begin();
   vector<PT(MultifileRecord)>::iterator i = _server_db._mfile_records.begin();
@@ -664,7 +666,10 @@ parse_fr(uchar *start, int size) {
   fr->_version = di.get_int32();
   fr->_version = di.get_int32();
   
   
   downloader_cat.debug()
   downloader_cat.debug()
-    << "Parsed file record: " << fr->_name << " version: " << fr->_version << endl;
+    << "Parsed file record: " << fr->_name 
+    << " version: " << fr->_version 
+    << " hash: " << fr->_hash 
+    << endl;
 
 
   // Return the new MultifileRecord
   // Return the new MultifileRecord
   return fr;
   return fr;
@@ -894,6 +899,7 @@ DownloadDb::FileRecord::
 FileRecord(void) {
 FileRecord(void) {
   _name = "";
   _name = "";
   _version = 0;
   _version = 0;
+  _hash = 0;
 }
 }
 
 
 
 
@@ -903,9 +909,10 @@ FileRecord(void) {
 //  Description:
 //  Description:
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 DownloadDb::FileRecord::
 DownloadDb::FileRecord::
-FileRecord(string name, Version version) {
+FileRecord(string name, Version version, Hash hash) {
   _name = name;
   _name = name;
   _version = version;
   _version = version;
+  _hash = hash;
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -915,7 +922,10 @@ FileRecord(string name, Version version) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void DownloadDb::FileRecord::
 void DownloadDb::FileRecord::
 output(ostream &out) const {
 output(ostream &out) const {
-  out << " FileRecord: " << _name << "  version: " << _version << endl;
+  out << " FileRecord: " << _name 
+      << " version: " << _version 
+      << " hash: " << _hash
+      << endl;
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -924,7 +934,7 @@ output(ostream &out) const {
 //  Description:
 //  Description:
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void DownloadDb::
 void DownloadDb::
-add_version(const Filename &name, ulong hash, int version) {
+add_version(const Filename &name, Hash hash, Version version) {
   int name_code = atoi(name.get_fullpath().c_str());
   int name_code = atoi(name.get_fullpath().c_str());
   _versions[name_code][version] = hash;
   _versions[name_code][version] = hash;
 }
 }
@@ -935,7 +945,7 @@ add_version(const Filename &name, ulong hash, int version) {
 //  Description:
 //  Description:
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void DownloadDb::
 void DownloadDb::
-add_version(int name, ulong hash, int version) {
+add_version(int name, Hash hash, Version version) {
   _versions[name][version] = hash;
   _versions[name][version] = hash;
 }
 }
 
 
@@ -945,7 +955,7 @@ add_version(int name, ulong hash, int version) {
 //  Description:
 //  Description:
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 int DownloadDb::
 int DownloadDb::
-get_version(const Filename &name, ulong hash) {
+get_version(const Filename &name, Hash hash) {
   int name_code = atoi(name.get_fullpath().c_str());
   int name_code = atoi(name.get_fullpath().c_str());
   vector_ulong ulvec = _versions[name_code];
   vector_ulong ulvec = _versions[name_code];
   vector_ulong::iterator i = find(ulvec.begin(), ulvec.end(), hash);
   vector_ulong::iterator i = find(ulvec.begin(), ulvec.end(), hash);

+ 16 - 10
panda/src/downloader/downloadDb.h

@@ -27,11 +27,11 @@
 magic_number
 magic_number
 number_of_multifiles
 number_of_multifiles
 header_length multifile_name phase version size status num_files
 header_length multifile_name phase version size status num_files
-  header_length file_name version
-  header_length file_name version
+  header_length file_name version hash
+  header_length file_name version hash
 header_length multifile_name phase version size status num_files
 header_length multifile_name phase version size status num_files
-  header_length file_name version
-  header_length file_name version
+  header_length file_name version hash 
+  header_length file_name version hash
   ...
   ...
 ...
 ...
 
 
@@ -40,6 +40,7 @@ A Db is a Vector<MultifileRecord>
 MultifileRecord is a Vector<FileRecord>
 MultifileRecord is a Vector<FileRecord>
 */
 */
 
 
+typedef ulong Hash;
 typedef int Version;
 typedef int Version;
 typedef int Phase;
 typedef int Phase;
 
 
@@ -81,6 +82,7 @@ public:
   INLINE void set_client_multifile_size(string mfname, int size);
   INLINE void set_client_multifile_size(string mfname, int size);
   INLINE void set_client_multifile_delta_size(string mfname, int size);
   INLINE void set_client_multifile_delta_size(string mfname, int size);
   INLINE int get_server_multifile_size(string mfname) const;
   INLINE int get_server_multifile_size(string mfname) const;
+  INLINE void set_server_multifile_size(string mfname, int size);
 
 
   INLINE int get_client_multifile_phase(string mfname) const;
   INLINE int get_client_multifile_phase(string mfname) const;
   INLINE int get_server_multifile_phase(string mfname) const;
   INLINE int get_server_multifile_phase(string mfname) const;
@@ -92,6 +94,9 @@ public:
   INLINE int get_client_num_files(string mfname) const;
   INLINE int get_client_num_files(string mfname) const;
   INLINE int get_server_num_files(string mfname) const;
   INLINE int get_server_num_files(string mfname) const;
 
 
+  INLINE Hash get_client_file_hash(string mfname, string fname) const;
+  INLINE Hash get_server_file_hash(string mfname, string fname) const;
+
   INLINE string get_client_file_name(string mfname, int index) const;
   INLINE string get_client_file_name(string mfname, int index) const;
   INLINE string get_server_file_name(string mfname, int index) const;
   INLINE string get_server_file_name(string mfname, int index) const;
 
 
@@ -109,7 +114,7 @@ public:
   bool client_multifile_expanded(string mfname) const;
   bool client_multifile_expanded(string mfname) const;
   bool client_multifile_version_correct(string mfname) const;
   bool client_multifile_version_correct(string mfname) const;
   bool client_file_version_correct(string mfname, string filename) const;
   bool client_file_version_correct(string mfname, string filename) const;
-  bool client_file_crc_correct(string mfname, string filename) const;
+  bool client_file_hash_correct(string mfname, string filename) const;
 
 
   // Operations on multifiles
   // Operations on multifiles
   void delete_client_multifile(string mfname);
   void delete_client_multifile(string mfname);
@@ -119,17 +124,18 @@ public:
   // Server side operations to create multifile records
   // Server side operations to create multifile records
   void create_new_server_db();
   void create_new_server_db();
   void server_add_multifile(string mfname, Phase phase, Version version, int size, int status);
   void server_add_multifile(string mfname, Phase phase, Version version, int size, int status);
-  void server_add_file(string mfname, string fname, Version version);
+  void server_add_file(string mfname, string fname, Version version, Hash hash);
 
 
 public:
 public:
 
 
   class EXPCL_PANDAEXPRESS FileRecord : public ReferenceCount {
   class EXPCL_PANDAEXPRESS FileRecord : public ReferenceCount {
   public:
   public:
     FileRecord(void);
     FileRecord(void);
-    FileRecord(string name, Version version);
+    FileRecord(string name, Version version, Hash hash);
     void output(ostream &out) const;
     void output(ostream &out) const;
     string _name;
     string _name;
     Version _version;
     Version _version;
+    Hash _hash;
   };
   };
 
 
   typedef vector<PT(FileRecord)> FileRecords;
   typedef vector<PT(FileRecord)> FileRecords;
@@ -196,9 +202,9 @@ public:
 
 
   typedef vector<unsigned long> vector_ulong;
   typedef vector<unsigned long> vector_ulong;
   typedef map<int, vector_ulong> VersionMap;
   typedef map<int, vector_ulong> VersionMap;
-  void add_version(const Filename &name, ulong hash, int version);
-  void add_version(int name, ulong hash, int version);
-  int get_version(const Filename &name, ulong hash);
+  void add_version(const Filename &name, Hash hash, Version version);
+  void add_version(int name, Hash hash, Version version);
+  int get_version(const Filename &name, Hash hash);
 
 
 protected:
 protected:
   void write_version_map(ofstream &write_stream);
   void write_version_map(ofstream &write_stream);