aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2014-10-15 11:24:30 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2014-10-15 11:24:30 +0300
commit158685efd66d762817a591384b769431f5ba0b2d (patch)
treec1346433d9aba0b880020969a96ebb54670927f6
parent4b55ae68ab4f3f3083d83b2eed34b1e55b0ed93e (diff)
downloaddnstools-158685efd66d762817a591384b769431f5ba0b2d.tar.gz
dnstools-158685efd66d762817a591384b769431f5ba0b2d.tar.bz2
whoseip: bugfix
* whoseip/Whoseip/DB.pm (ipdb_save_page): Split the page being created if the data don't fit into pagesize. (ipdb_insert): Don't use fixed entry length to compute maximum number of entries.
-rw-r--r--whoseip/Whoseip/DB.pm40
1 files changed, 21 insertions, 19 deletions
diff --git a/whoseip/Whoseip/DB.pm b/whoseip/Whoseip/DB.pm
index 696afd2..1583390 100644
--- a/whoseip/Whoseip/DB.pm
+++ b/whoseip/Whoseip/DB.pm
@@ -251,15 +251,31 @@ sub ipdb_save_page($$) {
251 print STDERR "saving leaf page $page->{off}\n" 251 print STDERR "saving leaf page $page->{off}\n"
252 if $dbf->{debug}; 252 if $dbf->{debug};
253 my @a; 253 my @a;
254 my $size = length(pack('LLL',0,0,0));
255 my $i = 0;
254 foreach my $ent (@{$page->{tab}}) { 256 foreach my $ent (@{$page->{tab}}) {
255 push @a, @{$ent}[0 .. 3],freeze($ent->[4]); 257 my $x = pack('LLLa2L/a', @{$ent}[0 .. 3],freeze($ent->[4]));
258 my $l = length($x);
259 if ($size + $l > $dbf->{pagesize}) {
260 my $p = ipdb_alloc_page($dbf, IPDB_PAGE_LEAF);
261 $page->{next} = $p->{off};
262 $p->{tab} = @{$page->{tab}}[$i .. $#{$page->{tab}}];
263 $p->{dirty} = 1;
264 splice @{$page->{tab}}, $i;
265 last;
266 }
267 $size += $l;
268 push @a, $x;
269 } continue {
270 ++$i;
256 } 271 }
257 $ret = syswrite($dbf->{fd}, 272 $ret = syswrite($dbf->{fd},
258 pack('LLL(LLLa2L/a)*@'."$dbf->{pagesize}", 273 pack('LLLa*.',
259 $page->{type}, 274 $page->{type},
260 $#{$page->{tab}} + 1, 275 $#{$page->{tab}} + 1,
261 $page->{next}, 276 $page->{next},
262 @a)); 277 @a,
278 $dbf->{pagesize}));
263 } else { 279 } else {
264 croak "unrecognized page type ($page->{type})"; 280 croak "unrecognized page type ($page->{type})";
265 } 281 }
@@ -364,9 +380,10 @@ sub ipdb_get_page($$) {
364 my ($x, @a) = unpack('LL257', $s); 380 my ($x, @a) = unpack('LL257', $s);
365 $ret{tab} = \@a; 381 $ret{tab} = \@a;
366 } elsif ($ret{type} == IPDB_PAGE_LEAF) { 382 } elsif ($ret{type} == IPDB_PAGE_LEAF) {
367 print STDERR "found leaf page at $off\n" if $dbf->{debug};
368 (my $x, my $nent, $ret{next}) = 383 (my $x, my $nent, $ret{next}) =
369 unpack('LLL', $s); 384 unpack('LLL', $s);
385 print STDERR "found leaf page at $off, has $nent entries\n"
386 if $dbf->{debug};
370 my ($x1, $x2, $x3, @a) = unpack("LLL(LLLa2L/a)$nent", $s); 387 my ($x1, $x2, $x3, @a) = unpack("LLL(LLLa2L/a)$nent", $s);
371 for (my $i = 0; $i < $nent; $i += 5) { 388 for (my $i = 0; $i < $nent; $i += 5) {
372 push @{$ret{tab}}, [ @a[$i .. $i+3], thaw $a[$i+4] ]; 389 push @{$ret{tab}}, [ @a[$i .. $i+3], thaw $a[$i+4] ];
@@ -555,21 +572,6 @@ sub ipdb_insert {
555 $page = $p; 572 $page = $p;
556 } 573 }
557 574
558 my $maxent = int(($dbf->{pagesize} - 12) / 14);
559
560 while ($#{$page->{tab}} == $maxent) {
561 if ($page->{next}) {
562 $page = ipdb_cache_get($dbf, $page->{next});
563 croak "$dbf->{filename}: index page found where leaf was expected"
564 unless $page->{type} == IPDB_PAGE_LEAF;
565 } else {
566 my $p = ipdb_alloc_page($dbf, IPDB_PAGE_LEAF);
567 $page->{next} = $p->{off};
568 $page->{dirty} = 1;
569 $page = $p;
570 }
571 }
572
573 push @{$page->{tab}}, [ $ipn, $netmask, time(), $country, \%_ ]; 575 push @{$page->{tab}}, [ $ipn, $netmask, time(), $country, \%_ ];
574 $page->{dirty} = 1; 576 $page->{dirty} = 1;
575 577

Return to:

Send suggestions and report system problems to the System administrator.