From: tabris Date: Sat, 25 Jun 2011 17:38:53 +0000 (+0000) Subject: minor cleanups of the tor code X-Git-Url: https://jfr.im/git/irc/SurrealServices/srsv.git/commitdiff_plain/b6cdbd26838d8508c34ef03ee1f152875063eb35 minor cleanups of the tor code also put update_tor_list() into InParent The TOR code leaks... but I can't find anything actually wrong, so I think it is just a Perl problem, not an oversight in the TOR code. Perl's malloc sucks anyway. git-svn-id: http://svn.tabris.net/repos/srsv@3526 70d4eda1-72e9-0310-a436-91e5bd24443c --- diff --git a/branches/0.4.3/SrSv/TOR.pm b/branches/0.4.3/SrSv/TOR.pm index e5137d5e..773bc828 100644 --- a/branches/0.4.3/SrSv/TOR.pm +++ b/branches/0.4.3/SrSv/TOR.pm @@ -33,10 +33,13 @@ sub openURI($) { my ($URI) = @_; my $fh; if($URI =~ s/^file:\/\///i) { - open($fh, '<', $URI) or die; + use IO::File; + $fh = IO::File->new($URI, 'r') or die; } else { # assume HTTP/FTP URI - open($fh, '-|', ('wget -q -O - ' . $URI)) or die; + use IO::Pipe; + $fh = IO::Pipe->new(); + $fh->reader(qq(wget -q -O - $URI)) or die; } return $fh; } @@ -55,8 +58,7 @@ BEGIN { sub parseTorRouterList($) { my ($fh) = @_; our (%currentRouter, @routerList); - our $l; - while ($l = <$fh>) { + foreach my $l (<$fh>) { my ($tok, undef) = split(' ', $l, 2); #print "$l"; chomp $l; @@ -65,12 +67,14 @@ sub parseTorRouterList($) { } } sub TOR_r { + my ($l) = @_; #r atari i2i65Qm8DXfRpHVk6N0tcT0fxvs djULF2FbASFyIzuSpH1Zit9cYFc 2007-10-07 00:19:17 85.31.187.200 9001 9030 my (undef, $name, undef, undef, undef, $ip, $in_port, $dir_port) = split(' ', $l); %currentRouter = ( NAME => $name, IP => $ip, IN_PORT => $in_port, DIR_PORT => $dir_port ); return; } sub TOR_s { + my ($l) = @_; if($l =~ /^s (.*)/) { #s Exit Fast Guard Stable Running V2Dir Valid my $tokens = $1; @@ -81,22 +85,25 @@ sub parseTorRouterList($) { } } sub TOR_router { + my ($l) = @_; my (undef, $name, $ip, $in_port, undef, $dir_port) = split(' ', $l); push @routerList, processTorRouter(%currentRouter) if scalar(%currentRouter); %currentRouter = ( NAME => $name, IP => $ip, IN_PORT => $in_port, DIR_PORT => $dir_port ); return; } sub TOR_reject { + my ($l) = @_; my ($tok, $tuple) = split(' ', $l); my ($ip, $ports) = split(':', $tuple); push @{$currentRouter{REJECT}}, "$ip:$ports"; } sub TOR_accept { + my ($l) = @_; my ($tok, $tuple) = split(' ', $l); my ($ip, $ports) = split(':', $tuple); push @{$currentRouter{ACCEPT}}, "$ip:$ports"; } - close $fh; + #close $fh; return @routerList; } diff --git a/branches/0.4.3/modules/securitybot.pm b/branches/0.4.3/modules/securitybot.pm index 9bdb5592..c2b8e6f6 100644 --- a/branches/0.4.3/modules/securitybot.pm +++ b/branches/0.4.3/modules/securitybot.pm @@ -34,7 +34,7 @@ use SrSv::MySQL::Glob; use SrSv::Shared qw(%conf %torip %unwhois); -use SrSv::Process::InParent qw(list_conf loadconf saveconf); +use SrSv::Process::InParent qw(list_conf loadconf saveconf update_tor_list); use SrSv::TOR;