1 | package transferqueue; |
|
|
2 | |
|
|
3 | sub new { |
|
|
4 | my $class = shift; |
|
|
5 | bless { |
|
|
6 | conns => $_[0], |
|
|
7 | }, $class; |
|
|
8 | } |
|
|
9 | |
|
|
10 | sub start_transfer { |
|
|
11 | my $self = shift; |
|
|
12 | |
|
|
13 | my $trans = bless [ $self, $Coro::current ], transfer::; |
|
|
14 | print "$self $trans $trans->[0] <<\n";#d# |
|
|
15 | Scalar::Util::weaken($trans->[0]); |
|
|
16 | |
|
|
17 | push @{$self->{wait}}, $trans; |
|
|
18 | |
|
|
19 | if (--$self->{conns} >= 0) { |
|
|
20 | $self->wake_next; |
|
|
21 | } |
|
|
22 | |
|
|
23 | $trans; |
|
|
24 | } |
|
|
25 | |
|
|
26 | sub wake_next { |
|
|
27 | my $self = shift; |
|
|
28 | |
|
|
29 | return unless $self->{conns} >= 0; |
|
|
30 | |
|
|
31 | (pop @{$self->{wait}})->wake if @{$self->{wait}}; |
|
|
32 | } |
|
|
33 | |
|
|
34 | sub waiters { |
|
|
35 | map $_->[1], @{$_[0]{wait}}; |
|
|
36 | } |
|
|
37 | |
|
|
38 | package transfer; |
|
|
39 | |
|
|
40 | use Coro::Timer (); |
|
|
41 | |
|
|
42 | sub try { |
|
|
43 | my $self = shift; |
|
|
44 | my $timeout = Coro::Timer::timeout $_[0]; |
|
|
45 | |
|
|
46 | Coro::schedule; |
|
|
47 | |
|
|
48 | return $self->[2]; |
|
|
49 | } |
|
|
50 | |
|
|
51 | sub wake { |
|
|
52 | my $self = shift; |
|
|
53 | $self->[2] = 1; |
|
|
54 | $self->[1]->ready; |
|
|
55 | } |
|
|
56 | |
|
|
57 | sub DESTROY { |
|
|
58 | my $self = shift; |
|
|
59 | $self->[0]{conns}++; |
|
|
60 | $self->[0]->wake_next; |
|
|
61 | } |
|
|
62 | |
|
|
63 | package conn; |
1 | package conn; |
64 | |
2 | |
65 | our %blockuri; |
3 | our %blockuri; |
66 | our $blockref; |
4 | our $blockref; |
67 | |
5 | |
… | |
… | |
130 | my %disallow; |
68 | my %disallow; |
131 | |
69 | |
132 | $self->err_block_referer |
70 | $self->err_block_referer |
133 | if $self->{h}{referer} =~ $blockref; |
71 | if $self->{h}{referer} =~ $blockref; |
134 | |
72 | |
135 | my $whois = $whois_cache{$self->{remote_addr}} |
73 | my $ra = $self->{remote_addr}; |
136 | ||= netgeo::ip_request($self->{remote_addr}); |
74 | my $whois = $whois_cache{$ra} ||= netgeo::ip_request($ra); |
137 | |
75 | |
138 | my $country = "XX"; |
76 | my $country = "XX"; |
139 | |
77 | |
140 | if ($whois =~ /^\*cy: (\S+)/m) { |
78 | if ($whois =~ /^\*cy: (\S+)/m) { |
141 | $country = uc $1; |
79 | $country = uc $1; |