summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Tanja.pm19
-rwxr-xr-xtest.pl2
2 files changed, 9 insertions, 12 deletions
diff --git a/Tanja.pm b/Tanja.pm
index 6dd29ab..ae04aaa 100644
--- a/Tanja.pm
+++ b/Tanja.pm
@@ -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(@_) });
diff --git a/test.pl b/test.pl
index 3d86748..bed74e0 100755
--- a/test.pl
+++ b/test.pl
@@ -121,7 +121,7 @@ sub t_double {
on_ready => sub { $done->end },
$DEBUG ? (on_write => sub { note 'A: ',Data::Dumper::Dumper(\@_) }) : (),
);
- $sb->link(AnyEvent::Handle->new(fh => $sockb), sync => $f&2, init => 1,
+ $sb->link(AnyEvent::Handle->new(fh => $sockb), sync => $f&2,
on_ready => sub { $done->end },
$DEBUG ? (on_write => sub { note 'B: ',Data::Dumper::Dumper(\@_) }) : (),
);