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 | |
parent | b2e82d34bc2a189f37c1c90ac2c7c93b1bc00e92 (diff) | |
download | gnunet-f7c0d631f7119d27e9ddcfc0064a3cd6610ba901.tar.gz gnunet-f7c0d631f7119d27e9ddcfc0064a3cd6610ba901.zip |
Added first data structures for the MESH service
-rw-r--r-- | src/include/gnunet_mesh_service.h | 4 | ||||
-rw-r--r-- | src/include/gnunet_protocols.h | 51 | ||||
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 232 | ||||
-rw-r--r-- | src/mesh/mesh.h | 126 |
4 files changed, 411 insertions, 2 deletions
diff --git a/src/include/gnunet_mesh_service.h b/src/include/gnunet_mesh_service.h index 1ff5e3bec..36dbafb86 100644 --- a/src/include/gnunet_mesh_service.h +++ b/src/include/gnunet_mesh_service.h | |||
@@ -114,7 +114,7 @@ typedef void (GNUNET_MESH_TunnelEndHandler)(void *cls, | |||
114 | 114 | ||
115 | 115 | ||
116 | /** | 116 | /** |
117 | * Connect to the mesh service. | 117 | * Connect to the mesh service. |
118 | * | 118 | * |
119 | * @param cfg configuration to use | 119 | * @param cfg configuration to use |
120 | * @param cls closure for the various callbacks that follow (including handlers in the handlers array) | 120 | * @param cls closure for the various callbacks that follow (including handlers in the handlers array) |
@@ -190,7 +190,7 @@ struct GNUNET_MESH_PeerRequestHandle; | |||
190 | * | 190 | * |
191 | * @param h mesh handle | 191 | * @param h mesh handle |
192 | * @param timeout how long to try to establish a connection | 192 | * @param timeout how long to try to establish a connection |
193 | * @param num_peers length of the peers arrray | 193 | * @param num_peers length of the peers array |
194 | * @param peers list of candidates to connect to | 194 | * @param peers list of candidates to connect to |
195 | * @param connect_handler function to call on successful connect (or timeout) | 195 | * @param connect_handler function to call on successful connect (or timeout) |
196 | * @param disconnect_handler function to call on disconnect | 196 | * @param disconnect_handler function to call on disconnect |
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index 60369086d..29657ff08 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h | |||
@@ -743,6 +743,57 @@ extern "C" | |||
743 | 743 | ||
744 | 744 | ||
745 | /** | 745 | /** |
746 | * MESH message types (WiP) | ||
747 | */ | ||
748 | |||
749 | /** | ||
750 | * Request the creation of a path | ||
751 | */ | ||
752 | #define GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE 256 | ||
753 | |||
754 | /** | ||
755 | * Request the modification of an existing path | ||
756 | */ | ||
757 | #define GNUNET_MESSAGE_TYPE_MESH_PATH_CHANGE 257 | ||
758 | |||
759 | /** | ||
760 | * Request the addition to a new branch to a path | ||
761 | */ | ||
762 | #define GNUNET_MESSAGE_TYPE_MESH_PATH_ADD 258 | ||
763 | |||
764 | /** | ||
765 | * At some point, the route will spontaneously change | ||
766 | */ | ||
767 | #define GNUNET_MESSAGE_TYPE_MESH_PATH_CHANGED 259 | ||
768 | |||
769 | /** | ||
770 | * Transport data in the mesh (origin->end) | ||
771 | */ | ||
772 | #define GNUNET_MESSAGE_TYPE_MESH_DATA_GO 260 | ||
773 | |||
774 | /** | ||
775 | * Transport data back in the mesh (end->origin) | ||
776 | * (not sure if this is the right way, should be some other solution) | ||
777 | */ | ||
778 | #define GNUNET_MESSAGE_TYPE_MESH_DATA_BACK 261 | ||
779 | |||
780 | /** | ||
781 | * We need flow control | ||
782 | */ | ||
783 | #define GNUNET_MESSAGE_TYPE_MESH_SPEED_NOTIFY 262 | ||
784 | |||
785 | /** | ||
786 | * 640kb should be enough for everybody | ||
787 | */ | ||
788 | #define GNUNET_MESSAGE_TYPE_MESH_RESERVE_END 288 | ||
789 | |||
790 | /** | ||
791 | * MESH message types END | ||
792 | */ | ||
793 | |||
794 | |||
795 | |||
796 | /** | ||
746 | * Message sent from client to join a chat room. | 797 | * Message sent from client to join a chat room. |
747 | */ | 798 | */ |
748 | #define GNUNET_MESSAGE_TYPE_CHAT_JOIN_REQUEST 300 | 799 | #define GNUNET_MESSAGE_TYPE_CHAT_JOIN_REQUEST 300 |
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 | ||
diff --git a/src/mesh/mesh.h b/src/mesh/mesh.h new file mode 100644 index 000000000..57778a352 --- /dev/null +++ b/src/mesh/mesh.h | |||
@@ -0,0 +1,126 @@ | |||
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 | * @author Bartlomiej Polot | ||
23 | * @file mesh/mesh.h | ||
24 | */ | ||
25 | |||
26 | |||
27 | #ifndef MESH_H_ | ||
28 | #define MESH_H_ | ||
29 | #include <stdint.h> | ||
30 | |||
31 | /** | ||
32 | * Message for mesh path management | ||
33 | */ | ||
34 | struct GNUNET_MESH_ManipulatePath | ||
35 | { | ||
36 | /** | ||
37 | * Type: GNUNET_MESSAGE_TYPE_MESH_PATH_[CREATE|CHANGE|ADD] | ||
38 | */ | ||
39 | struct GNUNET_MessageHeader header; | ||
40 | |||
41 | /** | ||
42 | * Id of the tunnel this path belongs to | ||
43 | */ | ||
44 | uint32_t tid; | ||
45 | |||
46 | /** | ||
47 | * Information about speed requirements | ||
48 | */ | ||
49 | uint32_t speed_min; | ||
50 | uint32_t speed_max; | ||
51 | |||
52 | /** | ||
53 | * Number of hops in the path given below | ||
54 | */ | ||
55 | uint16_t path_length; | ||
56 | |||
57 | /** | ||
58 | * path_length structs defining the *whole* path | ||
59 | */ | ||
60 | struct GNUNET_PeerIdentity peers[]; | ||
61 | }; | ||
62 | |||
63 | /** | ||
64 | * Message for mesh data traffic | ||
65 | */ | ||
66 | struct GNUNET_MESH_Data | ||
67 | { | ||
68 | /** | ||
69 | * Type: GNUNET_MESSAGE_TYPE_DATA_[GO|BACK] | ||
70 | */ | ||
71 | struct GNUNET_MessageHeader header; | ||
72 | |||
73 | /** | ||
74 | * OID of the tunnel | ||
75 | */ | ||
76 | struct GNUNET_PeerIdentity oid; | ||
77 | |||
78 | /** | ||
79 | * TID of the tunnel | ||
80 | */ | ||
81 | uint32_t tid; | ||
82 | |||
83 | /** | ||
84 | * Size of payload | ||
85 | * FIXME uint16 enough? | ||
86 | */ | ||
87 | uint16_t size; | ||
88 | |||
89 | /** | ||
90 | * Payload | ||
91 | */ | ||
92 | uint8_t data[]; | ||
93 | }; | ||
94 | |||
95 | /** | ||
96 | * Message for mesh flow control | ||
97 | */ | ||
98 | struct GNUNET_MESH_SpeedNotify | ||
99 | { | ||
100 | /** | ||
101 | * Type: GNUNET_MESSAGE_TYPE_DATA_SPEED_NOTIFY | ||
102 | */ | ||
103 | struct GNUNET_MessageHeader header; | ||
104 | |||
105 | /** | ||
106 | * OID of the tunnel | ||
107 | */ | ||
108 | struct GNUNET_PeerIdentity oid; | ||
109 | |||
110 | /** | ||
111 | * TID of the tunnel | ||
112 | */ | ||
113 | uint32_t tid; | ||
114 | |||
115 | /** | ||
116 | * Slowest link down the path | ||
117 | */ | ||
118 | uint32_t speed_min; | ||
119 | |||
120 | /** | ||
121 | * Fastest link down the path | ||
122 | */ | ||
123 | uint32_t speed_max; | ||
124 | }; | ||
125 | |||
126 | #endif \ No newline at end of file | ||