… | |
… | |
273 | network, often the same string as used for the C<binds> parameter of the |
273 | network, often the same string as used for the C<binds> parameter of the |
274 | other node. The need for seeds is easy to explain: I<somehow> the nodes |
274 | other node. The need for seeds is easy to explain: I<somehow> the nodes |
275 | of an aemp network have to find each other, and often this means over the |
275 | of an aemp network have to find each other, and often this means over the |
276 | internet. So broadcasts are out. |
276 | internet. So broadcasts are out. |
277 | |
277 | |
278 | Instead, a node usually specifies the addresses of a few (for redundancy) |
278 | Instead, a node usually specifies the addresses of one or few (for |
279 | other nodes, some of which should be up. Two nodes can set each other as |
279 | redundancy) other nodes, some of which should be up. Two nodes can set |
280 | seeds without any issues. You could even specify all nodes as seeds for |
280 | each other as seeds without any issues. You could even specify all nodes |
281 | all nodes, for total redundancy. But the common case is to have some more |
281 | as seeds for all nodes, for total redundancy. But the common case is to |
282 | or less central, stable servers running seed services for other nodes. |
282 | have some more or less central, stable servers running seed services for |
|
|
283 | other nodes. |
283 | |
284 | |
284 | All you need to do to ensure that an AnyEvent::MP network connects |
285 | All you need to do to ensure that an AnyEvent::MP network connects |
285 | together is to make sure that all seed nodes are connected together via |
286 | together is to make sure that all seed nodes are connected together via |
286 | their seed connections, i.e., all connections from seed nodes to I<their> |
287 | their seed connections, i.e., all connections from seed nodes to I<their> |
287 | seed nodes form a connected graph. It's not necessary (but common) for a |
288 | seed nodes form a connected graph. |
288 | seed node to list all other seed nodes as seeds. The rest of the nodes in |
|
|
289 | the network simply specify one or more of the seed nodes in their seed |
|
|
290 | list. |
|
|
291 | |
|
|
292 | The simplest way to do that would be for all nodes to specify a single |
|
|
293 | node as seed node, and you would get a star topology. If you specify all |
|
|
294 | nodes as seed nodes, you get a fully meshed network (that's what previous |
|
|
295 | releases of AnyEvent::MP actually did). |
|
|
296 | |
289 | |
297 | A node tries to keep connections open to all of it's seed nodes at all |
290 | A node tries to keep connections open to all of it's seed nodes at all |
298 | times, while other connections are made on demand only. |
291 | times, while other connections are made on demand only. |
|
|
292 | |
|
|
293 | The simplest way to do that would be for all nodes to use the same seed |
|
|
294 | nodes: seed nodes would seed each other, and all other nodes would connect |
|
|
295 | to the seed nodes. |
299 | |
296 | |
300 | All of this ensures that the network stays one network - even if all the |
297 | All of this ensures that the network stays one network - even if all the |
301 | nodes in one half of the net are separated from the nodes in the other |
298 | nodes in one half of the net are separated from the nodes in the other |
302 | half by some network problem, once that is over, they will eventually |
299 | half by some network problem, once that is over, they will eventually |
303 | become a single network again. |
300 | become a single network again. |
… | |
… | |
670 | Without further ado, here is the chat server (to run it, we assume the |
667 | Without further ado, here is the chat server (to run it, we assume the |
671 | set-up explained earlier, with a separate F<aemp run seed> node): |
668 | set-up explained earlier, with a separate F<aemp run seed> node): |
672 | |
669 | |
673 | use common::sense; |
670 | use common::sense; |
674 | use AnyEvent::MP; |
671 | use AnyEvent::MP; |
675 | use AnyEvent::MP::Global; |
|
|
676 | |
672 | |
677 | configure; |
673 | configure; |
678 | |
674 | |
679 | my %clients; |
675 | my %clients; |
680 | |
676 | |
… | |
… | |
984 | new function, C<spawn>: |
980 | new function, C<spawn>: |
985 | #todo# |
981 | #todo# |
986 | |
982 | |
987 | use common::sense; |
983 | use common::sense; |
988 | use AnyEvent::MP; |
984 | use AnyEvent::MP; |
989 | use AnyEvent::MP::Global; |
|
|
990 | |
985 | |
991 | my $nick = shift; |
986 | my $nick = shift; |
992 | |
987 | |
993 | configure; |
988 | configure; |
994 | |
989 | |