| 6 |
## |
## |
| 7 |
## ---------------------------------------------------------------------------------------- |
## ---------------------------------------------------------------------------------------- |
| 8 |
## $Log$ |
## $Log$ |
| 9 |
|
## Revision 1.5 2004/05/11 19:43:02 joko |
| 10 |
|
## don't use File::RsyncP::Digest on win32 |
| 11 |
|
## |
| 12 |
|
## Revision 1.4 2004/05/06 12:53:07 jonen |
| 13 |
|
## + added use of File::RsycP::digest |
| 14 |
|
## |
| 15 |
## Revision 1.3 2003/05/13 08:19:00 joko |
## Revision 1.3 2003/05/13 08:19:00 joko |
| 16 |
## switched to crc32 |
## switched to crc32 |
| 17 |
## |
## |
| 29 |
=head1 Todo |
=head1 Todo |
| 30 |
|
|
| 31 |
o Data::Transfer::Sync::Compare::Slot using Compare::Struct |
o Data::Transfer::Sync::Compare::Slot using Compare::Struct |
| 32 |
|
o Load checksum algorithm on demand, do some negotiation |
| 33 |
|
|
| 34 |
=cut |
=cut |
| 35 |
|
|
| 40 |
|
|
| 41 |
use mixin::with qw( Data::Transfer::Sync ); |
use mixin::with qw( Data::Transfer::Sync ); |
| 42 |
|
|
| 43 |
|
use shortcuts qw( RUNNING_IN_HELL ); |
| 44 |
use Data::Dumper; |
use Data::Dumper; |
| 45 |
|
|
| 46 |
# TODO: Load these appropriatly at runtime. |
# TODO: Load these appropriatly at runtime. |
| 47 |
use Digest::MD5 qw( md5 md5_hex md5_base64 ); |
use Digest::MD5 qw( md5 md5_hex md5_base64 ); |
| 48 |
use String::CRC32; |
use String::CRC32; |
| 49 |
|
|
| 50 |
|
# don't use File::RsyncP::Digest on win32 |
| 51 |
|
# TODO: enhance here! (e.g. negotiate proper checksum-algorithm first, apply afterwards) |
| 52 |
|
if (not RUNNING_IN_HELL()) { |
| 53 |
|
eval "use File::RsyncP::Digest;"; |
| 54 |
|
} |
| 55 |
|
|
| 56 |
# get logger instance |
# get logger instance |
| 57 |
my $logger = Log::Dispatch::Config->instance; |
my $logger = Log::Dispatch::Config->instance; |
| 58 |
|
|
| 87 |
# with small payloads already in ranges of hundreds of items/rows!!! |
# with small payloads already in ranges of hundreds of items/rows!!! |
| 88 |
# Try to avoid it or try to use it only for payloads greater than, hmmm, let's say 30 chars? |
# Try to avoid it or try to use it only for payloads greater than, hmmm, let's say 30 chars? |
| 89 |
# (we had about 15 chars average per item (row)) |
# (we had about 15 chars average per item (row)) |
| 90 |
# Possible (generic) solution: Just generate checksum, if length(checksum(payload)) < payload |
# Possible (generic) solution: Just generate checksum, if length(checksum(payload)) < length(payload) |
| 91 |
#$self->{node}->{$descent}->{checksum} = DBI::hash($dump, 1); |
#$self->{node}->{$descent}->{checksum} = DBI::hash($dump, 1); |
| 92 |
|
|
| 93 |
# 3. good ol' crc32??? |
# 3. good old crc32??? |
| 94 |
$self->{node}->{$descent}->{checksum} = crc32($dump); |
#$self->{node}->{$descent}->{checksum} = crc32($dump); |
| 95 |
|
|
| 96 |
# 4. some more modern Digest::SHA1 or similar? |
# 4. File::RsyncP::Digest - Perl interface to rsync message digest algorithms |
| 97 |
|
if (not RUNNING_IN_HELL()) { |
| 98 |
|
my $rsDigest = new File::RsyncP::Digest; |
| 99 |
|
$rsDigest->add($dump); |
| 100 |
|
my $digest = $rsDigest->digest(); |
| 101 |
|
$self->{node}->{$descent}->{checksum} = unpack("H*", $digest); |
| 102 |
|
|
| 103 |
|
} else { # fallback to Digest::MD5 on win32 |
| 104 |
|
$self->{node}->{$descent}->{checksum} = md5_base64($dump) . '=='; |
| 105 |
|
} |
| 106 |
|
|
| 107 |
|
# 5. some more modern Digest::SHA1 or similar? |
| 108 |
|
|
| 109 |
# signal good |
# signal good |
| 110 |
return 1; |
return 1; |