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