Changeset 11941

Show
Ignore:
Timestamp:
05/19/08 00:11:10 (5 years ago)
Author:
daisuke
Message:

more fixes

Location:
lang/perl/Moobal/trunk/lib/Moobal
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Moobal/trunk/lib/Moobal/Component/BackendHTTP.pm

    r11937 r11941  
    66# 
    77 
    8 package Moobal::BackendHTTP; 
     8package Moobal::Component::BackendHTTP; 
    99use Moose; 
    1010 
    11 with 'Moobal::Role::SocketContainer'; 
     11extends 'Moobal::Component::HTTP'; 
    1212 
    1313# Moobal::Component::Proxy connection, or undef 
     
    254254 
    255255sub close { 
    256     my $self = shift; # Moobal::BackendHTTP 
     256    my $self = shift; # Moobal::Component::BackendHTTP 
    257257 
    258258    # OSX Gives EPIPE on bad connects, and doesn't fail the connect 
     
    286286# or set our generation if given a parameter 
    287287sub generation { 
    288     my Moobal::BackendHTTP $self = $_[0]; 
     288    my Moobal::Component::BackendHTTP $self = $_[0]; 
    289289    return $self->{generation} unless $_[1]; 
    290290    return $self->{generation} = $_[1]; 
     
    293293# return what ip and port combination we're using 
    294294sub ipport { 
    295     my Moobal::BackendHTTP $self = $_[0]; 
     295    my Moobal::Component::BackendHTTP $self = $_[0]; 
    296296    return $self->{ipport}; 
    297297} 
     
    299299# called to tell backend that the client has gone on to do something else now. 
    300300sub forget_client { 
    301     my Moobal::BackendHTTP $self = $_[0]; 
     301    my Moobal::Component::BackendHTTP $self = $_[0]; 
    302302    $self->{client} = undef; 
    303303} 
     
    307307# returns true if client assignment was accepted. 
    308308sub assign_client { 
    309     my $self = shift; # Moobal::BackendHTTP 
     309    my $self = shift; # Moobal::Component::BackendHTTP 
    310310    my Moobal::Component::Proxy $client = shift; 
    311311    return 0 if $self->{client}; 
     
    390390# it has an upload ready on disk 
    391391sub invoke_buffered_upload_mode { 
    392     my $self = shift; # Moobal::BackendHTTP 
     392    my $self = shift; # Moobal::Component::BackendHTTP 
    393393 
    394394    # so, we're receiving a buffered upload, we need to go ahead and 
     
    402402# Backend 
    403403sub event_write { 
    404     my $self = shift; # Moobal::BackendHTTP 
     404    my $self = shift; # Moobal::Component::BackendHTTP 
    405405    print "Backend $self is writeable!\n" if &Moobal::DEBUG >= 2; 
    406406 
     
    453453 
    454454sub verify_failure { 
    455     my $self = shift; # Moobal::BackendHTTP 
     455    my $self = shift; # Moobal::Component::BackendHTTP 
    456456    $NoVerify{$self->{ipport}} = time() + 60; 
    457457    $self->{reportto}->note_bad_backend_connect($self); 
     
    461461 
    462462sub event_read_waiting_options { # : void 
    463     my $self = shift; # Moobal::BackendHTTP 
     463    my $self = shift; # Moobal::Component::BackendHTTP 
    464464    if ($self->{content_length_remain}) { 
    465465        # the HTTP/1.1 spec says OPTIONS responses can have content-lengths, 
     
    488488 
    489489sub handle_response { # : void 
    490     my $self = shift; # Moobal::BackendHTTP 
     490    my $self = shift; # Moobal::Component::BackendHTTP 
    491491    my $hd = $self->{res_headers}; # Moobal::HTTPHeaders  
    492492    my $client = $self->{client}; # Moobal::Component::Proxy  
     
    607607 
    608608sub may_reproxy { 
    609     my $self = shift; # Moobal::BackendHTTP 
     609    my $self = shift; # Moobal::Component::BackendHTTP 
    610610    my $svc = $self->{service}; # Moobal::Service  
    611611    return 0 unless $svc; 
     
    615615# Backend 
    616616sub event_read { 
    617     my $self = shift; # Moobal::BackendHTTP 
     617    my $self = shift; # Moobal::Component::BackendHTTP 
    618618    print "Backend $self is readable!\n" if &Moobal::DEBUG >= 2; 
    619619 
     
    674674# if $initial is on, then don't increment use count 
    675675sub next_request { 
    676     my Moobal::BackendHTTP $self = $_[0]; 
     676    my Moobal::Component::BackendHTTP $self = $_[0]; 
    677677    my $initial = $_[1]; 
    678678 
     
    740740# Backend: bad connection to backend 
    741741sub event_err { 
    742     my $self = shift; # Moobal::BackendHTTP 
     742    my $self = shift; # Moobal::Component::BackendHTTP 
    743743 
    744744    # FIXME: we get this after backend is done reading and we disconnect, 
     
    771771# Backend 
    772772sub event_hup { 
    773     my $self = shift; # Moobal::BackendHTTP 
     773    my $self = shift; # Moobal::Component::BackendHTTP 
    774774    print "HANGUP for $self\n" if &Moobal::DEBUG; 
    775775    $self->close("after_hup"); 
     
    777777 
    778778sub as_string { 
    779     my $self = shift; # Moobal::BackendHTTP 
     779    my $self = shift; # Moobal::Component::BackendHTTP 
    780780 
    781781    my $ret = $self->SUPER::as_string; 
     
    797797sub die_gracefully { 
    798798    # see if we need to die 
    799     my $self = shift; # Moobal::BackendHTTP 
     799    my $self = shift; # Moobal::Component::BackendHTTP 
    800800    $self->close('graceful_death') if $self->state eq 'bored'; 
    801801} 
  • lang/perl/Moobal/trunk/lib/Moobal/Component/ClientHTTP.pm

    r11938 r11941  
    2626has 'put_fh' => ( 
    2727    is => 'rw', 
    28     isa => 'FileHandle', 
     28    isa => 'Maybe[FileHandle]', 
    2929); 
    3030 
     
    114114# one-time routing of new request to the right handlers 
    115115sub handle_request { 
    116     my Moobal::Component::ClientHTTP $self = shift; 
     116    my $self = shift; 
    117117    my $hd = $self->{req_headers}; 
    118118 
     
    123123 
    124124    # notify that we're about to serve 
    125     return if $self->{service}->run_hook('start_web_request',  $self); 
    126     return if $self->{service}->run_hook('start_http_request', $self); 
     125    return if $self->service->run_hook('start_web_request',  $self); 
     126    return if $self->service->run_hook('start_http_request', $self); 
    127127 
    128128    # GET/HEAD requests (local, from disk) 
  • lang/perl/Moobal/trunk/lib/Moobal/Component/HTTP.pm

    r11938 r11941  
    6969has 'post_sendfile_cb' => ( 
    7070    is => 'rw', 
    71     isa => 'CodeRef' 
     71    isa => 'Maybe[CodeRef]' 
    7272); 
    7373 
     
    8383has 'selector_svc' => ( 
    8484    is => 'rw' 
     85); 
     86 
     87has 'closed' => ( 
     88    is => 'rw', 
     89    isa => 'Bool', 
     90    default => 0 
    8591); 
    8692 
     
    129135 
    130136    # now pass up the line 
    131     $self->socket->close(@_); 
     137    $self->danga_socket->close(@_); 
    132138} 
    133139 
     
    235241    # NOTE: because we only speak 1.0 to clients they can't have 
    236242    # pipeline in a read that we haven't read yet. 
     243 
    237244    $self->watch_read(1); 
    238245    $self->watch_write(0); 
     
    313320 
    314321    my $postread = sub { 
    315         return if $self->{closed}; 
     322        return if $self->closed; 
    316323 
    317324        my $sent = Moobal::Socket::sendfile($self->{fd}, 
     
    428435    Moobal::AIO::aio_stat($file, sub { 
    429436        # client's gone anyway 
    430         return if $self->{closed}; 
     437        return if $self->closed; 
    431438        unless (-e _) { 
    432439            return if $self->{service}->run_hook('static_get_poststat_file_missing', $self); 
     
    515522 
    516523                # if client's gone, just close filehandle and abort 
    517                 if ($self->{closed}) { 
     524                if ($self->closed) { 
    518525                    CORE::close($rp_fh) if $rp_fh; 
    519526                    return; 
     
    583590            $remain--; 
    584591            $statinfo{$file} = $! ? [] : [ stat(_) ]; 
    585             return if $remain || $self->{closed}; 
     592            return if $remain || $self->closed; 
    586593            $self->_serve_request_multiple_poststat($hd, $dirbase, \@multiple_files, \%statinfo); 
    587594        }); 
     
    677684 
    678685            # if client's gone, just close filehandle and abort 
    679             if ($self->{closed}) { 
     686            if ($self->closed) { 
    680687                CORE::close($rp_fh) if $rp_fh; 
    681688                  return; 
     
    761768    # now see if it exists 
    762769    Moobal::AIO::aio_stat($fullpath, sub { 
    763         return if $self->{closed}; 
     770        return if $self->closed; 
    764771        return $self->try_index_files($hd, $res, $uri, $filepos + 1) unless -f _; 
    765772 
  • lang/perl/Moobal/trunk/lib/Moobal/Component/Proxy.pm

    r11937 r11941  
    1515has 'backend' => ( 
    1616    is => 'rw', 
    17     isa => 'Moobal::BackendHTTP' 
     17    isa => 'Moobal::Component::BackendHTTP' 
    1818); 
    1919 
    2020my @fields = ( 
    2121# use fields ( 
    22             'backend',             # Moobal::BackendHTTP object (or undef if disconnected) 
     22            'backend',             # Moobal::Component::BackendHTTP object (or undef if disconnected) 
    2323            'backend_requested',   # true if we've requested a backend for this request 
    2424            'reconnect_count',     # number of times we've tried to reconnect to backend 
     
    197197sub too_far_behind_backend { 
    198198    my $self    = $_[0]; # Moobal::Component::Proxy  
    199     my $backend = $self->{backend}   or return 0; # Moobal::BackendHTTP  
     199    my $backend = $self->{backend}   or return 0; # Moobal::Component::BackendHTTP  
    200200 
    201201    # if a backend doesn't have a service, it's a 
     
    218218sub use_reproxy_backend { 
    219219    my $self = $_[0]; # Moobal::Component::Proxy  
    220     my $be = $_[1]; # Moobal::BackendHTTP  
     220    my $be = $_[1]; # Moobal::Component::BackendHTTP  
    221221 
    222222    # get a URI 
     
    255255sub backend_response_received { 
    256256    my $self = $_[0]; # Moobal::Component::Proxy  
    257     my $be = $_[1]; # Moobal::BackendHTTP  
     257    my $be = $_[1]; # Moobal::Component::BackendHTTP  
    258258 
    259259    # a response means that we are no longer currently waiting on a reproxy, and 
     
    406406sub backend_ready { 
    407407    my Moobal::Component::Proxy $self = $_[0]; 
    408     my Moobal::BackendHTTP $be = $_[1]; 
     408    my Moobal::Component::BackendHTTP $be = $_[1]; 
    409409 
    410410    # if we'd turned ourselves off while we waited for a backend, turn 
     
    10331033sub continue_buffered_upload { 
    10341034    my $self = shift; # Moobal::Component::Proxy  
    1035     my $be = shift; # Moobal::BackendHTTP  
     1035    my $be = shift; # Moobal::Component::BackendHTTP  
    10361036    return unless $self && $be; 
    10371037 
     
    11941194sub should_retry_after_500 { 
    11951195    my $self = shift; # Moobal::Component::Proxy  
    1196     my $be   = shift; # Moobal::BackendHTTP  
     1196    my $be   = shift; # Moobal::Component::BackendHTTP  
    11971197    my $svc = $be->{service}; 
    11981198    return 0 unless $svc->{enable_error_retries}; 
  • lang/perl/Moobal/trunk/lib/Moobal/HTTPHeaders.pm

    r11724 r11941  
    7878    $self->{type} = "httpres"; 
    7979 
    80     Moobal::objctor($self, $self->{type}); 
    8180    return $self; 
    8281} 
     
    101100    $self->{uri} = undef; 
    102101    $self->{type} = ($is_response ? "res" : "req"); 
    103     Moobal::objctor($self, $self->{type}); 
    104102 
    105103    # check request line 
     
    465463} 
    466464 
    467  
    468 sub DESTROY { 
    469     my Moobal::HTTPHeaders $self = shift; 
    470     Moobal::objdtor($self, $self->{type}); 
    471 } 
    472  
    4734651; 
    474466 
  • lang/perl/Moobal/trunk/lib/Moobal/Role/SocketHandler.pm

    r11932 r11941  
    1818    is => 'rw', 
    1919    isa => 'Danga::Socket', 
     20    handles => [ qw(watch_write watch_read peer_ip_string tcp_cork read) ] 
    2021); 
    2122 
     
    345346 
    346347    my $ret; 
    347     if ($ret = $self->SUPER::write(@_)) { 
     348    if ($ret = $self->danga_socket->write(@_)) { 
    348349        # Mark this socket alive so we don't time out 
    349350        $self->{alive_time} = $Moobal::tick_time; 
  • lang/perl/Moobal/trunk/lib/Moobal/Service.pm

    r11937 r11941  
    5555    does => 'Maybe[Moobal::Role::Listener]' 
    5656); 
     57 
     58has 'always_trusted' => ( 
     59    is => 'rw', 
     60    isa => 'Bool' 
     61); 
     62 
     63has 'trusted_upstream_proxies' => ( 
     64    is => 'rw', 
     65    isa => 'Maybe[Net::Netmask]' 
     66); 
     67 
    5768 
    5869sub enable { shift->enabled(1) } 
     
    130141    return 1; 
    131142} 
     143 
     144# called by BackendHTTP to ask if a client's IP is in our trusted list 
     145sub trusted_ip { 
     146    my $self = shift; # Moobal::Service 
     147    my $ip = shift; 
     148 
     149    return 1 if $self->always_trusted; 
     150 
     151    my $tmap = $self->trusted_upstream_proxies; 
     152    return 0 unless $tmap; 
     153 
     154    # try to use it as a Net::Netmask object 
     155    return 1 if eval { $tmap->match($ip); }; 
     156    return 0; 
     157} 
     158 
     159sub run_hook {} 
    132160 
    1331611; 
     
    896924} 
    897925 
    898 # called by BackendHTTP to ask if a client's IP is in our trusted list 
    899 sub trusted_ip { 
    900     my $self = shift; # Moobal::Service 
    901     my $ip = shift; 
    902  
    903     return 1 if $self->{'always_trusted'}; 
    904  
    905     my $tmap = $self->{trusted_upstream_proxies}; 
    906     return 0 unless $tmap; 
    907  
    908     # try to use it as a Net::Netmask object 
    909     return 1 if eval { $tmap->match($ip); }; 
    910     return 0; 
    911 } 
    912  
    913926# manage some header stuff 
    914927sub header_management {