Changeset 98

Show
Ignore:
Timestamp:
05/12/07 00:59:22 (3 years ago)
Author:
bradfitz
Message:

multiplexed slave iterator stuff.... you can start to see now how
the gpg encrypt-ahead-of-time stuff will work... we'll just keep
'n' copies/bytes/chunks encrypted ahead of time, if we're below
our limits, working off our separate iterators, which feed into each other....

Location:
trunk/lib/Brackup
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/Brackup/Backup.pm

    r97 r98  
    4848    my $chunk_iterator = Brackup::ChunkIterator->new(@files); 
    4949 
     50    my $gpg_iter; 
     51    if ($gpg_rcpt) { 
     52        ($chunk_iterator, $gpg_iter) = $chunk_iterator->mux_into(2); 
     53    } 
     54 
    5055    my $cur_file; # current (last seen) file 
    5156    my @stored_chunks; 
     
    6671                             $cur_file->path, $n_files_done, $n_files, ($n_kb_done/$n_kb)*100, 
    6772                             ($n_kb - $n_kb_done) / 1024)); 
     73 
     74        if ($gpg_iter) { 
     75            # catch our gpg iterator up.  we want it to be ahead of us, 
     76            # nothing iteresting is behind us. 
     77            $gpg_iter->next while $gpg_iter->behind_by > 1; 
     78        } 
    6879    }; 
    6980 
  • trunk/lib/Brackup/ChunkIterator.pm

    r95 r98  
    3131} 
    3232 
     33sub mux_into { 
     34    my ($self, $n_copies) = @_; 
     35    my @iters; 
     36    for (1..$n_copies) { 
     37        push @iters, Brackup::ChunkIterator::SlaveIterator->new; 
     38    } 
     39    my $on_empty = sub { 
     40        my $next = $self->next; 
     41        foreach my $peer (@iters) { 
     42            push @{$peer->{mag}}, $next; 
     43        } 
     44    }; 
     45    foreach (@iters) { 
     46        $_->{on_empty} = $on_empty; 
     47    } 
     48    return @iters; 
     49} 
     50 
     51package Brackup::ChunkIterator::SlaveIterator; 
     52use strict; 
     53use warnings; 
     54use Carp qw(croak); 
     55 
     56sub new { 
     57    my $class = shift; 
     58    return bless { 
     59        'on_empty' => undef, # subref 
     60        'mag'      => [], 
     61    }, $class; 
     62} 
     63 
     64sub next { 
     65    my $self = shift; 
     66    # the magazine itself could be true, but contain only undef: (undef), 
     67    # which signals the end. 
     68    return shift @{$self->{mag}} if @{$self->{mag}}; 
     69    $self->{on_empty}->(); 
     70    return shift @{$self->{mag}}; 
     71} 
     72 
     73sub behind_by { 
     74    my $self = shift; 
     75    return scalar @{$self->{mag}}; 
     76} 
     77 
    33781;