| 1 | package Tak::ConnectorService; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | ▶ | use IPC::Open2; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use IO::Socket::UNIX; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use IO::Socket::INET; # Sucks to be v6, see comment where used | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 1 | ▶ | use IO::All; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | ▶ | use Tak::Router; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 1 | ▶ | use Tak::Client; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 1 | ▶ | use Tak::ConnectionService; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 1 | ▶ | use Net::OpenSSH; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 1 | ▶ | use Tak::STDIONode; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 1 | ▶ | use Moo; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 1 | with 'Tak::Role::Service'; | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 0 | ▶ | has connections => (is => 'ro', default => sub { Tak::Router->new }); | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 0 | ▶ | has ssh => (is => 'ro', default => sub { {} }); | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | sub handle_create { | ||||||||||||||||||||
| 21 | 0 | ▶ | my ($self, $on, %args) = @_; | ||||||||||||||||||
|
Subroutine
handle_create: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||
| 22 | 0 | ▶ | die [ mistake => "No target supplied to create" ] unless $on; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 23 | 0 | ▶ | my $log_level = $args{log_level}||'info'; | ||||||||||||||||||
|
Condition0%0/2
$args{'log_level'} || 'info'
MC/DC0%0/1
$args{'log_level'} || 'info'
$args{'log_level'}
Truth table0%0/2
A
A= $args{'log_level'}
| |||||||||||||||||||||
| 24 | 0 | my ($kid_in, $kid_out, $kid_pid) = $self->_open($on, $log_level); | |||||||||||||||||||
| 25 | 0 | ▶ | if ($kid_pid) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 26 | 0 | ▶ | $kid_in->print($Tak::STDIONode::DATA, "__END__\n") unless $on eq '-'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 27 | # Need to get a handshake to indicate STDIOSetup has finished | ||||||||||||||||||||
| 28 | # messing around with file descriptors, otherwise we can severely | ||||||||||||||||||||
| 29 | # confuse things by sending before the dup. | ||||||||||||||||||||
| 30 | 0 | my $up = <$kid_out>; | |||||||||||||||||||
| 31 | 0 | ▶ | die [ failure => "Garbled response from child: $up" ] | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 32 | unless $up eq "Ssyshere\n"; | ||||||||||||||||||||
| 33 | } | ||||||||||||||||||||
| 34 | 0 | my $connection = Tak::ConnectionService->new( | |||||||||||||||||||
| 35 | read_fh => $kid_out, write_fh => $kid_in, | ||||||||||||||||||||
| 36 | listening_service => Tak::Router->new | ||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||
| 38 | 0 | my $client = Tak::Client->new(service => $connection); | |||||||||||||||||||
| 39 | # actually, we should register with a monotonic id and | ||||||||||||||||||||
| 40 | # stash the pid elsewhere. but meh for now. | ||||||||||||||||||||
| 41 | 0 | my $pid = $client->do(meta => 'pid'); | |||||||||||||||||||
| 42 | 0 | my $name = $on.':'.$pid; | |||||||||||||||||||
| 43 | 0 | my $conn_router = Tak::Router->new; | |||||||||||||||||||
| 44 | 0 | $conn_router->register(local => $connection->receiver->service); | |||||||||||||||||||
| 45 | 0 | $conn_router->register(remote => $connection); | |||||||||||||||||||
| 46 | 0 | $self->connections->register($name, $conn_router); | |||||||||||||||||||
| 47 | 0 | return ($name); | |||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | sub _open { | ||||||||||||||||||||
| 51 | 0 | ▶ | my ($self, $on, @args) = @_; | ||||||||||||||||||
|
Subroutine
_open: not called CC=9 SCAR=45.0
| |||||||||||||||||||||
| 52 | 0 | ▶ | if ($on eq '-') { | ||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||
| 53 | 0 | ▶ | my $kid_pid = IPC::Open2::open2(my $kid_out, my $kid_in, 'tak-stdio-node', '-', @args) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 54 | or die "Couldn't open2 child: $!"; | ||||||||||||||||||||
| 55 | 0 | return ($kid_in, $kid_out, $kid_pid); | |||||||||||||||||||
| 56 | } elsif ($on =~ /^\.?\//) { # ./foo or /foo | ||||||||||||||||||||
| 57 | 0 | ▶ | my $sock = IO::Socket::UNIX->new($on) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 58 | or die "Couldn't open unix domain socket ${on}: $!"; | ||||||||||||||||||||
| 59 | 0 | return ($sock, $sock, undef); | |||||||||||||||||||
| 60 | } elsif ($on =~ /:/) { # foo:80 we hope | ||||||||||||||||||||
| 61 | # IO::Socket::IP is a better answer. But can pull in XS deps. | ||||||||||||||||||||
| 62 | # Well, more strictly it pulls in Socket::GetAddrInfo, which can | ||||||||||||||||||||
| 63 | # actually work without its XS implementation (just doesn't handle v6) | ||||||||||||||||||||
| 64 | # and I've not properly pondered how to make things like fatpacking | ||||||||||||||||||||
| 65 | # Just Fucking Work in such a circumstance. First person to need IPv6 | ||||||||||||||||||||
| 66 | # and be reading this comment, please start a conversation about it. | ||||||||||||||||||||
| 67 | 0 | ▶ | my $sock = IO::Socket::INET->new(PeerAddr => $on) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 68 | or die "Couldn't open TCP socket ${on}: $!"; | ||||||||||||||||||||
| 69 | 0 | return ($sock, $sock, undef); | |||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | 0 | ▶ | my $ssh = $self->ssh->{$on} ||= Net::OpenSSH->new($on); | ||||||||||||||||||
|
Condition0%0/3
$self->ssh->{$on} ||= "Net::OpenSSH"->new($on)
MC/DC0%0/2
$self->ssh->{$on} ||= "Net::OpenSSH"->new($on)
$self->ssh->{$on}
"Net::OpenSSH"->new($on)
Truth table0%0/3
A ||= B
A= $self->ssh->{$on}B= "Net::OpenSSH"->new($on)
| |||||||||||||||||||||
| 72 | 0 | ▶ | $ssh->error and | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 73 | die "Couldn't establish ssh connection: ".$ssh->error; | ||||||||||||||||||||
| 74 | 0 | return $ssh->open2('perl','-', $on, @args); | |||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | sub start_connection_request { | ||||||||||||||||||||
| 78 | 0 | ▶ | my ($self, $req, @payload) = @_;; | ||||||||||||||||||
|
Subroutine
start_connection_request: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 79 | 0 | $self->connections->start_request($req, @payload); | |||||||||||||||||||
| 80 | } | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | sub receive_connection { | ||||||||||||||||||||
| 83 | 0 | ▶ | my ($self, @payload) = @_; | ||||||||||||||||||
|
Subroutine
receive_connection: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 84 | 0 | $self->connections->receive(@payload); | |||||||||||||||||||
| 85 | } | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 1 | 1; | |||||||||||||||||||