=head1 NAME AnyEvent::MP::DataConn - create socket connections between nodes =head1 SYNOPSIS use AnyEvent::MP::DataConn; =head1 DESCRIPTION This module can be used to create socket connections between the local and a remote node in the aemp network. The socket can be used freely for any purpose, and in most cases, this mechanism is a good way to transport big chunks of binary data. The connections created by this module use the same security mechanisms as normal AEMP connections (secure authentication, optional use of TLS), and in fact, use the same listening port as AEMP connections, so when two nodes can reach each other, they can, with high probability, creare a data connection between them. The protocol is, however, not the AEMP transport protocol, so this will only work between nodes implementing the "aemp-dataconn" protocol. =head1 FUNCTIONS =over 4 =cut package AnyEvent::MP::DataConn; use common::sense; use Carp (); use POSIX (); use AnyEvent (); use AnyEvent::Util (); use AnyEvent::MP; use AnyEvent::MP::Kernel; sub _inject { my ($conn, $error) = @_; } =item AnyEvent::MP::DataConn::connect_to $node, $timeout, [$initfunc, @initdata], @localmsg Creates a socket connection between the local node and the node C<$node> (which can also be specified as a port). When the connection could be successfully created, the C<$initfunc> will be called with the given C<@initdata> on the remote node (similar to C or C), and the C object representing the connection as additional argument. Also, the local port in which context C was called (C<$SELF>) will receive a message with contents C<@localmsg>, again with the AnyEvent::Handle object tacked to the end. The AnyEvent::Handle object will be in a "quiescent" state - you could rip out the file handle and forget about it, but it is recommended to use it, as the security settings might have called for a TLS connection. IF you opt to use it, you at least have to set an C callback. In case of any error (or timeout), nothing will be called on the remote side, and the local port will be C'ed with an C<< AnyEvent::MP::DataConn => "error message" >> kill reason. =cut sub connect_to($$$;@) { my ($node, $timeout, $initspec, @localmsg) = @_; my $port = $SELF; $node = node_of $node; my %state; $state{to} = AE::timer $timeout, 0, sub { %state = (); kil $port, AnyEvent::MP::DataConn:: => "$node: unable to establish connection within $timeout seconds"; }; my $continue_connect = sub { use Data::Dumper; warn Dumper $NODE{$node};#d# }; if (port_is_local $node) { return kil $port, AnyEvent::MP::DataConn:: => "connect_to does not yet support local/local connections, please bug me about it"; } elsif (node_is_up $node) { $continue_connect->(); } else { $state{mon_nodes} = mon_nodes sub { return unless $_[0] eq $node && $_[1]; delete $state{mon_nodes}; $continue_connect->() }; } } =back =head1 SEE ALSO L. =head1 AUTHOR Marc Lehmann http://home.schmorp.de/ =cut 1