File Coverage

blib/lib/Net/OSCAR/Callbacks/1/migrate.pm
Criterion Covered Total %
statement 10 10 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 14 100.0


line stmt bran cond sub pod time code
1             package Net::OSCAR::Callbacks;
2             BEGIN {
3 1     1   19 $Net::OSCAR::Callbacks::VERSION = '1.928';
4             }
5 1     1   5 use strict;
  1         2  
  1         22  
6 1     1   4 use warnings;
  1         2  
  1         26  
7 1     1   4 use vars qw($connection $snac $conntype $family $subtype $data $reqid $reqdata $session $protobit %data);
  1         1  
  1         500  
8             sub {
9              
10             # It looks like we get a blank family if the server sends
11             # no migration families (full migration.) Filter out
12             # this dummy entry.
13             my @migfamilies = grep { $_ != 0 } @{$data{families}};
14              
15             $connection->log_print(OSCAR_DBG_WARN, "Migration families received: ", join(" ", @migfamilies));
16             $session->loglevel(10);
17              
18             my $pause_queue;
19             if(@{$data{families}} == keys %{$connection->{families}} or @migfamilies == 0) {
20             $connection->log_print(OSCAR_DBG_WARN, "Full migration, disconnecting...");
21             $pause_queue = $connection->{pause_queue};
22              
23             # Don't let it think that we've lost the BOS connection
24             my $conntype = $connection->{conntype};
25             $connection->{conntype} = -1 if $connection->{conntype} == CONNTYPE_BOS;
26             $session->delconn($connection);
27             $connection->{conntype} = $conntype;
28              
29             $session->log_print(OSCAR_DBG_WARN, "Disconnected.");
30             } else {
31             $connection->log_print(OSCAR_DBG_WARN, "Partial migration");
32              
33             # Get the list of families which aren't being migrated
34             my @all_families = keys %{$connection->{families}};
35             $connection->{families} = {};
36             foreach my $fam (@all_families) {
37             next if grep { $_ == $fam } @migfamilies;
38             $connection->{families}->{$fam} = 1;
39             }
40              
41             # Filter the pause queue according to the migration split
42             my $all_pause_queue = $connection->{pause_queue};
43             $connection->{pause_queue} = [];
44             foreach my $item (@$all_pause_queue) {
45             if(grep { $item->{family} == $_ } @migfamilies) {
46             push @$pause_queue, $item;
47             } else {
48             push @{$connection->{pause_queue}}, $item;
49             }
50             }
51              
52             $connection->log_printf(OSCAR_DBG_WARN, "Migration pause queue: %d/%d", @{$pause_queue || []}, @{$connection->{pause_queue} || []});
53             }
54              
55             $session->log_print(OSCAR_DBG_WARN, "Creating new connection");
56             my $newconn = $session->addconn(
57             auth => $data{cookie},
58             conntype => $connection->{conntype},
59             description => $connection->{description},
60             peer => $data{peer},
61             paused => 1,
62             pause_queue => $pause_queue
63             );
64             $session->log_print(OSCAR_DBG_WARN, "Created.");
65              
66             };