Crossfire Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CF: images & caching.




Using versions is bad since then any patch recompile looks like a
new version when no client related info has changed thus creating
unneeded downloads.  It also prevents a client getting one numbering->name
from one server and using it for other servers.

A far better solution is to use checksum to determine if both have
matching data.  So client would ask for checksum of image name to
numbering file and only if client doesn't already have that file 
(presumably stored in some directory with the checksum being it's name)
then client asks for a new copy.  That way server hosts and such can
change and client only gets a new copy if it doesn't already have this
info.

Then if client discover from the numbering-name that there are image
names unknown to client then client can request those images as a
background job when there is available bandwidth in order to preload
them before needed.

I do not understand why generating and passing the checksum of a 
numbering->name file is anything other than simple.  Here's the code
for Adler-32 checksum.  Also, any decent checksum detects swapped bytes
and such so a previous comment saying a checksum won't catch same names
in different positions was incorrect.  The point of a checksum is by
passing minimal info to determine whether two things are the same.


------------------------------------------------------------

#define BASE 65521 /* largest prime smaller than 65536 */

/*
   Update a running Adler-32 checksum with the bytes buf[0..len-1]
 and return the updated checksum. The Adler-32 checksum should be
 initialized to 1.

 Usage example:

   unsigned long adler = 1L;

   while (read_buffer(buffer, length) != EOF) {
     adler = update_adler32(adler, buffer, length);
   }
   if (adler != original_adler) error();
*/
unsigned long update_adler32(unsigned long adler,
   unsigned char *buf, int len)
{
  unsigned long s1 = adler & 0xffff;
  unsigned long s2 = (adler >> 16) & 0xffff;
  int n;

  for (n = 0; n < len; n++) {
    s1 = (s1 + buf[n]) % BASE;
    s2 = (s2 + s1)     % BASE;
  }
  return (s2 << 16) + s1;
}

/* Return the adler32 of the bytes buf[0..len-1] */

unsigned long adler32(unsigned char *buf, int len)
{
  return update_adler32(1L, buf, len);
}
[to unsubscribe etc., send mail to crossfire-request@ifi.uio.no]


Follow-Ups: