X-Git-Url: http://dxcluster.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FRoute%2FNode.pm;h=4aa8be9ead142bdee079e45a11150d9f29a95d07;hb=a895f396222d99b306bbabe53dcb184131f7af2d;hp=02c8b341b2310f1d03c005aa3da6253879be4ba8;hpb=f6d0b05b25a61cb6d3aa671b7a8f5d4a69817b1c;p=spider.git diff --git a/perl/Route/Node.pm b/perl/Route/Node.pm index 02c8b341..4aa8be9e 100644 --- a/perl/Route/Node.pm +++ b/perl/Route/Node.pm @@ -12,6 +12,8 @@ use DXDebug; use Route; use Route::User; use DXUtil; +use DXJSON; +use Time::HiRes qw(gettimeofday); use strict; @@ -38,6 +40,7 @@ $filterdef = $Route::filterdef; %list = (); $max = 0; $obscount = 3; +our $cachefn = localdata('route_node_cache'); sub count { @@ -203,6 +206,14 @@ sub del_user return @out; } +# is a user on this node +sub is_user +{ + my $self = shift; + my $call = shift; + return scalar grep {$_ eq $call} @{$self->{users}}; +} + sub usercount { my $self = shift; @@ -384,6 +395,39 @@ sub PC92C_dxchan return (%{$parent->{PC92C_dxchan}}); } +sub TO_JSON { return { %{ shift() } }; } + +sub write_cache +{ + my $json = DXJSON->new; + $json->canonical(isdbg('routecache')); + + my $ta = [ gettimeofday ]; + my @s; + eval { + while (my ($k, $v) = each %list) { + push @s, "$k:" . $json->encode($v) . "\n"; + } + }; + if (!$@ && @s) { + my $fh = IO::File->new(">$cachefn") or confess("writing $cachefn $!"); + if (isdbg("routecache")) { + $fh->print(sort @s); + } + else { + $fh->print(@s); + } + $fh->close; + } else { + dbg("Route::Node:Write_cache error '$@'"); + return; + } + $json->indent(0)->canonical(0); + my $diff = _diffms($ta); + dbg("Route::Node:WRITE_CACHE time to write: $diff mS"); +} + + sub DESTROY { my $self = shift;