… | |
… | |
161 | my (undef, $iaddr) = unpack_sockaddr_in $peername |
161 | my (undef, $iaddr) = unpack_sockaddr_in $peername |
162 | or $self->err(500, "unable to decode peername"); |
162 | or $self->err(500, "unable to decode peername"); |
163 | |
163 | |
164 | $self->{remote_addr} = |
164 | $self->{remote_addr} = |
165 | $self->{remote_id} = inet_ntoa $iaddr; |
165 | $self->{remote_id} = inet_ntoa $iaddr; |
|
|
166 | |
166 | $self->{time} = $::NOW; |
167 | $self->{time} = $::NOW; |
167 | |
168 | |
168 | weaken ($Coro::current->{conn} = $self); |
169 | weaken ($Coro::current->{conn} = $self); |
169 | |
170 | |
170 | $::conns++; |
171 | $::conns++; |
… | |
… | |
448 | } |
449 | } |
449 | } |
450 | } |
450 | } elsif (-f _ && -r _) { |
451 | } elsif (-f _ && -r _) { |
451 | -x _ and $self->err(403, "forbidden"); |
452 | -x _ and $self->err(403, "forbidden"); |
452 | |
453 | |
453 | if (%{$conn{$self->{remote_id}}} > $::MAX_TRANSFERS_IP) { |
454 | if (keys %{$conn{$self->{remote_id}}} > $::MAX_TRANSFERS_IP) { |
454 | my $timeout = $::NOW + 10; |
455 | my $timeout = $::NOW + 10; |
455 | while (%{$conn{$self->{remote_id}}} > $::MAX_TRANSFERS_IP) { |
456 | while (keys %{$conn{$self->{remote_id}}} > $::MAX_TRANSFERS_IP) { |
456 | if ($timeout < $::NOW) { |
457 | if ($timeout < $::NOW) { |
457 | $self->block($::BLOCKTIME, "too many connections"); |
458 | $self->block($::BLOCKTIME, "too many connections"); |
458 | } else { |
459 | } else { |
459 | $httpevent->wait; |
460 | $httpevent->wait; |
460 | } |
461 | } |
… | |
… | |
509 | |
510 | |
510 | satisfiable: |
511 | satisfiable: |
511 | # check for segmented downloads |
512 | # check for segmented downloads |
512 | if ($l && $::NO_SEGMENTED) { |
513 | if ($l && $::NO_SEGMENTED) { |
513 | my $timeout = $::NOW + 15; |
514 | my $timeout = $::NOW + 15; |
514 | while (%{$uri{$self->{remote_id}}{$self->{uri}}} > 1) { |
515 | while (keys %{$uri{$self->{remote_id}}{$self->{uri}}} > 1) { |
515 | if ($timeout <= $::NOW) { |
516 | if ($timeout <= $::NOW) { |
516 | $self->block($::BLOCKTIME, "segmented downloads are forbidden"); |
517 | $self->block($::BLOCKTIME, "segmented downloads are forbidden"); |
517 | #$self->err_segmented_download; |
518 | #$self->err_segmented_download; |
518 | } else { |
519 | } else { |
519 | $httpevent->wait; |
520 | $httpevent->wait; |
… | |
… | |
566 | } |
567 | } |
567 | } |
568 | } |
568 | |
569 | |
569 | if ($blocked{$self->{remote_id}}) { |
570 | if ($blocked{$self->{remote_id}}) { |
570 | $self->{h}{connection} = "close"; |
571 | $self->{h}{connection} = "close"; |
571 | die bless {}, err:: |
572 | die bless {}, err::; |
572 | } |
573 | } |
573 | |
574 | |
574 | if (0) { # !AIO |
575 | if (0) { # !AIO |
575 | sysread $fh, $buf, $h > $bufsize ? $bufsize : $h |
576 | sysread $fh, $buf, $h > $bufsize ? $bufsize : $h |
576 | or last; |
577 | or last; |