]> jfr.im git - irc/SurrealServices/srsv.git/commitdiff
minor cleanups of the tor code
authortabris <redacted>
Sat, 25 Jun 2011 17:38:53 +0000 (17:38 +0000)
committertabris <redacted>
Sat, 25 Jun 2011 17:38:53 +0000 (17:38 +0000)
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

branches/0.4.3/SrSv/TOR.pm
branches/0.4.3/modules/securitybot.pm

index e5137d5e4a30615e89901daab5a87f3693bcdd9e..773bc82803c67e5d0fc1aff2c3bd8edb0344c997 100644 (file)
@@ -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;
 }
 
index 9bdb5592ebff1037106d6a81b8115f10df9a1b5f..c2b8e6f68f875d26d6afcd44275ca1758d46c82b 100644 (file)
@@ -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;