NewMadeleine

Documentation

« back to PM2 home.
nm_madico_launcher.h
Go to the documentation of this file.
1/*
2 * NewMadeleine
3 * Copyright (C) 2006-2026 (see AUTHORS file)
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 */
15
20#ifndef NM_MADICO_LAUNCHER_H
21#define NM_MADICO_LAUNCHER_H
22
23#include <Padico/Topology.h>
24#include <Padico/NetSelector.h>
25
26static nm_drv_vect_t nm_madico_launcher_default_selector(const char*url, void*_arg)
27{
28 struct nm_launcher_gates_s*p_gates = _arg;
29 const int size = p_gates->size;
30 int i = 0;
31 while(i < size)
32 {
33 if((p_gates->p_gates[i].p_url != NULL) && (strcmp(p_gates->p_gates[i].p_url, url) == 0))
34 {
35 nm_drv_vect_t p_drvs = nm_drv_vect_copy(&p_gates->p_gates[i].drvs);
36 return p_drvs;
37 }
38 i++;
39 }
40 return NULL;
41}
42
43
46static inline void nm_launcher_gates_populate_ns(struct nm_launcher_gates_s*p_gates, padico_topo_node_t*p_peers)
47{
48 int use_ns = 0;
49 const char*nmad_driver = padico_getenv("NMAD_DRIVER");
50 if( (nmad_driver == NULL) ||
51 (strcmp(nmad_driver, "defaults") == 0) ||
52 (strcmp(nmad_driver, "auto") == 0) )
53 {
54 /* no NMAD_DRIVER or explicit auto: use NetSelector */
55 use_ns = 1;
56 }
57 else if(strncmp(nmad_driver, "file:", 5) == 0)
58 {
59 /* NetSelector does not support the file: syntax */
60 use_ns = 0;
61 }
62 else if(strchr(nmad_driver, ',') != NULL)
63 {
64 /* NMAD_DRIVER using NetSelector syntax -> inherit */
65 puk_opt_setvalue("NetSelector_madico", "netselector_list", nmad_driver);
66 padico_out(puk_verbose_info, "use NetSelector with value = %s\n", nmad_driver);
67 use_ns = 1;
68 }
69 if(use_ns)
70 {
71 struct nm_component_hashtable_s loaded_components;
72 nm_component_hashtable_init(&loaded_components);
73 int i;
74 for(i = 0; i < p_gates->size; i++)
75 {
76 if(!nm_drv_vect_empty(&p_gates->p_gates[i].drvs))
77 {
78 /* register already initialized drivers _before_ trying to load
79 * anything else to avoid duplicates */
80 nm_drv_vect_itor_t d;
81 puk_vect_foreach(d, nm_drv, &p_gates->p_gates[i].drvs)
82 {
83 nm_drv_t p_drv = *d;
84 nm_drv_t p_drv0 = nm_component_hashtable_lookup(&loaded_components, p_drv->assembly);
85 if(p_drv0 == NULL)
86 {
87 nm_component_hashtable_insert(&loaded_components, p_drv->assembly, p_drv);
88 }
89 }
90 }
91 }
92 for(i = 0; i < p_gates->size; i++)
93 {
94 if(p_peers[i] == NULL)
95 {
96 /* no topology info for this node yet; skip */
97 continue;
98 }
99 if(!nm_drv_vect_empty(&p_gates->p_gates[i].drvs))
100 {
101 /* drivers already initialized for this gate; skip */
102 continue;
103 }
104 const puk_component_t component_1 =
105 padico_ns_serial_selector(p_peers[i], "trk_small", puk_iface_NewMad_minidriver());
106 const puk_component_t component_2 =
107 padico_ns_serial_selector(p_peers[i], "trk_large", puk_iface_NewMad_minidriver());
108 if(component_1 == NULL)
109 NM_FATAL("no suitable component to connect small trk to node %s\n",
110 padico_topo_node_getname(p_peers[i]));
111 if(component_2 == NULL)
112 NM_FATAL("no suitable component to connect large trk to node %s\n",
113 padico_topo_node_getname(p_peers[i]));
114
115 nm_drv_t p_drv1 = nm_component_hashtable_lookup(&loaded_components, component_1);
116 if(p_drv1 == NULL)
117 {
118 p_drv1 = nm_launcher_add_driver(component_1, nm_trk_kind_small);
119 nm_component_hashtable_insert(&loaded_components, component_1, p_drv1);
120 }
121 nm_drv_vect_push_back(&p_gates->p_gates[i].drvs, p_drv1);
122 nm_drv_t p_drv2 = nm_component_hashtable_lookup(&loaded_components, component_2);
123 if(p_drv2 == NULL)
124 {
125 p_drv2 = nm_launcher_add_driver(component_2, nm_trk_kind_large);
126 nm_component_hashtable_insert(&loaded_components, component_2, p_drv2);
127 }
128 nm_drv_vect_push_back(&p_gates->p_gates[i].drvs, p_drv2);
129 }
131 nm_component_hashtable_destroy(&loaded_components);
132 }
133 int i;
134 for(i = 0; i < p_gates->size; i++)
135 {
136 if(p_peers[i] != NULL)
137 {
138 assert(PADICO_TOPO_UUID_SIZE == NM_UUID_SIZE);
139 padico_topo_uuid_t uuid = padico_topo_node_getuuid(p_peers[i]);
140 memcpy(p_gates->p_gates[i].uuid.bytes, uuid, NM_UUID_SIZE);
141 }
142 }
143
144}
145
146
147#endif /* NM_MADICO_LAUNCHER_H */
assert(p_data->ops.p_traversal !=NULL)
nm_drv_t nm_launcher_add_driver(puk_component_t component, nm_trk_kind_t kind)
Add a driver to the session.
void nm_launcher_set_selector(nm_launcher_selector_t selector, void *_arg)
Declare the selector to use to establish connections.
static void nm_launcher_gates_populate_ns(struct nm_launcher_gates_s *p_gates, padico_topo_node_t *p_peers)
use PadicoTM NetSelector to populate gates with driver.
static nm_drv_vect_t nm_madico_launcher_default_selector(const char *url, void *_arg)
nm_len_t size
size of the onsided data (not incuding target-side completion)
#define NM_FATAL(format,...)
Definition nm_public.h:67
@ nm_trk_kind_small
small packets with headers & parsing
Definition nm_types.h:98
@ nm_trk_kind_large
large packets with rdv, no header
Definition nm_types.h:99
#define NM_UUID_SIZE
128 bits uuid, as 32 hexadecimal numbers
Definition nm_types.h:120
a driver.
Definition nm_drv.h:35
puk_component_t assembly
Component assembly associated to the driver.
Definition nm_drv.h:42
struct nm_drv_vect_s drvs
struct nm_uuid_s uuid
a set of gates to manage connection establishment by launcher
struct nm_launcher_gate_s * p_gates
char bytes[32]
Definition nm_types.h:125