ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-MP/MP/Intro.pod
(Generate patch)

Comparing AnyEvent-MP/MP/Intro.pod (file contents):
Revision 1.24 by root, Sat Aug 29 15:13:36 2009 UTC vs.
Revision 1.25 by root, Sat Aug 29 15:36:06 2009 UTC

135and do interprocess message passing we first have to make sure some things 135and do interprocess message passing we first have to make sure some things
136have been set up correctly for our nodes to talk to each other. 136have been set up correctly for our nodes to talk to each other.
137 137
138=head1 System Requirements and System Setup 138=head1 System Requirements and System Setup
139 139
140Before we can start with real IPC we have to make sure some things work on your 140Before we can start with real IPC we have to make sure some things work on
141system. 141your system.
142 142
143First we have to setup a I<shared secret>: for two L<AnyEvent::MP> I<nodes> to 143First we have to setup a I<shared secret>: for two L<AnyEvent::MP>
144be able to communicate with each other and authenticate each other it is 144I<nodes> to be able to communicate with each other over the network it is
145necessary to setup the same I<shared secret> for both of them (or use TLS 145necessary to setup the same I<shared secret> for both of them, so they can
146certificates). 146prove their trustworthyness to each other.
147 147
148The easiest way is to set this up is to use the F<aemp> utility: 148The easiest way is to set this up is to use the F<aemp> utility:
149 149
150 aemp gensecret 150 aemp gensecret
151 151
152This creates a F<$HOME/.perl-anyevent-mp> config file and generates a random 152This creates a F<$HOME/.perl-anyevent-mp> config file and generates a
153shared secret. You can copy this file to any other system and then communicate 153random shared secret. You can copy this file to any other system and
154over the network (via TCP) with it. You can also select your own shared secret 154then communicate over the network (via TCP) with it. You can also select
155(F<aemp setsecret>) and for increased security requirements you can even create 155your own shared secret (F<aemp setsecret>) and for increased security
156a TLS certificate (F<aemp gencert>), causing connections to not just be 156requirements you can even create (or configure) a TLS certificate (F<aemp
157authenticated, but also to be encrypted. 157gencert>), causing connections to not just be securely authenticated, but
158also to be encrypted and protected against tinkering.
158 159
159Connections will only be successful when the I<nodes> that want to connect to 160Connections will only be successfully established when the I<nodes>
160each other have the same I<shared secret> (or successfully verify the TLS 161that want to connect to each other have the same I<shared secret> (or
161certificate of the other side). 162successfully verify the TLS certificate of the other side, in which case
163no shared secret is required).
162 164
163B<If something does not work as expected, and for example tcpdump shows 165B<If something does not work as expected, and for example tcpdump shows
164that the connections are closed almost immediately, you should make sure 166that the connections are closed almost immediately, you should make sure
165that F<~/.perl-anyevent-mp> is the same on all hosts/user accounts that 167that F<~/.perl-anyevent-mp> is the same on all hosts/user accounts that
166you try to connect with each other!> 168you try to connect with each other!>
167 169
168Thats all for now, there is more fiddling around with the C<aemp> utility 170Thats is all for now, you will find some more advanced fiddling with the
169later. 171C<aemp> utility later.
172
170 173
171=head1 Passing Messages Between Processes 174=head1 Passing Messages Between Processes
172 175
173=head2 The Receiver 176=head2 The Receiver
174 177
175Lets split the previous example up into two small programs. First the 178Lets split the previous example up into two programs: one that contains
176receiver application: 179the sender and one for the receiver. First the receiver application, in
180full:
177 181
178 #!/opt/perl/bin/perl
179 use AnyEvent; 182 use AnyEvent;
180 use AnyEvent::MP; 183 use AnyEvent::MP;
181 use AnyEvent::MP::Global; 184 use AnyEvent::MP::Global;
182 185
183 initialise_node "eg_simple_receiver"; 186 initialise_node "eg_simple_receiver";
194 197
195 AnyEvent->condvar->recv; 198 AnyEvent->condvar->recv;
196 199
197=head3 AnyEvent::MP::Global 200=head3 AnyEvent::MP::Global
198 201
199Now, that wasn't too bad, was it? Ok, lets step through the new functions 202Now, that wasn't too bad, was it? Ok, let's step through the new functions
200and modules that have been used. For starters there is now an additional 203and modules that have been used.
201module loaded: L<AnyEvent::MP::Global>.
202 204
203That module provides us with a I<global registry>, which lets us share data 205For starters, there is now an additional module being
204among all I<nodes> in a network. Why do we need it you might ask? 206used: L<AnyEvent::MP::Global>. This module provides us with a I<global
207registry>, which lets us register ports in groups that are visible on all
208I<nodes> in a network.
205 209
206The thing is, that the I<port ids> are just random strings, assigned by 210What is this useful for? Well, the I<port IDs> are random-looking strings,
207L<AnyEvent::MP>. We can't know those I<port ids> in advance, so we don't know 211assigned by L<AnyEvent::MP>. We cannot know those I<port IDs> in advance,
208which I<port id> to send messages to if the message is to be passed between 212so we don't know which I<port ID> to send messages to, especially when the
209I<nodes> (or UNIX processes). To find the right I<port> of another I<node> in 213message is to be passed between different I<nodes> (or UNIX processes). To
210the network we will need to communicate that somehow to the sender. And 214find the right I<port> of another I<node> in the network we will need
215to communicate this somehow to the sender. And exactly that is what
211exactly that is what L<AnyEvent::MP::Global> provides. 216L<AnyEvent::MP::Global> provides.
212 217
218Especially in larger, more anonymous networks this is handy: imagine you
219have a few database backends, a few web frontends and some processing
220distributed over a number of hosts: all of these would simply register
221themselves in the appropriate group, and your web frontends can start to
222find some database backend.
223
213=head3 initialise_node And The Network 224=head3 C<initialise_node> And The Network
214 225
215Now, lets have a look at the next new thing, the C<initialise_node>: 226Now, lets have a look at the next new thing, the C<initialise_node>:
216 227
217 initialise_node "eg_simple_receiver"; 228 initialise_node "eg_simple_receiver";
218 229

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines