… | |
… | |
43 | Creates a listener on the given host/port using |
43 | Creates a listener on the given host/port using |
44 | C<AnyEvent::Socket::tcp_server>. |
44 | C<AnyEvent::Socket::tcp_server>. |
45 | |
45 | |
46 | See C<new>, below, for constructor arguments. |
46 | See C<new>, below, for constructor arguments. |
47 | |
47 | |
48 | Defaults for peerhost, peerport, fh and tls are provided. |
48 | Defaults for peerhost, peerport and fh are provided. |
49 | |
49 | |
50 | =cut |
50 | =cut |
51 | |
51 | |
52 | sub mp_server($$@) { |
52 | sub mp_server($$@) { |
53 | my $cb = pop; |
53 | my $cb = pop; |
… | |
… | |
58 | |
58 | |
59 | $cb->(new AnyEvent::MP::Transport |
59 | $cb->(new AnyEvent::MP::Transport |
60 | fh => $fh, |
60 | fh => $fh, |
61 | peerhost => $host, |
61 | peerhost => $host, |
62 | peerport => $port, |
62 | peerport => $port, |
63 | tls => "accept", |
|
|
64 | @args, |
63 | @args, |
65 | ); |
64 | ); |
66 | } |
65 | } |
67 | } |
66 | } |
68 | |
67 | |
… | |
… | |
82 | $cb->(new AnyEvent::MP::Transport |
81 | $cb->(new AnyEvent::MP::Transport |
83 | fh => $fh, |
82 | fh => $fh, |
84 | peername => $host, |
83 | peername => $host, |
85 | peerhost => $nhost, |
84 | peerhost => $nhost, |
86 | peerport => $nport, |
85 | peerport => $nport, |
87 | tls => "accept", |
|
|
88 | @args, |
86 | @args, |
89 | ); |
87 | ); |
90 | } |
88 | } |
91 | } |
89 | } |
92 | |
90 | |
… | |
… | |
105 | on_eof => sub { clean-close-callback }, |
103 | on_eof => sub { clean-close-callback }, |
106 | on_connect => sub { successful-connect-callback }, |
104 | on_connect => sub { successful-connect-callback }, |
107 | greeting => { key => value }, |
105 | greeting => { key => value }, |
108 | |
106 | |
109 | # tls support |
107 | # tls support |
110 | tls => "accept|connect", |
|
|
111 | tls_ctx => AnyEvent::TLS, |
108 | tls_ctx => AnyEvent::TLS, |
112 | peername => $peername, # for verification |
109 | peername => $peername, # for verification |
113 | ; |
110 | ; |
114 | |
111 | |
115 | =cut |
112 | =cut |
… | |
… | |
129 | $self->{queue} = []; |
126 | $self->{queue} = []; |
130 | |
127 | |
131 | { |
128 | { |
132 | Scalar::Util::weaken (my $self = $self); |
129 | Scalar::Util::weaken (my $self = $self); |
133 | |
130 | |
134 | if (exists $arg{connect}) { |
|
|
135 | $arg{tls_ctx} ||= { sslv2 => 0, sslv3 => 0, tlsv1 => 1, verify => 1 }; |
131 | #$arg{tls_ctx} ||= { sslv2 => 0, sslv3 => 0, tlsv1 => 1, verify => 1 }; |
136 | } |
|
|
137 | |
132 | |
138 | $arg{secret} = AnyEvent::MP::Base::default_secret () |
133 | $arg{secret} = AnyEvent::MP::Base::default_secret () |
139 | unless exists $arg{secret}; |
134 | unless exists $arg{secret}; |
140 | |
135 | |
141 | $self->{hdl} = new AnyEvent::Handle |
136 | $self->{hdl} = new AnyEvent::Handle |
… | |
… | |
213 | |
208 | |
214 | # read nonce |
209 | # read nonce |
215 | $self->{hdl}->push_read (line => sub { |
210 | $self->{hdl}->push_read (line => sub { |
216 | my $rgreeting2 = $_[1]; |
211 | my $rgreeting2 = $_[1]; |
217 | |
212 | |
218 | if ($self->{tls_ctx} and 1 == int $self->{remote_greeting}{"tls"}) { |
213 | if ($self->{tls_ctx} and 1 == int $self->{remote_greeting}{tls}) { |
219 | $self->{tls} = $lgreeting2 lt $rgreeting2 ? "connect" : "accept"; |
214 | $self->{tls} = $lgreeting2 lt $rgreeting2 ? "connect" : "accept"; |
220 | $self->{hdl}->starttls ($self->{tls}, $self->{tls_ctx}); |
215 | $self->{hdl}->starttls ($self->{tls}, $self->{tls_ctx}); |
221 | } |
216 | } |
222 | |
217 | |
223 | # auth |
218 | # auth |
… | |
… | |
366 | |
361 | |
367 | A comma-separated list of packet encoding/framign formats understood. The |
362 | A comma-separated list of packet encoding/framign formats understood. The |
368 | receiving side should choose the first framing format it supports for |
363 | receiving side should choose the first framing format it supports for |
369 | sending packets (which might be different from the format it has to accept). |
364 | sending packets (which might be different from the format it has to accept). |
370 | |
365 | |
371 | =cut |
366 | =back |
372 | |
367 | |
373 | The remaining arguments are C<KEY=VALUE> pairs. The following key-value |
368 | The remaining arguments are C<KEY=VALUE> pairs. The following key-value |
374 | pairs are known at this time: |
369 | pairs are known at this time: |
375 | |
370 | |
376 | =over 4 |
371 | =over 4 |
… | |
… | |
439 | =back |
434 | =back |
440 | |
435 | |
441 | Example (the actual reply matching the previous example): |
436 | Example (the actual reply matching the previous example): |
442 | |
437 | |
443 | hmac_md6_64_256;wIlLedBY956UCGSISG9mBZRDTG8xUi73/sVse2DSQp0;json |
438 | hmac_md6_64_256;wIlLedBY956UCGSISG9mBZRDTG8xUi73/sVse2DSQp0;json |
444 | |
|
|
445 | |
439 | |
446 | =head2 DATA PHASE |
440 | =head2 DATA PHASE |
447 | |
441 | |
448 | After this, packets get exchanged using the chosen framing protocol. It is |
442 | After this, packets get exchanged using the chosen framing protocol. It is |
449 | quite possible that both sides use a different framing protocol. |
443 | quite possible that both sides use a different framing protocol. |