20 |
|
|
21 |
my $listen_port = 4444; |
my $listen_port = 4444; |
22 |
|
|
23 |
my $node_path = '/tmp/client.pl'; |
my $node_path = $0; |
24 |
|
$node_path =~ s{server.pl}{client.pl}; |
25 |
|
|
26 |
my $lsn = IO::Socket::INET->new(Listen => 1, LocalPort => $listen_port, Reuse => 1) or die $!; |
my $lsn = IO::Socket::INET->new(Listen => 1, LocalPort => $listen_port, Reuse => 1) or die $!; |
27 |
my $sel = IO::Select->new($lsn); |
my $sel = IO::Select->new($lsn); |
54 |
my $node_port = 4000; |
my $node_port = 4000; |
55 |
|
|
56 |
foreach my $host ( @cloud ) { |
foreach my $host ( @cloud ) { |
57 |
system "echo $node_path | cpio --create --dereference | ssh -T -F $cloud_path.ssh $host cpio --extract --make-directories --unconditional"; |
system "echo $node_path | cpio --create --dereference | ssh -T -F $cloud_path.ssh $host cpio --extract --make-directories --unconditional --verbose"; |
58 |
fork_node( $node_port++, $host ); |
fork_node( $node_port++, $host ); |
59 |
} |
} |
60 |
|
|
65 |
if ($sock == $lsn) { |
if ($sock == $lsn) { |
66 |
my $new = $lsn->accept; |
my $new = $lsn->accept; |
67 |
$sel->add($new); |
$sel->add($new); |
68 |
$session->{$new} = $new->peerport; |
$session->{peerport}->{ $new->peerport } = $new; |
69 |
warn "[socket] connect\n"; |
warn "[socket] connect\n"; |
70 |
Storable::store_fd( { ping => 1 }, $new ); |
Storable::store_fd( { ping => 1 }, $new ); |
71 |
info 0 => 'ping', $new->peerport; |
info 0 => 'ping', $new->peerport; |
79 |
} else { |
} else { |
80 |
warn "<<<< ", dump($data), $/; |
warn "<<<< ", dump($data), $/; |
81 |
if ( $data->{repl} ) { |
if ( $data->{repl} ) { |
82 |
my $response = { repl => $$, info => $info }; |
my $response = { repl => $$ }; |
83 |
|
if ( $data->{repl} =~ m/ping/ ) { |
84 |
|
foreach my $port ( keys %{ $session->{port} } ) { |
85 |
|
warn ">>>> [$port]\n"; |
86 |
|
Storable::store_fd( { ping => 1 }, $session->{port}->{$port} ); |
87 |
|
} |
88 |
|
} elsif ( $data->{repl} =~ m/info/ ) { |
89 |
|
$response->{info} = $info; |
90 |
|
} |
91 |
Storable::store_fd( $response, $sock ); |
Storable::store_fd( $response, $sock ); |
92 |
} elsif ( $data->{ping} ) { |
} elsif ( $data->{ping} ) { |
93 |
$info->{_peer_port}->{$sock->peerport} = $data->{port}; |
my $port = $data->{port}; |
94 |
info $data->{port} => 'peer port', $sock->peerport; |
info $port => 'ping', $port; |
95 |
|
$session->{port}->{ $data->{port} } = $sock; |
96 |
} |
} |
97 |
} |
} |
98 |
} |
} |