diff options
Diffstat (limited to 'Tanja.pm')
-rw-r--r-- | Tanja.pm | 19 |
1 files changed, 8 insertions, 11 deletions
@@ -189,7 +189,6 @@ use Carp 'croak'; # Args: Tanja::Server, AnyEvent::Handle, %options # Options: -# init => bool. True if the other party connected to us, false otherwise. (Default false) # sync => bool. True to fetch the other servers' patterns. (Default true) # on_error => $cb->($message). Called when an error occurs, $message = undef for disconnect. # on_ready => $cb->(). Called when the link is "ready". (i.e. if you send tuples they will be forwarded) @@ -200,7 +199,6 @@ sub new { require AnyEvent::Handle; croak 'No JSON module available.' if !Tanja::Link::JSON->init; my $s = bless { - init => 0, sync => 1, %o, serv => $serv, @@ -252,21 +250,20 @@ sub _write { sub _handshake { my $s = shift; - # If we should initiate the handshake, do so - $s->{init} && $s->{hdl}->push_write("ver,1.0 ser,json\012"); + # Send our handshake message + $s->{hdl}->push_write("ver,1.0 seri,json sero,json\012"); # Receive handshake from other party $s->{hdl}->push_read(line => "\012" => sub { my $ver = ($_[1] =~ /\bver,([^ ]+)\b/) && $1; - my $ser = ($_[1] =~ /\bser,([^ ]+)\b/) && $1; + my $seri = ($_[1] =~ /\bseri,([^ ]+)\b/) && $1; + my $sero = ($_[1] =~ /\bsero,([^ ]+)\b/) && $1; # Validate - $s->_err("Invalid handshake: $_[1]") if !$ver || !$ser - || ($s->{init} ? $ver ne '1.0' : !grep /^1\./, split /,/, $ver) - || ($s->{init} ? $ser ne 'json' : !grep $_ eq 'json', split /,/, $ser); - - # Reply with our handshake if we hadn't sent it yet. - !$s->{init} && $s->{hdl}->push_write("ver,1.0 ser,json\012"); + $s->_err("Invalid handshake: $_[1]") if !$ver or !$seri or !$sero + or !grep /^1\./, split /,/, $ver + or !grep $_ eq 'json', split /,/, $seri + or !grep $_ eq 'json', split /,/, $sero; # Handshake complete, start receiving stuff $s->{hdl}->push_read('Tanja::Link::JSON' => sub { $s->_recv(@_) }); |