… | |
… | |
126 | identifiers become invalid. |
126 | identifiers become invalid. |
127 | |
127 | |
128 | =item $noderef = node_of $port |
128 | =item $noderef = node_of $port |
129 | |
129 | |
130 | Extracts and returns the noderef from a portid or a noderef. |
130 | Extracts and returns the noderef from a portid or a noderef. |
|
|
131 | |
|
|
132 | =item initialise_node $noderef, $seednode, $seednode... |
|
|
133 | |
|
|
134 | =item initialise_node "slave/", $master, $master... |
|
|
135 | |
|
|
136 | Before a node can talk to other nodes on the network it has to initialise |
|
|
137 | itself - the minimum a node needs to know is it's own name, and optionally |
|
|
138 | it should know the noderefs of some other nodes in the network. |
|
|
139 | |
|
|
140 | This function initialises a node - it must be called exactly once (or |
|
|
141 | never) before calling other AnyEvent::MP functions. |
|
|
142 | |
|
|
143 | All arguments are noderefs, which can be either resolved or unresolved. |
|
|
144 | |
|
|
145 | There are two types of networked nodes, public nodes and slave nodes: |
|
|
146 | |
|
|
147 | =over 4 |
|
|
148 | |
|
|
149 | =item public nodes |
|
|
150 | |
|
|
151 | For public nodes, C<$noderef> must either be a (possibly unresolved) |
|
|
152 | noderef, in which case it will be resolved, or C<undef> (or missing), in |
|
|
153 | which case the noderef will be guessed. |
|
|
154 | |
|
|
155 | Afterwards, the node will bind itself on all endpoints and try to connect |
|
|
156 | to all additional C<$seednodes> that are specified. Seednodes are optional |
|
|
157 | and can be used to quickly bootstrap the node into an existing network. |
|
|
158 | |
|
|
159 | =item slave nodes |
|
|
160 | |
|
|
161 | When the C<$noderef> is the special string C<slave/>, then the node will |
|
|
162 | become a slave node. Slave nodes cannot be contacted from outside and will |
|
|
163 | route most of their traffic to the master node that they attach to. |
|
|
164 | |
|
|
165 | At least one additional noderef is required: The node will try to connect |
|
|
166 | to all of them and will become a slave attached to the first node it can |
|
|
167 | successfully connect to. |
|
|
168 | |
|
|
169 | =back |
|
|
170 | |
|
|
171 | This function will block until all nodes have been resolved and, for slave |
|
|
172 | nodes, until it has successfully established a connection to a master |
|
|
173 | server. |
|
|
174 | |
|
|
175 | Example: become a public node listening on the default node. |
|
|
176 | |
|
|
177 | initialise_node; |
|
|
178 | |
|
|
179 | Example: become a public node, and try to contact some well-known master |
|
|
180 | servers to become part of the network. |
|
|
181 | |
|
|
182 | initialise_node undef, "master1", "master2"; |
|
|
183 | |
|
|
184 | Example: become a public node listening on port C<4041>. |
|
|
185 | |
|
|
186 | initialise_node 4041; |
|
|
187 | |
|
|
188 | Example: become a public node, only visible on localhost port 4044. |
|
|
189 | |
|
|
190 | initialise_node "locahost:4044"; |
|
|
191 | |
|
|
192 | Example: become a slave node to any of the specified master servers. |
|
|
193 | |
|
|
194 | initialise_node "slave/", "master1", "192.168.13.17", "mp.example.net"; |
131 | |
195 | |
132 | =item $cv = resolve_node $noderef |
196 | =item $cv = resolve_node $noderef |
133 | |
197 | |
134 | Takes an unresolved node reference that may contain hostnames and |
198 | Takes an unresolved node reference that may contain hostnames and |
135 | abbreviated IDs, resolves all of them and returns a resolved node |
199 | abbreviated IDs, resolves all of them and returns a resolved node |
… | |
… | |
506 | Transport/communication errors are reported as C<< transport_error => |
570 | Transport/communication errors are reported as C<< transport_error => |
507 | $message >>. |
571 | $message >>. |
508 | |
572 | |
509 | =back |
573 | =back |
510 | |
574 | |
511 | =head1 FUNCTIONS FOR NODES |
|
|
512 | |
|
|
513 | =over 4 |
|
|
514 | |
|
|
515 | =item initialise_node $noderef, $seednode, $seednode... |
|
|
516 | |
|
|
517 | =item initialise_node "slave/", $master, $master... |
|
|
518 | |
|
|
519 | Initialises a node - must be called exactly once before calling other |
|
|
520 | AnyEvent::MP functions when talking to other nodes is required. |
|
|
521 | |
|
|
522 | All arguments are noderefs, which can be either resolved or unresolved. |
|
|
523 | |
|
|
524 | There are two types of networked nodes, public nodes and slave nodes: |
|
|
525 | |
|
|
526 | =over 4 |
|
|
527 | |
|
|
528 | =item public nodes |
|
|
529 | |
|
|
530 | For public nodes, C<$noderef> must either be a (possibly unresolved) |
|
|
531 | noderef, in which case it will be resolved, or C<undef> (or missing), in |
|
|
532 | which case the noderef will be guessed. |
|
|
533 | |
|
|
534 | Afterwards, the node will bind itself on all endpoints and try to connect |
|
|
535 | to all additional C<$seednodes> that are specified. Seednodes are optional |
|
|
536 | and can be used to quickly bootstrap the node into an existing network. |
|
|
537 | |
|
|
538 | =item slave nodes |
|
|
539 | |
|
|
540 | When the C<$noderef> is the special string C<slave/>, then the node will |
|
|
541 | become a slave node. Slave nodes cannot be contacted from outside and will |
|
|
542 | route most of their traffic to the master node that they attach to. |
|
|
543 | |
|
|
544 | At least one additional noderef is required: The node will try to connect |
|
|
545 | to all of them and will become a slave attached to the first node it can |
|
|
546 | successfully connect to. |
|
|
547 | |
|
|
548 | =back |
|
|
549 | |
|
|
550 | This function will block until all nodes have been resolved and, for slave |
|
|
551 | nodes, until it has successfully established a connection to a master |
|
|
552 | server. |
|
|
553 | |
|
|
554 | Example: become a public node listening on the default node. |
|
|
555 | |
|
|
556 | initialise_node; |
|
|
557 | |
|
|
558 | Example: become a public node, and try to contact some well-known master |
|
|
559 | servers to become part of the network. |
|
|
560 | |
|
|
561 | initialise_node undef, "master1", "master2"; |
|
|
562 | |
|
|
563 | Example: become a public node listening on port C<4041>. |
|
|
564 | |
|
|
565 | initialise_node 4041; |
|
|
566 | |
|
|
567 | Example: become a public node, only visible on localhost port 4044. |
|
|
568 | |
|
|
569 | initialise_node "locahost:4044"; |
|
|
570 | |
|
|
571 | Example: become a slave node to any of the specified master servers. |
|
|
572 | |
|
|
573 | initialise_node "slave/", "master1", "192.168.13.17", "mp.example.net"; |
|
|
574 | |
|
|
575 | =cut |
|
|
576 | |
|
|
577 | =back |
|
|
578 | |
|
|
579 | =head1 NODE MESSAGES |
575 | =head1 NODE MESSAGES |
580 | |
576 | |
581 | Nodes understand the following messages sent to them. Many of them take |
577 | Nodes understand the following messages sent to them. Many of them take |
582 | arguments called C<@reply>, which will simply be used to compose a reply |
578 | arguments called C<@reply>, which will simply be used to compose a reply |
583 | message - C<$reply[0]> is the port to reply to, C<$reply[1]> the type and |
579 | message - C<$reply[0]> is the port to reply to, C<$reply[1]> the type and |