… | |
… | |
168 | it should know the noderefs of some other nodes in the network. |
168 | it should know the noderefs of some other nodes in the network. |
169 | |
169 | |
170 | This function initialises a node - it must be called exactly once (or |
170 | This function initialises a node - it must be called exactly once (or |
171 | never) before calling other AnyEvent::MP functions. |
171 | never) before calling other AnyEvent::MP functions. |
172 | |
172 | |
173 | All arguments are noderefs, which can be either resolved or unresolved. |
173 | All arguments (optionally except for the first) are noderefs, which can be |
|
|
174 | either resolved or unresolved. |
|
|
175 | |
|
|
176 | The first argument will be looked up in the configuration database first |
|
|
177 | (if it is C<undef> then the current nodename will be used instead) to find |
|
|
178 | the relevant configuration profile (see L<aemp>). If none is found then |
|
|
179 | the default configuration is used. The configuration supplies additional |
|
|
180 | seed/master nodes and can override the actual noderef. |
174 | |
181 | |
175 | There are two types of networked nodes, public nodes and slave nodes: |
182 | There are two types of networked nodes, public nodes and slave nodes: |
176 | |
183 | |
177 | =over 4 |
184 | =over 4 |
178 | |
185 | |
179 | =item public nodes |
186 | =item public nodes |
180 | |
187 | |
181 | For public nodes, C<$noderef> must either be a (possibly unresolved) |
188 | For public nodes, C<$noderef> (supplied either directly to |
182 | noderef, in which case it will be resolved, or C<undef> (or missing), in |
189 | C<initialise_node> or indirectly via a profile or the nodename) must be a |
183 | which case the noderef will be guessed. |
190 | noderef (possibly unresolved, in which case it will be resolved). |
184 | |
191 | |
185 | Afterwards, the node will bind itself on all endpoints and try to connect |
192 | After resolving, the node will bind itself on all endpoints and try to |
186 | to all additional C<$seednodes> that are specified. Seednodes are optional |
193 | connect to all additional C<$seednodes> that are specified. Seednodes are |
187 | and can be used to quickly bootstrap the node into an existing network. |
194 | optional and can be used to quickly bootstrap the node into an existing |
|
|
195 | network. |
188 | |
196 | |
189 | =item slave nodes |
197 | =item slave nodes |
190 | |
198 | |
191 | When the C<$noderef> is the special string C<slave/>, then the node will |
199 | When the C<$noderef> (either as given or overriden by the config file) |
|
|
200 | is the special string C<slave/>, then the node will become a slave |
192 | become a slave node. Slave nodes cannot be contacted from outside and will |
201 | node. Slave nodes cannot be contacted from outside and will route most of |
193 | route most of their traffic to the master node that they attach to. |
202 | their traffic to the master node that they attach to. |
194 | |
203 | |
195 | At least one additional noderef is required: The node will try to connect |
204 | At least one additional noderef is required (either by specifying it |
196 | to all of them and will become a slave attached to the first node it can |
205 | directly or because it is part of the configuration profile): The node |
197 | successfully connect to. |
206 | will try to connect to all of them and will become a slave attached to the |
|
|
207 | first node it can successfully connect to. |
198 | |
208 | |
199 | =back |
209 | =back |
200 | |
210 | |
201 | This function will block until all nodes have been resolved and, for slave |
211 | This function will block until all nodes have been resolved and, for slave |
202 | nodes, until it has successfully established a connection to a master |
212 | nodes, until it has successfully established a connection to a master |
203 | server. |
213 | server. |
204 | |
214 | |
205 | Example: become a public node listening on the default node. |
215 | Example: become a public node listening on the guessed noderef, or the one |
|
|
216 | specified via C<aemp> for the current node. This should be the most common |
|
|
217 | form of invocation for "daemon"-type nodes. |
206 | |
218 | |
207 | initialise_node; |
219 | initialise_node; |
|
|
220 | |
|
|
221 | Example: become a slave node to any of the the seednodes specified via |
|
|
222 | C<aemp>. This form is often used for commandline clients. |
|
|
223 | |
|
|
224 | initialise_node "slave/"; |
|
|
225 | |
|
|
226 | Example: become a slave node to any of the specified master servers. This |
|
|
227 | form is also often used for commandline clients. |
|
|
228 | |
|
|
229 | initialise_node "slave/", "master1", "192.168.13.17", "mp.example.net"; |
208 | |
230 | |
209 | Example: become a public node, and try to contact some well-known master |
231 | Example: become a public node, and try to contact some well-known master |
210 | servers to become part of the network. |
232 | servers to become part of the network. |
211 | |
233 | |
212 | initialise_node undef, "master1", "master2"; |
234 | initialise_node undef, "master1", "master2"; |
… | |
… | |
215 | |
237 | |
216 | initialise_node 4041; |
238 | initialise_node 4041; |
217 | |
239 | |
218 | Example: become a public node, only visible on localhost port 4044. |
240 | Example: become a public node, only visible on localhost port 4044. |
219 | |
241 | |
220 | initialise_node "locahost:4044"; |
242 | initialise_node "localhost:4044"; |
221 | |
|
|
222 | Example: become a slave node to any of the specified master servers. |
|
|
223 | |
|
|
224 | initialise_node "slave/", "master1", "192.168.13.17", "mp.example.net"; |
|
|
225 | |
243 | |
226 | =item $cv = resolve_node $noderef |
244 | =item $cv = resolve_node $noderef |
227 | |
245 | |
228 | Takes an unresolved node reference that may contain hostnames and |
246 | Takes an unresolved node reference that may contain hostnames and |
229 | abbreviated IDs, resolves all of them and returns a resolved node |
247 | abbreviated IDs, resolves all of them and returns a resolved node |