diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-03-09 03:04:06 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-03-09 03:04:06 +0000 |
commit | f7c0d631f7119d27e9ddcfc0064a3cd6610ba901 (patch) | |
tree | 1999235fdea77d572ef88116ea3370dc88585859 /src/mesh/gnunet-service-mesh.c | |
parent | b2e82d34bc2a189f37c1c90ac2c7c93b1bc00e92 (diff) | |
download | gnunet-f7c0d631f7119d27e9ddcfc0064a3cd6610ba901.tar.gz gnunet-f7c0d631f7119d27e9ddcfc0064a3cd6610ba901.zip |
Added first data structures for the MESH service
Diffstat (limited to 'src/mesh/gnunet-service-mesh.c')
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 232 |
1 files changed, 232 insertions, 0 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c new file mode 100644 index 000000000..bdfd1a3ac --- /dev/null +++ b/src/mesh/gnunet-service-mesh.c | |||
@@ -0,0 +1,232 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2001 - 2011 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet 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 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file mesh/gnunet-service-mesh.c | ||
23 | * @brief GNUnet MESH service | ||
24 | * @author Bartlomiej Polot | ||
25 | */ | ||
26 | |||
27 | #include <stdint.h> | ||
28 | |||
29 | /** | ||
30 | * All the states a peer participating in a tunnel can be in. | ||
31 | */ | ||
32 | enum PeerState | ||
33 | { | ||
34 | /** | ||
35 | * Request sent, not yet answered. | ||
36 | */ | ||
37 | MESH_PEER_WAITING, | ||
38 | |||
39 | /** | ||
40 | * Peer connected and ready to accept data | ||
41 | */ | ||
42 | MESH_PEER_READY, | ||
43 | |||
44 | /** | ||
45 | * Peer connected previosly but not responding | ||
46 | */ | ||
47 | MESH_PEER_UNAVAILABLE, | ||
48 | |||
49 | /** | ||
50 | * Peer requested but not ever connected | ||
51 | */ | ||
52 | MESH_PEER_UNREACHABLE | ||
53 | }; | ||
54 | |||
55 | /** | ||
56 | * Struct containing all information regarding a given peer | ||
57 | */ | ||
58 | struct PeerInfo | ||
59 | { | ||
60 | /** | ||
61 | * ID of the peer | ||
62 | */ | ||
63 | struct GNUNET_PeerIdentity id; | ||
64 | |||
65 | /** | ||
66 | * Is the peer reachable? Is the peer even connected? | ||
67 | */ | ||
68 | struct PeerState state; | ||
69 | |||
70 | /** | ||
71 | * Who to send the data to | ||
72 | */ | ||
73 | uint32_t first_hop; | ||
74 | |||
75 | /** | ||
76 | * Max data rate to this peer | ||
77 | */ | ||
78 | uint32_t max_speed; | ||
79 | }; | ||
80 | |||
81 | /** | ||
82 | * Information regarding a path | ||
83 | */ | ||
84 | struct Path | ||
85 | { | ||
86 | /** | ||
87 | * Id of the path, in case it's needed | ||
88 | */ | ||
89 | uint32_t id; | ||
90 | |||
91 | /** | ||
92 | * Whether the path is serving traffic in a tunnel or is a backup | ||
93 | */ | ||
94 | int in_use; | ||
95 | |||
96 | /** | ||
97 | * List of all the peers that form the path from origin to target | ||
98 | */ | ||
99 | PeerInfo *peers; | ||
100 | }; | ||
101 | |||
102 | /** | ||
103 | * Struct containing all information regarding a tunnel | ||
104 | * For an intermediate node the improtant info used will be: | ||
105 | * - OID \ To identify | ||
106 | * - TID / the tunnel | ||
107 | * - paths[0] | To know where to send it next | ||
108 | * - metainfo: ready, speeds, accounting | ||
109 | * For an end node more fields will be needed (client-handling) | ||
110 | */ | ||
111 | struct MESH_tunnel | ||
112 | { | ||
113 | /** | ||
114 | * Origin ID: Node that created the tunnel | ||
115 | */ | ||
116 | struct GNUNET_PeerIdentity oid; | ||
117 | |||
118 | /** | ||
119 | * Tunnel number (unique for a given oid) | ||
120 | */ | ||
121 | uint32_t tid; | ||
122 | |||
123 | /** | ||
124 | * Whether the tunnel is in state to transmit data | ||
125 | */ | ||
126 | int ready; | ||
127 | |||
128 | /** | ||
129 | * Minimal speed for this tunnel in kb/s | ||
130 | */ | ||
131 | uint32_t speed_min; | ||
132 | |||
133 | /** | ||
134 | * Maximal speed for this tunnel in kb/s | ||
135 | */ | ||
136 | uint32_t speed_max; | ||
137 | |||
138 | /** | ||
139 | * Peers in the tunnel, for future optimizations | ||
140 | */ | ||
141 | struct PeerInfo *peers; | ||
142 | |||
143 | /** | ||
144 | * Paths (used and backup) | ||
145 | */ | ||
146 | struct Path *paths; | ||
147 | |||
148 | /** | ||
149 | * Messages ready to transmit | ||
150 | */ | ||
151 | struct GNUNET_MessageHeader *msg_out; | ||
152 | |||
153 | /** | ||
154 | * Messages received and not processed | ||
155 | */ | ||
156 | struct GNUNET_MessageHeader *msg_in; | ||
157 | |||
158 | /** | ||
159 | * FIXME Clients. Is anyone to be notified for traffic here? | ||
160 | */ | ||
161 | }; | ||
162 | |||
163 | /** | ||
164 | * So, I'm an endpoint. Why am I receiveing traffic? | ||
165 | * Who is interested in this? How to communicate with them? | ||
166 | */ | ||
167 | struct Clients | ||
168 | { | ||
169 | /** | ||
170 | * FIXME add structures needed to handle client connections | ||
171 | */ | ||
172 | int fixme; | ||
173 | }; | ||
174 | |||
175 | |||
176 | |||
177 | /** | ||
178 | * Process mesh requests. FIXME NON FUNCTIONAL, COPIED FROM DHT!! | ||
179 | * | ||
180 | * @param cls closure | ||
181 | * @param server the initialized server | ||
182 | * @param c configuration to use | ||
183 | */ | ||
184 | static void | ||
185 | run (void *cls, | ||
186 | struct GNUNET_SERVER_Handle *server, | ||
187 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
188 | { | ||
189 | struct GNUNET_TIME_Relative next_send_time; | ||
190 | unsigned long long temp_config_num; | ||
191 | char *converge_modifier_buf; | ||
192 | |||
193 | cfg = c; | ||
194 | datacache = GNUNET_DATACACHE_create (cfg, "dhtcache"); | ||
195 | GNUNET_SERVER_add_handlers (server, plugin_handlers); | ||
196 | GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); | ||
197 | coreAPI = GNUNET_CORE_connect (cfg, /* Main configuration */ | ||
198 | DEFAULT_CORE_QUEUE_SIZE, /* queue size */ | ||
199 | NULL, /* Closure passed to DHT functions */ | ||
200 | &core_init, /* Call core_init once connected */ | ||
201 | &handle_core_connect, /* Handle connects */ | ||
202 | &handle_core_disconnect, /* remove peers on disconnects */ | ||
203 | NULL, /* Do we care about "status" updates? */ | ||
204 | NULL, /* Don't want notified about all incoming messages */ | ||
205 | GNUNET_NO, /* For header only inbound notification */ | ||
206 | NULL, /* Don't want notified about all outbound messages */ | ||
207 | GNUNET_NO, /* For header only outbound notification */ | ||
208 | core_handlers); /* Register these handlers */ | ||
209 | |||
210 | if (coreAPI == NULL) | ||
211 | return; | ||
212 | } | ||
213 | |||
214 | /** | ||
215 | * The main function for the mesh service. | ||
216 | * | ||
217 | * @param argc number of arguments from the command line | ||
218 | * @param argv command line arguments | ||
219 | * @return 0 ok, 1 on error | ||
220 | */ | ||
221 | int | ||
222 | main (int argc, char *const *argv) | ||
223 | { | ||
224 | int ret; | ||
225 | |||
226 | ret = (GNUNET_OK == | ||
227 | GNUNET_SERVICE_run (argc, | ||
228 | argv, | ||
229 | "mesh", | ||
230 | GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1; | ||
231 | return ret; | ||
232 | } \ No newline at end of file | ||