diff options
author | David Brodski <david@brodski.eu> | 2011-04-12 23:33:44 +0000 |
---|---|---|
committer | David Brodski <david@brodski.eu> | 2011-04-12 23:33:44 +0000 |
commit | d47e8be9228c131f93441743c8e90b360d554e9d (patch) | |
tree | 9a5d82775a5e7c46ac4ba01784f129a2c8db387c /src/transport | |
parent | d8cd4422e9d88a0c8180976179662ae2e890db6d (diff) | |
download | gnunet-d47e8be9228c131f93441743c8e90b360d554e9d.tar.gz gnunet-d47e8be9228c131f93441743c8e90b360d554e9d.zip |
Big cleanup and heap used for fragments send and with the timeouts
Diffstat (limited to 'src/transport')
-rw-r--r-- | src/transport/gnunet-transport-wlan-helper.c | 456 | ||||
-rw-r--r-- | src/transport/plugin_transport_wlan.c | 737 | ||||
-rw-r--r-- | src/transport/wlan/loopback_helper.c | 41 |
3 files changed, 664 insertions, 570 deletions
diff --git a/src/transport/gnunet-transport-wlan-helper.c b/src/transport/gnunet-transport-wlan-helper.c index e18a6e7c8..aaa34284d 100644 --- a/src/transport/gnunet-transport-wlan-helper.c +++ b/src/transport/gnunet-transport-wlan-helper.c | |||
@@ -92,7 +92,6 @@ | |||
92 | #define ARPHRD_IEEE80211_PRISM 802 | 92 | #define ARPHRD_IEEE80211_PRISM 802 |
93 | #define ARPHRD_IEEE80211_FULL 803 | 93 | #define ARPHRD_IEEE80211_FULL 803 |
94 | 94 | ||
95 | int first; | ||
96 | int closeprog; | 95 | int closeprog; |
97 | 96 | ||
98 | #include "wlan/helper_common.h" | 97 | #include "wlan/helper_common.h" |
@@ -130,125 +129,129 @@ struct Hardware_Infos | |||
130 | 129 | ||
131 | struct sendbuf *write_pout; | 130 | struct sendbuf *write_pout; |
132 | int fd_in, arptype_in; | 131 | int fd_in, arptype_in; |
133 | int fd_out, arptype_out; | 132 | int fd_out; |
134 | int fd_main; | 133 | //int arptype_out; |
135 | int fd_rtc; | 134 | //int fd_main; |
135 | //int fd_rtc; | ||
136 | 136 | ||
137 | DRIVER_TYPE drivertype; /* inited to DT_UNKNOWN on allocation by wi_alloc */ | 137 | DRIVER_TYPE drivertype; /* inited to DT_UNKNOWN on allocation by wi_alloc */ |
138 | 138 | ||
139 | FILE *f_cap_in; | 139 | //FILE *f_cap_in; |
140 | 140 | ||
141 | struct pcap_file_header pfh_in; | 141 | //struct pcap_file_header pfh_in; |
142 | 142 | ||
143 | int sysfs_inject; | 143 | //int sysfs_inject; |
144 | int channel; | 144 | //int channel; |
145 | int freq; | 145 | //int freq; |
146 | int rate; | 146 | //int rate; |
147 | int tx_power; | 147 | //int tx_power; |
148 | char *wlanctlng; /* XXX never set */ | 148 | //char *wlanctlng; /* XXX never set */ |
149 | char *iwpriv; | 149 | //char *iwpriv; |
150 | char *iwconfig; | 150 | //char *iwconfig; |
151 | char *ifconfig; | 151 | //char *ifconfig; |
152 | char *iface; | 152 | char *iface; |
153 | char *main_if; | 153 | //char *main_if; |
154 | unsigned char pl_mac[6]; | 154 | unsigned char pl_mac[6]; |
155 | int inject_wlanng; | 155 | //int inject_wlanng; |
156 | }; | 156 | }; |
157 | 157 | ||
158 | //#include "radiotap.h" | 158 | //#include "radiotap.h" |
159 | 159 | ||
160 | // mac of this node | 160 | // mac of this node |
161 | char mac[] = | 161 | /*char mac[] = |
162 | { 0x13, 0x22, 0x33, 0x44, 0x55, 0x66 }; | 162 | { 0x13, 0x22, 0x33, 0x44, 0x55, 0x66 }; |
163 | 163 | */ | |
164 | /* wifi bitrate to use in 500kHz units */ | 164 | /* wifi bitrate to use in 500kHz units */ |
165 | 165 | ||
166 | static const u8 u8aRatesToUse[] = | 166 | /* |
167 | { | 167 | static const u8 u8aRatesToUse[] = |
168 | 168 | { | |
169 | 54 * 2, 48 * 2, 36 * 2, 24 * 2, 18 * 2, 12 * 2, 9 * 2, 11 * 2, 11, // 5.5 | ||
170 | 2 * 2, 1 * 2 }; | ||
171 | 169 | ||
172 | #define OFFSET_FLAGS 0x10 | 170 | 54 * 2, 48 * 2, 36 * 2, 24 * 2, 18 * 2, 12 * 2, 9 * 2, 11 * 2, 11, // 5.5 |
173 | #define OFFSET_RATE 0x11 | 171 | 2 * 2, 1 * 2 }; |
174 | 172 | ||
173 | #define OFFSET_FLAGS 0x10 | ||
174 | #define OFFSET_RATE 0x11 | ||
175 | */ | ||
175 | // this is where we store a summary of the | 176 | // this is where we store a summary of the |
176 | // information from the radiotap header | 177 | // information from the radiotap header |
177 | 178 | ||
178 | typedef struct | 179 | /* |
179 | { | 180 | typedef struct |
180 | int m_nChannel; | 181 | { |
181 | int m_nChannelFlags; | 182 | int m_nChannel; |
182 | int m_nRate; | 183 | int m_nChannelFlags; |
183 | int m_nAntenna; | 184 | int m_nRate; |
184 | int m_nRadiotapFlags; | 185 | int m_nAntenna; |
185 | }__attribute__((packed)) PENUMBRA_RADIOTAP_DATA; | 186 | int m_nRadiotapFlags; |
186 | 187 | }__attribute__((packed)) PENUMBRA_RADIOTAP_DATA; | |
188 | */ | ||
187 | static void | 189 | static void |
188 | sigfunc_hw(int sig) | 190 | sigfunc_hw(int sig) |
189 | { | 191 | { |
190 | closeprog = 1; | 192 | closeprog = 1; |
191 | } | 193 | } |
192 | 194 | ||
193 | void | 195 | /* |
194 | Dump(u8 * pu8, int nLength) | 196 | void |
195 | { | 197 | Dump(u8 * pu8, int nLength) |
196 | char sz[256], szBuf[512], szChar[17], *buf, fFirst = 1; | 198 | { |
197 | unsigned char baaLast[2][16]; | 199 | char sz[256], szBuf[512], szChar[17], *buf, fFirst = 1; |
198 | uint n, nPos = 0, nStart = 0, nLine = 0, nSameCount = 0; | 200 | unsigned char baaLast[2][16]; |
199 | 201 | uint n, nPos = 0, nStart = 0, nLine = 0, nSameCount = 0; | |
200 | buf = szBuf; | 202 | |
201 | szChar[0] = '\0'; | 203 | buf = szBuf; |
202 | 204 | szChar[0] = '\0'; | |
203 | for (n = 0; n < nLength; n++) | 205 | |
204 | { | 206 | for (n = 0; n < nLength; n++) |
205 | baaLast[(nLine & 1) ^ 1][n & 0xf] = pu8[n]; | 207 | { |
206 | if ((pu8[n] < 32) || (pu8[n] >= 0x7f)) | 208 | baaLast[(nLine & 1) ^ 1][n & 0xf] = pu8[n]; |
207 | szChar[n & 0xf] = '.'; | 209 | if ((pu8[n] < 32) || (pu8[n] >= 0x7f)) |
208 | else | 210 | szChar[n & 0xf] = '.'; |
209 | szChar[n & 0xf] = pu8[n]; | 211 | else |
210 | szChar[(n & 0xf) + 1] = '\0'; | 212 | szChar[n & 0xf] = pu8[n]; |
211 | nPos += sprintf(&sz[nPos], "%02X ", baaLast[(nLine & 1) ^ 1][n & 0xf]); | 213 | szChar[(n & 0xf) + 1] = '\0'; |
212 | if ((n & 15) != 15) | 214 | nPos += sprintf(&sz[nPos], "%02X ", baaLast[(nLine & 1) ^ 1][n & 0xf]); |
213 | continue; | 215 | if ((n & 15) != 15) |
214 | if ((memcmp(baaLast[0], baaLast[1], 16) == 0) && (!fFirst)) | 216 | continue; |
215 | { | 217 | if ((memcmp(baaLast[0], baaLast[1], 16) == 0) && (!fFirst)) |
216 | nSameCount++; | 218 | { |
217 | } | 219 | nSameCount++; |
218 | else | 220 | } |
219 | { | 221 | else |
220 | if (nSameCount) | 222 | { |
221 | buf += sprintf(buf, "(repeated %d times)\n", nSameCount); | 223 | if (nSameCount) |
222 | buf += sprintf(buf, "%04x: %s %s\n", nStart, sz, szChar); | 224 | buf += sprintf(buf, "(repeated %d times)\n", nSameCount); |
223 | nSameCount = 0; | 225 | buf += sprintf(buf, "%04x: %s %s\n", nStart, sz, szChar); |
224 | printf("%s", szBuf); | 226 | nSameCount = 0; |
225 | buf = szBuf; | 227 | printf("%s", szBuf); |
226 | } | 228 | buf = szBuf; |
227 | nPos = 0; | 229 | } |
228 | nStart = n + 1; | 230 | nPos = 0; |
229 | nLine++; | 231 | nStart = n + 1; |
230 | fFirst = 0; | 232 | nLine++; |
231 | sz[0] = '\0'; | 233 | fFirst = 0; |
232 | szChar[0] = '\0'; | 234 | sz[0] = '\0'; |
233 | } | 235 | szChar[0] = '\0'; |
234 | if (nSameCount) | 236 | } |
235 | buf += sprintf(buf, "(repeated %d times)\n", nSameCount); | 237 | if (nSameCount) |
236 | 238 | buf += sprintf(buf, "(repeated %d times)\n", nSameCount); | |
237 | buf += sprintf(buf, "%04x: %s", nStart, sz); | 239 | |
238 | if (n & 0xf) | 240 | buf += sprintf(buf, "%04x: %s", nStart, sz); |
239 | { | 241 | if (n & 0xf) |
240 | *buf++ = ' '; | 242 | { |
241 | while (n & 0xf) | 243 | *buf++ = ' '; |
242 | { | 244 | while (n & 0xf) |
243 | buf += sprintf(buf, " "); | 245 | { |
244 | n++; | 246 | buf += sprintf(buf, " "); |
245 | } | 247 | n++; |
246 | } | 248 | } |
247 | buf += sprintf(buf, "%s\n", szChar); | 249 | } |
248 | printf("%s", szBuf); | 250 | buf += sprintf(buf, "%s\n", szChar); |
249 | } | 251 | printf("%s", szBuf); |
250 | 252 | } | |
251 | void | 253 | */ |
254 | static void | ||
252 | usage() | 255 | usage() |
253 | { | 256 | { |
254 | printf("Usage: interface-name options\n" | 257 | printf("Usage: interface-name options\n" |
@@ -259,7 +262,7 @@ usage() | |||
259 | exit(1); | 262 | exit(1); |
260 | } | 263 | } |
261 | 264 | ||
262 | unsigned long | 265 | static unsigned long |
263 | calc_crc_osdep(unsigned char * buf, int len) | 266 | calc_crc_osdep(unsigned char * buf, int len) |
264 | { | 267 | { |
265 | unsigned long crc = 0xFFFFFFFF; | 268 | unsigned long crc = 0xFFFFFFFF; |
@@ -272,7 +275,7 @@ calc_crc_osdep(unsigned char * buf, int len) | |||
272 | 275 | ||
273 | /* CRC checksum verification routine */ | 276 | /* CRC checksum verification routine */ |
274 | 277 | ||
275 | int | 278 | static int |
276 | check_crc_buf_osdep(unsigned char *buf, int len) | 279 | check_crc_buf_osdep(unsigned char *buf, int len) |
277 | { | 280 | { |
278 | unsigned long crc; | 281 | unsigned long crc; |
@@ -287,83 +290,86 @@ check_crc_buf_osdep(unsigned char *buf, int len) | |||
287 | } | 290 | } |
288 | 291 | ||
289 | /* Search a file recursively */ | 292 | /* Search a file recursively */ |
290 | static char * | 293 | /* |
291 | searchInside(const char * dir, const char * filename) | 294 | static char * |
292 | { | 295 | searchInside(const char * dir, const char * filename) |
293 | char * ret; | 296 | { |
294 | char * curfile; | 297 | char * ret; |
295 | struct stat sb; | 298 | char * curfile; |
296 | int len, lentot; | 299 | struct stat sb; |
297 | DIR *dp; | 300 | int len, lentot; |
298 | struct dirent *ep; | 301 | DIR *dp; |
299 | 302 | struct dirent *ep; | |
300 | dp = opendir(dir); | 303 | |
301 | if (dp == NULL) | 304 | dp = opendir(dir); |
302 | { | 305 | if (dp == NULL) |
303 | return NULL; | 306 | { |
304 | } | 307 | return NULL; |
305 | 308 | } | |
306 | len = strlen(filename); | 309 | |
307 | lentot = strlen(dir) + 256 + 2; | 310 | len = strlen(filename); |
308 | curfile = (char *) calloc(1, lentot); | 311 | lentot = strlen(dir) + 256 + 2; |
309 | 312 | curfile = (char *) calloc(1, lentot); | |
310 | while ((ep = readdir(dp)) != NULL) | 313 | |
311 | { | 314 | while ((ep = readdir(dp)) != NULL) |
312 | 315 | { | |
313 | memset(curfile, 0, lentot); | 316 | |
314 | sprintf(curfile, "%s/%s", dir, ep->d_name); | 317 | memset(curfile, 0, lentot); |
315 | 318 | sprintf(curfile, "%s/%s", dir, ep->d_name); | |
316 | //Checking if it's the good file | 319 | |
317 | if ((int) strlen(ep->d_name) == len && !strcmp(ep->d_name, filename)) | 320 | //Checking if it's the good file |
318 | { | 321 | if ((int) strlen(ep->d_name) == len && !strcmp(ep->d_name, filename)) |
319 | (void) closedir(dp); | 322 | { |
320 | return curfile; | 323 | (void) closedir(dp); |
321 | } | 324 | return curfile; |
322 | lstat(curfile, &sb); | 325 | } |
323 | 326 | lstat(curfile, &sb); | |
324 | //If it's a directory and not a link, try to go inside to search | 327 | |
325 | if (S_ISDIR(sb.st_mode) && !S_ISLNK(sb.st_mode)) | 328 | //If it's a directory and not a link, try to go inside to search |
326 | { | 329 | if (S_ISDIR(sb.st_mode) && !S_ISLNK(sb.st_mode)) |
327 | //Check if the directory isn't "." or ".." | 330 | { |
328 | if (strcmp(".", ep->d_name) && strcmp("..", ep->d_name)) | 331 | //Check if the directory isn't "." or ".." |
329 | { | 332 | if (strcmp(".", ep->d_name) && strcmp("..", ep->d_name)) |
330 | //Recursive call | 333 | { |
331 | ret = searchInside(curfile, filename); | 334 | //Recursive call |
332 | if (ret != NULL) | 335 | ret = searchInside(curfile, filename); |
333 | { | 336 | if (ret != NULL) |
334 | (void) closedir(dp); | 337 | { |
335 | free(curfile); | 338 | (void) closedir(dp); |
336 | return ret; | 339 | free(curfile); |
337 | } | 340 | return ret; |
338 | } | 341 | } |
339 | } | 342 | } |
340 | } | 343 | } |
341 | (void) closedir(dp); | 344 | } |
342 | free(curfile); | 345 | (void) closedir(dp); |
343 | return NULL; | 346 | free(curfile); |
344 | } | 347 | return NULL; |
345 | 348 | } | |
349 | */ | ||
346 | /* Search a wireless tool and return its path */ | 350 | /* Search a wireless tool and return its path */ |
347 | static char * | 351 | /* |
348 | wiToolsPath(const char * tool) | 352 | static char * |
349 | { | 353 | wiToolsPath(const char * tool) |
350 | char * path; | 354 | { |
351 | int i, nbelems; | 355 | char * path; |
352 | static const char * paths[] = | 356 | int i, nbelems; |
353 | { "/sbin", "/usr/sbin", "/usr/local/sbin", "/bin", "/usr/bin", | 357 | static const char * paths[] = |
354 | "/usr/local/bin", "/tmp" }; | 358 | { "/sbin", "/usr/sbin", "/usr/local/sbin", "/bin", "/usr/bin", |
355 | 359 | "/usr/local/bin", "/tmp" }; | |
356 | nbelems = sizeof(paths) / sizeof(char *); | 360 | |
357 | 361 | nbelems = sizeof(paths) / sizeof(char *); | |
358 | for (i = 0; i < nbelems; i++) | 362 | |
359 | { | 363 | for (i = 0; i < nbelems; i++) |
360 | path = searchInside(paths[i], tool); | 364 | { |
361 | if (path != NULL) | 365 | path = searchInside(paths[i], tool); |
362 | return path; | 366 | if (path != NULL) |
363 | } | 367 | return path; |
364 | 368 | } | |
365 | return NULL; | 369 | |
366 | } | 370 | return NULL; |
371 | } | ||
372 | */ | ||
367 | 373 | ||
368 | static int | 374 | static int |
369 | linux_get_channel(struct Hardware_Infos *dev) | 375 | linux_get_channel(struct Hardware_Infos *dev) |
@@ -374,15 +380,17 @@ linux_get_channel(struct Hardware_Infos *dev) | |||
374 | 380 | ||
375 | memset(&wrq, 0, sizeof(struct iwreq)); | 381 | memset(&wrq, 0, sizeof(struct iwreq)); |
376 | 382 | ||
377 | if (dev->main_if) | 383 | /* |
378 | strncpy(wrq.ifr_name, dev->main_if, IFNAMSIZ ); | 384 | if (dev->main_if) |
379 | else | 385 | strncpy(wrq.ifr_name, dev->main_if, IFNAMSIZ ); |
380 | strncpy(wrq.ifr_name, dev->iface, IFNAMSIZ ); | 386 | else*/ |
387 | strncpy(wrq.ifr_name, dev->iface, IFNAMSIZ ); | ||
381 | 388 | ||
382 | fd = dev->fd_in; | 389 | fd = dev->fd_in; |
383 | if (dev->drivertype == DT_IPW2200) | 390 | /* |
384 | fd = dev->fd_main; | 391 | if (dev->drivertype == DT_IPW2200) |
385 | 392 | fd = dev->fd_main; | |
393 | */ | ||
386 | if (ioctl(fd, SIOCGIWFREQ, &wrq) < 0) | 394 | if (ioctl(fd, SIOCGIWFREQ, &wrq) < 0) |
387 | return (-1); | 395 | return (-1); |
388 | 396 | ||
@@ -770,43 +778,45 @@ int | |||
770 | wlaninit(struct Hardware_Infos * dev, char *iface) | 778 | wlaninit(struct Hardware_Infos * dev, char *iface) |
771 | { | 779 | { |
772 | 780 | ||
773 | char *iwpriv; | 781 | //char *iwpriv; |
774 | char strbuf[512]; | 782 | char strbuf[512]; |
775 | dev->inject_wlanng = 1; | 783 | //dev->inject_wlanng = 1; |
776 | dev->rate = 2; /* default to 1Mbps if nothing is set */ | 784 | //dev->rate = 2; /* default to 1Mbps if nothing is set */ |
777 | 785 | ||
778 | /* open raw socks */ | 786 | /* open raw socks */ |
779 | dev->fd_in = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); | 787 | /* |
780 | if (0 > dev->fd_in) | 788 | dev->fd_in = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); |
781 | { | 789 | if (0 > dev->fd_in) |
782 | perror("socket(PF_PACKET) failed at fd_in"); | 790 | { |
783 | if (getuid() != 0) | 791 | perror("socket(PF_PACKET) failed at fd_in"); |
784 | fprintf(stderr, "This program requires root privileges.\n"); | 792 | if (getuid() != 0) |
785 | return (1); | 793 | fprintf(stderr, "This program requires root privileges.\n"); |
786 | } | 794 | return (1); |
787 | 795 | } | |
788 | dev->fd_main = socket(PF_PACKET, SOCK_RAW, htons( ETH_P_ALL ) ); | 796 | */ |
789 | if (0 > dev->fd_main) | 797 | /* |
790 | { | 798 | dev->fd_main = socket(PF_PACKET, SOCK_RAW, htons( ETH_P_ALL ) ); |
791 | perror("socket(PF_PACKET) failed at fd_main"); | 799 | if (0 > dev->fd_main) |
792 | if (getuid() != 0) | 800 | { |
793 | fprintf(stderr, "This program requires root privileges.\n"); | 801 | perror("socket(PF_PACKET) failed at fd_main"); |
794 | return (1); | 802 | if (getuid() != 0) |
795 | } | 803 | fprintf(stderr, "This program requires root privileges.\n"); |
796 | 804 | return (1); | |
805 | } | ||
806 | */ | ||
797 | /* Check iwpriv existence */ | 807 | /* Check iwpriv existence */ |
808 | /* | ||
809 | iwpriv = wiToolsPath("iwpriv"); | ||
810 | dev->iwpriv = iwpriv; | ||
811 | dev->iwconfig = wiToolsPath("iwconfig"); | ||
812 | dev->ifconfig = wiToolsPath("ifconfig"); | ||
798 | 813 | ||
799 | iwpriv = wiToolsPath("iwpriv"); | 814 | if (!iwpriv) |
800 | dev->iwpriv = iwpriv; | 815 | { |
801 | dev->iwconfig = wiToolsPath("iwconfig"); | 816 | fprintf(stderr, "Can't find wireless tools, exiting.\n"); |
802 | dev->ifconfig = wiToolsPath("ifconfig"); | 817 | goto close_in; |
803 | 818 | } | |
804 | if (!iwpriv) | 819 | */ |
805 | { | ||
806 | fprintf(stderr, "Can't find wireless tools, exiting.\n"); | ||
807 | goto close_in; | ||
808 | } | ||
809 | |||
810 | dev->fd_out = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); | 820 | dev->fd_out = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); |
811 | if (0 > dev->fd_out) | 821 | if (0 > dev->fd_out) |
812 | { | 822 | { |
@@ -836,6 +846,7 @@ wlaninit(struct Hardware_Infos * dev, char *iface) | |||
836 | else | 846 | else |
837 | { | 847 | { |
838 | // At the moment only mac80211 tested | 848 | // At the moment only mac80211 tested |
849 | fprintf(stderr, "only mac80211 stack supported, exiting.\n"); | ||
839 | return 1; | 850 | return 1; |
840 | } | 851 | } |
841 | 852 | ||
@@ -844,14 +855,16 @@ wlaninit(struct Hardware_Infos * dev, char *iface) | |||
844 | szaDriverTypes[dev->drivertype]); | 855 | szaDriverTypes[dev->drivertype]); |
845 | #endif | 856 | #endif |
846 | 857 | ||
847 | if (openraw(dev, iface, dev->fd_out, &dev->arptype_out, dev->pl_mac) != 0) | 858 | if (openraw(dev, iface, dev->fd_out, &dev->arptype_in, dev->pl_mac) != 0) |
848 | { | 859 | { |
849 | goto close_out; | 860 | goto close_out; |
850 | } | 861 | } |
851 | 862 | ||
852 | dev->fd_in = dev->fd_out; | 863 | dev->fd_in = dev->fd_out; |
864 | dev->iface = GNUNET_malloc(sizeof(char) *6); | ||
865 | strncpy(dev->iface, iface, sizeof(char) * 6); | ||
853 | 866 | ||
854 | dev->arptype_in = dev->arptype_out; | 867 | //dev->arptype_out = dev->arptype_in; |
855 | 868 | ||
856 | return 0; | 869 | return 0; |
857 | close_out: close(dev->fd_out); | 870 | close_out: close(dev->fd_out); |
@@ -961,7 +974,7 @@ stdin_send_hw(void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | |||
961 | + sizeof(struct Radiotap_Send) + sizeof(struct GNUNET_MessageHeader), | 974 | + sizeof(struct Radiotap_Send) + sizeof(struct GNUNET_MessageHeader), |
962 | sendsize); | 975 | sendsize); |
963 | 976 | ||
964 | wlanheader = write_pout->buf + sizeof(u8aRadiotap); | 977 | wlanheader = write_pout->buf + sizeof(u8aRadiotap); |
965 | mac_set(wlanheader, dev); | 978 | mac_set(wlanheader, dev); |
966 | 979 | ||
967 | sendsize += sizeof(u8aRadiotap); | 980 | sendsize += sizeof(u8aRadiotap); |
@@ -974,7 +987,7 @@ stdin_send_hw(void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | |||
974 | write_pout->size = sendsize; | 987 | write_pout->size = sendsize; |
975 | } | 988 | } |
976 | 989 | ||
977 | int | 990 | static int |
978 | maketest(unsigned char * buf, struct Hardware_Infos * dev) | 991 | maketest(unsigned char * buf, struct Hardware_Infos * dev) |
979 | { | 992 | { |
980 | uint16_t * tmp16; | 993 | uint16_t * tmp16; |
@@ -1024,8 +1037,8 @@ maketest(unsigned char * buf, struct Hardware_Infos * dev) | |||
1024 | //0x00, 0x1f, 0x3f, 0xd1, 0x8e, 0xe6, // mac1 - in this case receiver | 1037 | //0x00, 0x1f, 0x3f, 0xd1, 0x8e, 0xe6, // mac1 - in this case receiver |
1025 | 0x00, 0x1d, 0xe0, 0xb0, 0x17, 0xdf, // mac1 - in this case receiver | 1038 | 0x00, 0x1d, 0xe0, 0xb0, 0x17, 0xdf, // mac1 - in this case receiver |
1026 | 0xC0, 0x3F, 0x0E, 0x44, 0x2D, 0x51, // mac2 - in this case sender | 1039 | 0xC0, 0x3F, 0x0E, 0x44, 0x2D, 0x51, // mac2 - in this case sender |
1027 | 0x02, 0x1d, 0xe0, 0x00, 0x01, 0xc4, | 1040 | //0x02, 0x1d, 0xe0, 0x00, 0x01, 0xc4, |
1028 | //0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac3 - in this case bssid | 1041 | 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac3 - in this case bssid |
1029 | 0x10, 0x86, //Sequence Control | 1042 | 0x10, 0x86, //Sequence Control |
1030 | }; | 1043 | }; |
1031 | if (first == 0) | 1044 | if (first == 0) |
@@ -1117,7 +1130,7 @@ hardwaremode(int argc, char *argv[]) | |||
1117 | write_pout.size = maketest(write_pout.buf, &dev); | 1130 | write_pout.size = maketest(write_pout.buf, &dev); |
1118 | tv.tv_sec = 2; | 1131 | tv.tv_sec = 2; |
1119 | tv.tv_usec = 0; | 1132 | tv.tv_usec = 0; |
1120 | retval = select(0, NULL, NULL, NULL, &tv); | 1133 | select(0, NULL, NULL, NULL, &tv); |
1121 | 1134 | ||
1122 | maxfd = 0; | 1135 | maxfd = 0; |
1123 | 1136 | ||
@@ -1172,7 +1185,7 @@ hardwaremode(int argc, char *argv[]) | |||
1172 | { | 1185 | { |
1173 | closeprog = 1; | 1186 | closeprog = 1; |
1174 | fprintf(stderr, "Write ERROR to STDOUT\n"); | 1187 | fprintf(stderr, "Write ERROR to STDOUT\n"); |
1175 | exit(1); | 1188 | goto end; |
1176 | } | 1189 | } |
1177 | else | 1190 | else |
1178 | { | 1191 | { |
@@ -1276,6 +1289,9 @@ hardwaremode(int argc, char *argv[]) | |||
1276 | GNUNET_SERVER_mst_destroy(stdin_mst); | 1289 | GNUNET_SERVER_mst_destroy(stdin_mst); |
1277 | return 0; | 1290 | return 0; |
1278 | 1291 | ||
1292 | end: GNUNET_SERVER_mst_destroy(stdin_mst); | ||
1293 | return 1; | ||
1294 | |||
1279 | } | 1295 | } |
1280 | 1296 | ||
1281 | int | 1297 | int |
diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c index 950ad9ccf..0564e9127 100644 --- a/src/transport/plugin_transport_wlan.c +++ b/src/transport/plugin_transport_wlan.c | |||
@@ -61,6 +61,7 @@ | |||
61 | #define HALLO_BEACON_SCALING_FACTOR 900 | 61 | #define HALLO_BEACON_SCALING_FACTOR 900 |
62 | 62 | ||
63 | #define DEBUG_wlan GNUNET_NO | 63 | #define DEBUG_wlan GNUNET_NO |
64 | #define DEBUG_wlan_retransmission GNUNET_NO | ||
64 | 65 | ||
65 | #define MESSAGE_LENGHT_UNKNOWN -1 | 66 | #define MESSAGE_LENGHT_UNKNOWN -1 |
66 | //#define NO_MESSAGE_OR_MESSAGE_FINISHED -2 | 67 | //#define NO_MESSAGE_OR_MESSAGE_FINISHED -2 |
@@ -194,17 +195,7 @@ struct Plugin | |||
194 | /** | 195 | /** |
195 | * Messages in the fragmentation queue, head | 196 | * Messages in the fragmentation queue, head |
196 | */ | 197 | */ |
197 | struct FragmentMessage * pending_Fragment_Messages_head; | 198 | struct GNUNET_CONTAINER_Heap * pending_Fragment_Messages; |
198 | |||
199 | /** | ||
200 | * Messages in the fragmentation queue, tail | ||
201 | */ | ||
202 | struct FragmentMessage * pending_Fragment_Messages_tail; | ||
203 | |||
204 | /** | ||
205 | * number of pending fragment message | ||
206 | */ | ||
207 | unsigned int pending_fragment_messages; | ||
208 | 199 | ||
209 | /** | 200 | /** |
210 | * Messages in the in Queue, head | 201 | * Messages in the in Queue, head |
@@ -247,6 +238,7 @@ struct Finish_send | |||
247 | char * msgheader; | 238 | char * msgheader; |
248 | struct GNUNET_MessageHeader * msgstart; | 239 | struct GNUNET_MessageHeader * msgstart; |
249 | ssize_t size; | 240 | ssize_t size; |
241 | struct GNUNET_TIME_Absolute next_send; | ||
250 | }; | 242 | }; |
251 | 243 | ||
252 | /** | 244 | /** |
@@ -273,6 +265,17 @@ struct Receive_Fragment_Queue | |||
273 | struct Radiotap_rx rxinfo; | 265 | struct Radiotap_rx rxinfo; |
274 | }; | 266 | }; |
275 | 267 | ||
268 | struct Session_id_pair | ||
269 | { | ||
270 | struct Session * session; | ||
271 | uint32_t message_id; | ||
272 | }; | ||
273 | |||
274 | struct Plugin_Session_pair | ||
275 | { | ||
276 | struct Plugin * plugin; | ||
277 | struct Session * session; | ||
278 | }; | ||
276 | 279 | ||
277 | /** | 280 | /** |
278 | * Queue for the fragments received | 281 | * Queue for the fragments received |
@@ -477,6 +480,11 @@ struct Session | |||
477 | struct FragmentMessage | 480 | struct FragmentMessage |
478 | { | 481 | { |
479 | /** | 482 | /** |
483 | * heap pointer of this message | ||
484 | */ | ||
485 | struct GNUNET_CONTAINER_HeapNode * node; | ||
486 | |||
487 | /** | ||
480 | * Session this message belongs to | 488 | * Session this message belongs to |
481 | */ | 489 | */ |
482 | 490 | ||
@@ -498,6 +506,13 @@ struct FragmentMessage | |||
498 | char *msg; | 506 | char *msg; |
499 | 507 | ||
500 | /** | 508 | /** |
509 | * 0 if not in ack queue | ||
510 | * 1 if in ack queue | ||
511 | */ | ||
512 | |||
513 | char in_ack_queue; | ||
514 | |||
515 | /** | ||
501 | * Timeout value for the pending message. | 516 | * Timeout value for the pending message. |
502 | */ | 517 | */ |
503 | struct GNUNET_TIME_Absolute timeout; | 518 | struct GNUNET_TIME_Absolute timeout; |
@@ -550,11 +565,10 @@ struct FragmentationAckHeader | |||
550 | 565 | ||
551 | }; | 566 | }; |
552 | 567 | ||
553 | static void | 568 | static struct FragmentMessage * return_val; |
554 | do_transmit(void *cls, | ||
555 | const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
556 | |||
557 | 569 | ||
570 | static void | ||
571 | do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
558 | 572 | ||
559 | /** | 573 | /** |
560 | * Sets a bit active in the bitArray. Increment bit-specific | 574 | * Sets a bit active in the bitArray. Increment bit-specific |
@@ -574,7 +588,6 @@ setBit(char *bitArray, unsigned int bitIdx) | |||
574 | bitArray[arraySlot] |= targetBit; | 588 | bitArray[arraySlot] |= targetBit; |
575 | } | 589 | } |
576 | 590 | ||
577 | |||
578 | /** | 591 | /** |
579 | * Checks if a bit is active in the bitArray | 592 | * Checks if a bit is active in the bitArray |
580 | * | 593 | * |
@@ -602,10 +615,9 @@ testBit(char *bitArray, unsigned int bitIdx) | |||
602 | static uint32_t | 615 | static uint32_t |
603 | get_next_message_id() | 616 | get_next_message_id() |
604 | { | 617 | { |
605 | return GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); | 618 | return GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); |
606 | } | 619 | } |
607 | 620 | ||
608 | |||
609 | /** | 621 | /** |
610 | * search for a session with the addr | 622 | * search for a session with the addr |
611 | * | 623 | * |
@@ -614,22 +626,50 @@ get_next_message_id() | |||
614 | * @return returns the session | 626 | * @return returns the session |
615 | */ | 627 | */ |
616 | static struct Session * | 628 | static struct Session * |
617 | search_session(struct Plugin *plugin, | 629 | search_session(struct Plugin *plugin, const struct MacAddress *addr) |
618 | const struct MacAddress *addr) | ||
619 | { | 630 | { |
620 | struct Sessionqueue * queue = plugin->sessions; | 631 | struct Sessionqueue * queue = plugin->sessions; |
621 | 632 | ||
622 | while (queue != NULL) | 633 | while (queue != NULL) |
623 | { | 634 | { |
624 | GNUNET_assert (queue->content != NULL); | 635 | GNUNET_assert (queue->content != NULL); |
625 | if (memcmp(addr, &queue->content->addr, sizeof (struct MacAddress)) == 0) | 636 | if (memcmp(addr, &queue->content->addr, sizeof(struct MacAddress)) == 0) |
626 | return queue->content; /* session found */ | 637 | return queue->content; /* session found */ |
627 | queue = queue->next; | 638 | queue = queue->next; |
628 | } | 639 | } |
629 | return NULL; | 640 | return NULL; |
630 | } | 641 | } |
631 | 642 | ||
632 | /** | 643 | /** |
644 | * Function called for a quick conversion of the binary address to | ||
645 | * a numeric address. Note that the caller must not free the | ||
646 | * address and that the next call to this function is allowed | ||
647 | * to override the address again. | ||
648 | * | ||
649 | * @param cls closure | ||
650 | * @param addr binary address | ||
651 | * @param addrlen length of the address | ||
652 | * @return string representing the same address | ||
653 | */ | ||
654 | static const char* | ||
655 | wlan_plugin_address_to_string(void *cls, const void *addr, size_t addrlen) | ||
656 | { | ||
657 | static char ret[40]; | ||
658 | const struct MacAddress *mac; | ||
659 | |||
660 | if (addrlen != sizeof(struct MacAddress)) | ||
661 | { | ||
662 | GNUNET_break (0); | ||
663 | return NULL; | ||
664 | } | ||
665 | mac = addr; | ||
666 | GNUNET_snprintf(ret, sizeof(ret), "%s Mac-Address %X:%X:%X:%X:%X:%X", | ||
667 | PROTOCOL_PREFIX, mac->mac[0], mac->mac[1], mac->mac[2], mac->mac[3], | ||
668 | mac->mac[4], mac->mac[5]); | ||
669 | return ret; | ||
670 | } | ||
671 | |||
672 | /** | ||
633 | * create a new session | 673 | * create a new session |
634 | * | 674 | * |
635 | * @param plugin pointer to the plugin struct | 675 | * @param plugin pointer to the plugin struct |
@@ -638,8 +678,7 @@ search_session(struct Plugin *plugin, | |||
638 | */ | 678 | */ |
639 | 679 | ||
640 | static struct Session * | 680 | static struct Session * |
641 | create_session(struct Plugin *plugin, | 681 | create_session(struct Plugin *plugin, const struct MacAddress * addr) |
642 | const struct MacAddress * addr) | ||
643 | { | 682 | { |
644 | struct Sessionqueue * queue = GNUNET_malloc (sizeof (struct Sessionqueue)); | 683 | struct Sessionqueue * queue = GNUNET_malloc (sizeof (struct Sessionqueue)); |
645 | 684 | ||
@@ -661,7 +700,6 @@ create_session(struct Plugin *plugin, | |||
661 | return queue->content; | 700 | return queue->content; |
662 | } | 701 | } |
663 | 702 | ||
664 | |||
665 | /** | 703 | /** |
666 | * Get session from address, create if no session exists | 704 | * Get session from address, create if no session exists |
667 | * | 705 | * |
@@ -670,8 +708,7 @@ create_session(struct Plugin *plugin, | |||
670 | * @return returns the session | 708 | * @return returns the session |
671 | */ | 709 | */ |
672 | static struct Session * | 710 | static struct Session * |
673 | get_Session (struct Plugin *plugin, | 711 | get_session(struct Plugin *plugin, const struct MacAddress *addr) |
674 | const struct MacAddress *addr) | ||
675 | { | 712 | { |
676 | struct Session * session = search_session(plugin, addr); | 713 | struct Session * session = search_session(plugin, addr); |
677 | if (session != NULL) | 714 | if (session != NULL) |
@@ -679,41 +716,45 @@ get_Session (struct Plugin *plugin, | |||
679 | return create_session(plugin, addr); | 716 | return create_session(plugin, addr); |
680 | } | 717 | } |
681 | 718 | ||
682 | |||
683 | /** | 719 | /** |
684 | * Queue the session to send data | 720 | * Queue the session to send data |
721 | * checks if there is a message pending | ||
722 | * checks if this session is not allready in the queue | ||
723 | * @param plugin pointer to the plugin | ||
724 | * @param session pointer to the session to add | ||
685 | */ | 725 | */ |
686 | //TODO doxigen | ||
687 | static void | 726 | static void |
688 | queue_Session(struct Plugin *plugin, struct Session * session) | 727 | queue_session(struct Plugin *plugin, struct Session * session) |
689 | { | 728 | { |
690 | struct Sessionqueue * queue = plugin->pending_Sessions; | 729 | struct Sessionqueue * queue = plugin->pending_Sessions; |
691 | struct Sessionqueue * lastitem = NULL; | 730 | struct Sessionqueue * lastitem = NULL; |
692 | 731 | ||
693 | while (queue != NULL) | 732 | if (session->pending_message != NULL) |
694 | { | 733 | { |
695 | // content is never NULL | 734 | while (queue != NULL) |
696 | GNUNET_assert (queue->content != NULL); | ||
697 | // is session already in queue? | ||
698 | if (session == queue->content) | ||
699 | { | 735 | { |
700 | return; | 736 | // content is never NULL |
737 | GNUNET_assert (queue->content != NULL); | ||
738 | // is session already in queue? | ||
739 | if (session == queue->content) | ||
740 | { | ||
741 | return; | ||
742 | } | ||
743 | // try next | ||
744 | lastitem = queue; | ||
745 | queue = queue->next; | ||
701 | } | 746 | } |
702 | // try next | ||
703 | lastitem = queue; | ||
704 | queue = queue->next; | ||
705 | } | ||
706 | 747 | ||
707 | // Session is not in the queue | 748 | // Session is not in the queue |
708 | 749 | ||
709 | queue = GNUNET_malloc (sizeof (struct Sessionqueue)); | 750 | queue = GNUNET_malloc (sizeof (struct Sessionqueue)); |
710 | queue->content = session; | 751 | queue->content = session; |
711 | 752 | ||
712 | //insert at the tail | 753 | //insert at the tail |
713 | GNUNET_CONTAINER_DLL_insert_after (plugin->pending_Sessions, | 754 | GNUNET_CONTAINER_DLL_insert_tail(plugin->pending_Sessions, |
714 | plugin->pending_Sessions_tail, | 755 | plugin->pending_Sessions_tail, queue); |
715 | plugin->pending_Sessions_tail, queue); | 756 | plugin->pendingsessions++; |
716 | plugin->pendingsessions++; | 757 | } |
717 | 758 | ||
718 | } | 759 | } |
719 | 760 | ||
@@ -792,11 +833,12 @@ get_ack_timeout(struct FragmentMessage * fm) | |||
792 | * Function to set the timer for the next timeout of the fragment queue | 833 | * Function to set the timer for the next timeout of the fragment queue |
793 | * @param plugin the handle to the plugin struct | 834 | * @param plugin the handle to the plugin struct |
794 | */ | 835 | */ |
836 | |||
795 | static void | 837 | static void |
796 | check_next_fragment_timeout(struct Plugin * const plugin) | 838 | set_next_send(struct Plugin * const plugin) |
797 | { | 839 | { |
798 | struct FragmentMessage * fm; | 840 | struct FragmentMessage * fm; |
799 | struct GNUNET_TIME_Relative next_send; | 841 | struct GNUNET_TIME_Relative next_send = GNUNET_TIME_UNIT_FOREVER_REL; |
800 | 842 | ||
801 | //cancel old task | 843 | //cancel old task |
802 | if (plugin->server_write_delay_task != GNUNET_SCHEDULER_NO_TASK) | 844 | if (plugin->server_write_delay_task != GNUNET_SCHEDULER_NO_TASK) |
@@ -804,36 +846,52 @@ check_next_fragment_timeout(struct Plugin * const plugin) | |||
804 | GNUNET_SCHEDULER_cancel(plugin->server_write_delay_task); | 846 | GNUNET_SCHEDULER_cancel(plugin->server_write_delay_task); |
805 | plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK; | 847 | plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK; |
806 | } | 848 | } |
807 | fm = plugin->pending_Fragment_Messages_head; | ||
808 | 849 | ||
809 | GNUNET_assert(plugin->server_write_delay_task == GNUNET_SCHEDULER_NO_TASK); | 850 | fm = GNUNET_CONTAINER_heap_peek(plugin->pending_Fragment_Messages); |
810 | 851 | ||
811 | //check if some acks are in the queue | 852 | //check if some acks are in the queue |
812 | if (plugin->ack_send_queue_head != NULL) | 853 | if (plugin->ack_send_queue_head != NULL) |
813 | { | 854 | { |
814 | next_send = GNUNET_TIME_UNIT_ZERO; | 855 | next_send = GNUNET_TIME_UNIT_ZERO; |
815 | } | 856 | } |
857 | |||
816 | //check if there are some fragments in the queue | 858 | //check if there are some fragments in the queue |
817 | else | 859 | else |
818 | { | 860 | { |
819 | next_send = GNUNET_TIME_absolute_get_remaining(plugin->beacon_time); | 861 | next_send = GNUNET_TIME_absolute_get_remaining(plugin->beacon_time); |
820 | if (fm != NULL) | 862 | if (fm != NULL) |
821 | { | 863 | { |
822 | next_send = GNUNET_TIME_relative_min(next_send, | 864 | if (GNUNET_CONTAINER_node_get_cost(fm->node) != 0) |
823 | get_next_frag_timeout(fm)); | 865 | { |
866 | next_send = GNUNET_TIME_relative_min(next_send, | ||
867 | get_next_frag_timeout(fm)); | ||
868 | } | ||
869 | else | ||
870 | { | ||
871 | next_send = GNUNET_TIME_UNIT_ZERO; | ||
872 | } | ||
824 | } | 873 | } |
825 | } | 874 | } |
875 | |||
876 | #if DEBUG_wlan | ||
877 | |||
878 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Next packet is send in: %u\n", | ||
879 | next_send.rel_value); | ||
880 | |||
881 | #endif | ||
882 | |||
826 | plugin->server_write_delay_task = GNUNET_SCHEDULER_add_delayed(next_send, | 883 | plugin->server_write_delay_task = GNUNET_SCHEDULER_add_delayed(next_send, |
827 | &delay_fragment_task, plugin); | 884 | &delay_fragment_task, plugin); |
885 | |||
828 | } | 886 | } |
829 | 887 | ||
830 | //TODO doxigen | ||
831 | /** | 888 | /** |
832 | * Function to get the next queued Session, removes the session from the queue | 889 | * Function to get the next queued Session, removes the session from the queue |
890 | * @param plugin pointer to the plugin struct | ||
891 | * @return pointer to the session found, returns NULL if there is now session in the queue | ||
833 | */ | 892 | */ |
834 | |||
835 | static struct Session * | 893 | static struct Session * |
836 | get_next_queue_Session(struct Plugin * plugin) | 894 | get_next_queue_session(struct Plugin * plugin) |
837 | { | 895 | { |
838 | struct Session * session; | 896 | struct Session * session; |
839 | struct Sessionqueue * sessionqueue; | 897 | struct Sessionqueue * sessionqueue; |
@@ -845,14 +903,15 @@ get_next_queue_Session(struct Plugin * plugin) | |||
845 | session = sessionqueue->content; | 903 | session = sessionqueue->content; |
846 | 904 | ||
847 | pm = session->pending_message; | 905 | pm = session->pending_message; |
906 | |||
907 | #if DEBUG_wlan | ||
848 | if (pm == NULL) | 908 | if (pm == NULL) |
849 | { | 909 | { |
850 | #if DEBUG_wlan | ||
851 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 910 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
852 | "pending message is empty, should not happen. session %p\n", | 911 | "pending message is empty, should not happen. session %p\n", |
853 | session); | 912 | session); |
854 | #endif | ||
855 | } | 913 | } |
914 | #endif | ||
856 | GNUNET_assert(pm != NULL); | 915 | GNUNET_assert(pm != NULL); |
857 | 916 | ||
858 | //check for message timeout | 917 | //check for message timeout |
@@ -905,38 +964,6 @@ get_next_queue_Session(struct Plugin * plugin) | |||
905 | } | 964 | } |
906 | 965 | ||
907 | /** | 966 | /** |
908 | * Function to sort the message into the message fragment queue | ||
909 | * @param plugin the plugin struct | ||
910 | * @param fm message to sort into the queue | ||
911 | */ | ||
912 | static void | ||
913 | sort_fragment_into_queue(struct Plugin * plugin, struct FragmentMessage * fm) | ||
914 | { | ||
915 | struct FragmentMessage * fm2; | ||
916 | //sort into the list at the right position | ||
917 | |||
918 | fm2 = plugin->pending_Fragment_Messages_head; | ||
919 | |||
920 | while (fm2 != NULL) | ||
921 | { | ||
922 | if (GNUNET_TIME_absolute_get_difference(fm2->next_ack, fm->next_ack).rel_value | ||
923 | == 0) | ||
924 | { | ||
925 | GNUNET_CONTAINER_DLL_insert_before(plugin->pending_Fragment_Messages_head, | ||
926 | plugin->pending_Fragment_Messages_tail,fm2,fm); | ||
927 | return; | ||
928 | } | ||
929 | else | ||
930 | { | ||
931 | fm2 = fm2->next; | ||
932 | } | ||
933 | } | ||
934 | |||
935 | GNUNET_CONTAINER_DLL_insert_tail(plugin->pending_Fragment_Messages_head, | ||
936 | plugin->pending_Fragment_Messages_tail,fm); | ||
937 | } | ||
938 | |||
939 | /** | ||
940 | * frees the space of a message in the fragment queue (send queue) | 967 | * frees the space of a message in the fragment queue (send queue) |
941 | * @param plugin the plugin struct | 968 | * @param plugin the plugin struct |
942 | * @param fm message to free | 969 | * @param fm message to free |
@@ -944,19 +971,20 @@ sort_fragment_into_queue(struct Plugin * plugin, struct FragmentMessage * fm) | |||
944 | static void | 971 | static void |
945 | free_fragment_message(struct Plugin * plugin, struct FragmentMessage * fm) | 972 | free_fragment_message(struct Plugin * plugin, struct FragmentMessage * fm) |
946 | { | 973 | { |
974 | struct Session * session = fm->session; | ||
975 | |||
947 | if (fm != NULL) | 976 | if (fm != NULL) |
948 | { | 977 | { |
949 | (fm->session->fragment_messages_out_count)--; | 978 | (session->fragment_messages_out_count)--; |
950 | GNUNET_free_non_null(fm->msg); | 979 | GNUNET_free_non_null(fm->msg); |
951 | GNUNET_CONTAINER_DLL_remove (plugin->pending_Fragment_Messages_head, | 980 | GNUNET_CONTAINER_heap_remove_node(fm->node); |
952 | plugin->pending_Fragment_Messages_tail, fm); | ||
953 | GNUNET_free(fm); | 981 | GNUNET_free(fm); |
954 | plugin->pending_fragment_messages--; | ||
955 | 982 | ||
983 | queue_session(plugin, session); | ||
956 | #if DEBUG_wlan | 984 | #if DEBUG_wlan |
957 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 985 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
958 | "free pending fragment messages, pending messages remaining %u\n", | 986 | "free pending fragment messages, pending messages remaining %u\n", |
959 | plugin->pending_fragment_messages); | 987 | GNUNET_CONTAINER_heap_get_size(plugin->pending_Fragment_Messages)); |
960 | #endif | 988 | #endif |
961 | } | 989 | } |
962 | } | 990 | } |
@@ -976,9 +1004,10 @@ check_fragment_queue(struct Plugin * plugin) | |||
976 | 1004 | ||
977 | struct PendingMessage * pm; | 1005 | struct PendingMessage * pm; |
978 | 1006 | ||
979 | if (plugin->pending_fragment_messages < FRAGMENT_QUEUE_SIZE) | 1007 | if (GNUNET_CONTAINER_heap_get_size(plugin->pending_Fragment_Messages) |
1008 | < FRAGMENT_QUEUE_SIZE) | ||
980 | { | 1009 | { |
981 | session = get_next_queue_Session(plugin); | 1010 | session = get_next_queue_session(plugin); |
982 | if (session != NULL) | 1011 | if (session != NULL) |
983 | { | 1012 | { |
984 | pm = session->pending_message; | 1013 | pm = session->pending_message; |
@@ -995,9 +1024,8 @@ check_fragment_queue(struct Plugin * plugin) | |||
995 | fm->next_ack = GNUNET_TIME_absolute_get(); | 1024 | fm->next_ack = GNUNET_TIME_absolute_get(); |
996 | fm->message_id_out = get_next_message_id(); | 1025 | fm->message_id_out = get_next_message_id(); |
997 | fm->ack_bitfield = 0; | 1026 | fm->ack_bitfield = 0; |
998 | 1027 | fm->node = GNUNET_CONTAINER_heap_insert( | |
999 | sort_fragment_into_queue(plugin, fm); | 1028 | plugin->pending_Fragment_Messages, fm, 0); |
1000 | plugin->pending_fragment_messages++; | ||
1001 | 1029 | ||
1002 | if (pm->transmit_cont != NULL) | 1030 | if (pm->transmit_cont != NULL) |
1003 | { | 1031 | { |
@@ -1022,13 +1050,14 @@ check_fragment_queue(struct Plugin * plugin) | |||
1022 | session->pending_message = session->pending_message2; | 1050 | session->pending_message = session->pending_message2; |
1023 | session->pending_message2 = NULL; | 1051 | session->pending_message2 = NULL; |
1024 | //requeue session | 1052 | //requeue session |
1025 | queue_Session(plugin, session); | 1053 | queue_session(plugin, session); |
1026 | } | 1054 | } |
1027 | 1055 | ||
1028 | //check if timeout changed | ||
1029 | check_next_fragment_timeout(plugin); | ||
1030 | } | 1056 | } |
1031 | } | 1057 | } |
1058 | |||
1059 | //check if timeout changed | ||
1060 | set_next_send(plugin); | ||
1032 | } | 1061 | } |
1033 | 1062 | ||
1034 | /** | 1063 | /** |
@@ -1056,14 +1085,16 @@ check_finished_fragment(struct Plugin * plugin, struct FragmentMessage * fm) | |||
1056 | if (fm->ack_bitfield == tmpfield) | 1085 | if (fm->ack_bitfield == tmpfield) |
1057 | { | 1086 | { |
1058 | 1087 | ||
1059 | free_fragment_message(plugin, fm); | 1088 | #if DEBUG_wlan_retransmission |
1060 | |||
1061 | #if DEBUG_wlan | ||
1062 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1089 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1063 | "Finished sending and got all acks for a fragmented message\n"); | 1090 | "Finished sending and got all acks; message_id %u\n", |
1091 | fm->message_id_out); | ||
1064 | #endif | 1092 | #endif |
1065 | 1093 | ||
1066 | check_next_fragment_timeout(plugin); | 1094 | free_fragment_message(plugin, fm); |
1095 | |||
1096 | |||
1097 | |||
1067 | check_fragment_queue(plugin); | 1098 | check_fragment_queue(plugin); |
1068 | 1099 | ||
1069 | } | 1100 | } |
@@ -1075,9 +1106,12 @@ check_finished_fragment(struct Plugin * plugin, struct FragmentMessage * fm) | |||
1075 | */ | 1106 | */ |
1076 | 1107 | ||
1077 | static void | 1108 | static void |
1078 | set_next_message_fragment_pos(struct FragmentMessage * fm) | 1109 | set_next_message_fragment_pos(struct Plugin * plugin, |
1110 | struct FragmentMessage * fm) | ||
1079 | { | 1111 | { |
1080 | 1112 | ||
1113 | fm->message_pos++; | ||
1114 | |||
1081 | //check if retransmit is needed | 1115 | //check if retransmit is needed |
1082 | if (GNUNET_TIME_absolute_get_remaining(fm->next_ack).rel_value == 0) | 1116 | if (GNUNET_TIME_absolute_get_remaining(fm->next_ack).rel_value == 0) |
1083 | { | 1117 | { |
@@ -1087,6 +1121,15 @@ set_next_message_fragment_pos(struct FragmentMessage * fm) | |||
1087 | // find first missing fragment | 1121 | // find first missing fragment |
1088 | 1122 | ||
1089 | fm->message_pos = 0; | 1123 | fm->message_pos = 0; |
1124 | |||
1125 | GNUNET_CONTAINER_heap_update_cost(plugin->pending_Fragment_Messages, | ||
1126 | fm->node, 0); | ||
1127 | |||
1128 | #if DEBUG_wlan_retransmission | ||
1129 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
1130 | "Retransmit; message_id %u; fragment number %i, size: %u\n", | ||
1131 | fm->message_id_out, fm->message_pos, fm->message_size); | ||
1132 | #endif | ||
1090 | } | 1133 | } |
1091 | 1134 | ||
1092 | //test if ack 0 (or X) was already received | 1135 | //test if ack 0 (or X) was already received |
@@ -1118,7 +1161,6 @@ getRadiotapHeader(struct Plugin * plugin, struct Session * session, | |||
1118 | return GNUNET_YES; | 1161 | return GNUNET_YES; |
1119 | } | 1162 | } |
1120 | 1163 | ||
1121 | |||
1122 | /** | 1164 | /** |
1123 | * function to generate the wlan hardware header for one packet | 1165 | * function to generate the wlan hardware header for one packet |
1124 | * @param Header address to write the header to | 1166 | * @param Header address to write the header to |
@@ -1127,9 +1169,8 @@ getRadiotapHeader(struct Plugin * plugin, struct Session * session, | |||
1127 | * @return GNUNET_YES if there was no error | 1169 | * @return GNUNET_YES if there was no error |
1128 | */ | 1170 | */ |
1129 | static int | 1171 | static int |
1130 | getWlanHeader(struct ieee80211_frame * Header, | 1172 | getWlanHeader(struct ieee80211_frame * Header, |
1131 | const struct MacAddress * to_mac_addr, | 1173 | const struct MacAddress * to_mac_addr, struct Plugin * plugin) |
1132 | struct Plugin * plugin) | ||
1133 | { | 1174 | { |
1134 | Header->i_fc[0] = 0x80; | 1175 | Header->i_fc[0] = 0x80; |
1135 | Header->i_fc[1] = 0x00; | 1176 | Header->i_fc[1] = 0x00; |
@@ -1171,7 +1212,6 @@ getcrc16(const char *msgbuf, size_t msgbuf_size) | |||
1171 | return 0; | 1212 | return 0; |
1172 | } | 1213 | } |
1173 | 1214 | ||
1174 | |||
1175 | static void | 1215 | static void |
1176 | send_hello_beacon(struct Plugin * plugin) | 1216 | send_hello_beacon(struct Plugin * plugin) |
1177 | { | 1217 | { |
@@ -1182,16 +1222,17 @@ send_hello_beacon(struct Plugin * plugin) | |||
1182 | 1222 | ||
1183 | uint16_t size; | 1223 | uint16_t size; |
1184 | ssize_t bytes; | 1224 | ssize_t bytes; |
1225 | uint16_t hallo_size; | ||
1185 | struct GNUNET_MessageHeader * msgheader; | 1226 | struct GNUNET_MessageHeader * msgheader; |
1186 | struct ieee80211_frame * ieeewlanheader; | 1227 | struct ieee80211_frame * ieeewlanheader; |
1187 | struct Radiotap_Send * radioHeader; | 1228 | struct Radiotap_Send * radioHeader; |
1188 | struct GNUNET_MessageHeader * msgheader2; | 1229 | struct GNUNET_MessageHeader * msgheader2; |
1189 | 1230 | ||
1190 | GNUNET_assert(sizeof(struct WlanHeader) + GNUNET_HELLO_size( | 1231 | hallo_size = GNUNET_HELLO_size(*(plugin->env->our_hello)); |
1191 | *(plugin->env->our_hello)) <= WLAN_MTU); | 1232 | GNUNET_assert(sizeof(struct WlanHeader) + hallo_size <= WLAN_MTU); |
1192 | size = sizeof(struct GNUNET_MessageHeader) + sizeof(struct Radiotap_Send) | 1233 | size = sizeof(struct GNUNET_MessageHeader) + sizeof(struct Radiotap_Send) |
1193 | + sizeof(struct ieee80211_frame) + sizeof(struct GNUNET_MessageHeader) | 1234 | + sizeof(struct ieee80211_frame) + sizeof(struct GNUNET_MessageHeader) |
1194 | + GNUNET_HELLO_size(*(plugin->env->our_hello)); | 1235 | + hallo_size; |
1195 | 1236 | ||
1196 | msgheader = GNUNET_malloc(size); | 1237 | msgheader = GNUNET_malloc(size); |
1197 | msgheader->size = htons(size); | 1238 | msgheader->size = htons(size); |
@@ -1207,8 +1248,7 @@ send_hello_beacon(struct Plugin * plugin) | |||
1207 | + sizeof(struct GNUNET_MessageHeader)); | 1248 | + sizeof(struct GNUNET_MessageHeader)); |
1208 | 1249 | ||
1209 | msgheader2->type = htons(GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT); | 1250 | msgheader2->type = htons(GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT); |
1210 | memcpy(&msgheader2[1], *plugin->env->our_hello, GNUNET_HELLO_size( | 1251 | memcpy(&msgheader2[1], *plugin->env->our_hello, hallo_size); |
1211 | *(plugin->env->our_hello))); | ||
1212 | 1252 | ||
1213 | bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, msgheader, size); | 1253 | bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, msgheader, size); |
1214 | 1254 | ||
@@ -1224,7 +1264,7 @@ send_hello_beacon(struct Plugin * plugin) | |||
1224 | GNUNET_free(msgheader); | 1264 | GNUNET_free(msgheader); |
1225 | 1265 | ||
1226 | set_next_beacon_time(plugin); | 1266 | set_next_beacon_time(plugin); |
1227 | check_next_fragment_timeout(plugin); | 1267 | set_next_send(plugin); |
1228 | } | 1268 | } |
1229 | 1269 | ||
1230 | static void | 1270 | static void |
@@ -1276,7 +1316,7 @@ send_ack(struct Plugin * plugin, struct AckSendQueue * ack) | |||
1276 | GNUNET_assert(bytes != GNUNET_SYSERR); | 1316 | GNUNET_assert(bytes != GNUNET_SYSERR); |
1277 | GNUNET_assert(bytes == size); | 1317 | GNUNET_assert(bytes == size); |
1278 | GNUNET_free(msgheader); | 1318 | GNUNET_free(msgheader); |
1279 | check_next_fragment_timeout(plugin); | 1319 | set_next_send(plugin); |
1280 | } | 1320 | } |
1281 | 1321 | ||
1282 | static void | 1322 | static void |
@@ -1295,7 +1335,6 @@ finish_sending(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1295 | finish->msgheader, finish->size); | 1335 | finish->msgheader, finish->size); |
1296 | GNUNET_assert(bytes != GNUNET_SYSERR); | 1336 | GNUNET_assert(bytes != GNUNET_SYSERR); |
1297 | 1337 | ||
1298 | GNUNET_assert(plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK); | ||
1299 | if (bytes != finish->size) | 1338 | if (bytes != finish->size) |
1300 | { | 1339 | { |
1301 | 1340 | ||
@@ -1309,12 +1348,12 @@ finish_sending(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1309 | { | 1348 | { |
1310 | GNUNET_free(finish->msgstart); | 1349 | GNUNET_free(finish->msgstart); |
1311 | GNUNET_free(finish); | 1350 | GNUNET_free(finish); |
1312 | check_next_fragment_timeout(plugin); | ||
1313 | } | ||
1314 | 1351 | ||
1315 | } | 1352 | set_next_send(plugin); |
1316 | 1353 | ||
1354 | } | ||
1317 | 1355 | ||
1356 | } | ||
1318 | 1357 | ||
1319 | /** | 1358 | /** |
1320 | * Function called when wlan helper is ready to get some data | 1359 | * Function called when wlan helper is ready to get some data |
@@ -1332,21 +1371,22 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1332 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) | 1371 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) |
1333 | return; | 1372 | return; |
1334 | 1373 | ||
1335 | struct Session * session = NULL; | 1374 | struct Session * session; |
1336 | struct FragmentMessage * fm = NULL; | 1375 | struct FragmentMessage * fm; |
1337 | struct ieee80211_frame * ieeewlanheader = NULL; | 1376 | struct ieee80211_frame * ieeewlanheader; |
1338 | struct Radiotap_Send * radioHeader = NULL; | 1377 | struct Radiotap_Send * radioHeader; |
1339 | struct GNUNET_MessageHeader * msgheader = NULL; | 1378 | struct GNUNET_MessageHeader * msgheader; |
1340 | 1379 | ||
1341 | struct FragmentationHeader fragheader; | 1380 | struct FragmentationHeader fragheader; |
1342 | struct FragmentationHeader * fragheaderptr = NULL; | 1381 | struct FragmentationHeader * fragheaderptr; |
1343 | struct Finish_send * finish = NULL; | 1382 | struct Finish_send * finish; |
1344 | struct AckSendQueue * ack; | 1383 | struct AckSendQueue * ack; |
1345 | uint16_t size = 0; | 1384 | uint16_t size; |
1346 | ssize_t bytes; | 1385 | ssize_t bytes; |
1347 | const char * copystart = NULL; | 1386 | const char * copystart; |
1348 | uint16_t copysize = 0; | 1387 | uint16_t copysize; |
1349 | uint copyoffset = 0; | 1388 | uint copyoffset; |
1389 | struct GNUNET_TIME_Absolute next_send; | ||
1350 | 1390 | ||
1351 | if (plugin->ack_send_queue_head != NULL) | 1391 | if (plugin->ack_send_queue_head != NULL) |
1352 | { | 1392 | { |
@@ -1367,7 +1407,8 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1367 | 1407 | ||
1368 | } | 1408 | } |
1369 | 1409 | ||
1370 | fm = plugin->pending_Fragment_Messages_head; | 1410 | fm = GNUNET_CONTAINER_heap_peek(plugin->pending_Fragment_Messages); |
1411 | |||
1371 | if (fm != NULL) | 1412 | if (fm != NULL) |
1372 | { | 1413 | { |
1373 | session = fm->session; | 1414 | session = fm->session; |
@@ -1380,8 +1421,8 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1380 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "message timeout\n"); | 1421 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "message timeout\n"); |
1381 | #endif | 1422 | #endif |
1382 | 1423 | ||
1383 | check_fragment_queue(plugin); | ||
1384 | free_fragment_message(plugin, fm); | 1424 | free_fragment_message(plugin, fm); |
1425 | check_fragment_queue(plugin); | ||
1385 | 1426 | ||
1386 | } | 1427 | } |
1387 | else | 1428 | else |
@@ -1391,13 +1432,11 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1391 | // { | 1432 | // { |
1392 | size = sizeof(struct FragmentationHeader); | 1433 | size = sizeof(struct FragmentationHeader); |
1393 | 1434 | ||
1394 | set_next_message_fragment_pos(fm); | 1435 | set_next_message_fragment_pos(plugin, fm); |
1395 | 1436 | ||
1396 | copyoffset = (WLAN_MTU - sizeof(struct FragmentationHeader)) | 1437 | copyoffset = (WLAN_MTU - sizeof(struct FragmentationHeader)) |
1397 | * fm->message_pos; | 1438 | * fm->message_pos; |
1398 | 1439 | ||
1399 | |||
1400 | |||
1401 | fragheader.fragment_off_or_num = htons(fm->message_pos); | 1440 | fragheader.fragment_off_or_num = htons(fm->message_pos); |
1402 | fragheader.message_id = htonl(fm->message_id_out); | 1441 | fragheader.message_id = htonl(fm->message_id_out); |
1403 | copystart = fm->msg + copyoffset; | 1442 | copystart = fm->msg + copyoffset; |
@@ -1478,6 +1517,27 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1478 | } | 1517 | } |
1479 | GNUNET_assert(bytes != GNUNET_SYSERR); | 1518 | GNUNET_assert(bytes != GNUNET_SYSERR); |
1480 | 1519 | ||
1520 | //check if this was the last fragment of this message, if true then queue at the end of the list | ||
1521 | if (copysize + copyoffset >= fm->message_size) | ||
1522 | { | ||
1523 | GNUNET_assert(copysize + copyoffset == fm->message_size); | ||
1524 | |||
1525 | GNUNET_CONTAINER_heap_update_cost( | ||
1526 | plugin->pending_Fragment_Messages, fm->node, MIN( | ||
1527 | fm->timeout.abs_value, fm->next_ack.abs_value)); | ||
1528 | // if fragments have opimized timeouts | ||
1529 | //sort_fragment_into_queue(plugin,fm); | ||
1530 | |||
1531 | #if DEBUG_wlan_retransmission | ||
1532 | GNUNET_log( | ||
1533 | GNUNET_ERROR_TYPE_DEBUG, | ||
1534 | "Finished sending all fragments waiting for acks; message_id %u; message_id %u; fragment number %i, size: %u, time until timeout %u\n", | ||
1535 | fm->message_id_out, fm->message_id_out, fm->message_pos, | ||
1536 | fm->message_size, GNUNET_TIME_absolute_get_remaining( | ||
1537 | fm->timeout)); | ||
1538 | #endif | ||
1539 | } | ||
1540 | |||
1481 | if (bytes != size) | 1541 | if (bytes != size) |
1482 | { | 1542 | { |
1483 | finish = GNUNET_malloc(sizeof( struct Finish_send)); | 1543 | finish = GNUNET_malloc(sizeof( struct Finish_send)); |
@@ -1485,6 +1545,7 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1485 | finish->msgheader = (char *) msgheader + bytes; | 1545 | finish->msgheader = (char *) msgheader + bytes; |
1486 | finish->size = size - bytes; | 1546 | finish->size = size - bytes; |
1487 | finish->msgstart = msgheader; | 1547 | finish->msgstart = msgheader; |
1548 | finish ->next_send = next_send; | ||
1488 | 1549 | ||
1489 | GNUNET_assert(plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK); | 1550 | GNUNET_assert(plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK); |
1490 | 1551 | ||
@@ -1496,24 +1557,8 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1496 | else | 1557 | else |
1497 | { | 1558 | { |
1498 | GNUNET_assert(bytes == size); | 1559 | GNUNET_assert(bytes == size); |
1499 | |||
1500 | GNUNET_free(msgheader); | 1560 | GNUNET_free(msgheader); |
1501 | check_next_fragment_timeout(plugin); | 1561 | set_next_send(plugin); |
1502 | } | ||
1503 | |||
1504 | //check if this was the last fragment of this message, if true then queue at the end of the list | ||
1505 | if (copysize + copyoffset >= fm->message_size) | ||
1506 | { | ||
1507 | GNUNET_assert(copysize + copyoffset == fm->message_size); | ||
1508 | |||
1509 | GNUNET_CONTAINER_DLL_remove (plugin->pending_Fragment_Messages_head, | ||
1510 | plugin->pending_Fragment_Messages_tail, fm); | ||
1511 | |||
1512 | GNUNET_CONTAINER_DLL_insert_tail(plugin->pending_Fragment_Messages_head, | ||
1513 | plugin->pending_Fragment_Messages_tail, fm); | ||
1514 | // if fragments have opimized timeouts | ||
1515 | //sort_fragment_into_queue(plugin,fm); | ||
1516 | |||
1517 | } | 1562 | } |
1518 | 1563 | ||
1519 | } | 1564 | } |
@@ -1523,7 +1568,6 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1523 | "do_transmit did nothing, should not happen!\n"); | 1568 | "do_transmit did nothing, should not happen!\n"); |
1524 | } | 1569 | } |
1525 | 1570 | ||
1526 | |||
1527 | /** | 1571 | /** |
1528 | * Another peer has suggested an address for this | 1572 | * Another peer has suggested an address for this |
1529 | * peer and transport plugin. Check that this could be a valid | 1573 | * peer and transport plugin. Check that this could be a valid |
@@ -1556,8 +1600,6 @@ wlan_plugin_address_suggested(void *cls, const void *addr, size_t addrlen) | |||
1556 | return GNUNET_SYSERR; | 1600 | return GNUNET_SYSERR; |
1557 | } | 1601 | } |
1558 | 1602 | ||
1559 | |||
1560 | |||
1561 | /** | 1603 | /** |
1562 | * Function that can be used by the transport service to transmit | 1604 | * Function that can be used by the transport service to transmit |
1563 | * a message using the plugin. | 1605 | * a message using the plugin. |
@@ -1567,7 +1609,7 @@ wlan_plugin_address_suggested(void *cls, const void *addr, size_t addrlen) | |||
1567 | * @param priority how important is the message | 1609 | * @param priority how important is the message |
1568 | * @param msgbuf the message to transmit | 1610 | * @param msgbuf the message to transmit |
1569 | * @param msgbuf_size number of bytes in 'msgbuf' | 1611 | * @param msgbuf_size number of bytes in 'msgbuf' |
1570 | * @param timeout when should we time out | 1612 | * @param timeout when should we time out |
1571 | * @param session which session must be used (or NULL for "any") | 1613 | * @param session which session must be used (or NULL for "any") |
1572 | * @param addr the address to use (can be NULL if the plugin | 1614 | * @param addr the address to use (can be NULL if the plugin |
1573 | * is "on its own" (i.e. re-use existing TCP connection)) | 1615 | * is "on its own" (i.e. re-use existing TCP connection)) |
@@ -1592,8 +1634,8 @@ wlan_plugin_send(void *cls, const struct GNUNET_PeerIdentity * target, | |||
1592 | GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) | 1634 | GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) |
1593 | { | 1635 | { |
1594 | struct Plugin * plugin = cls; | 1636 | struct Plugin * plugin = cls; |
1595 | struct PendingMessage * newmsg = NULL; | 1637 | struct PendingMessage * newmsg; |
1596 | struct WlanHeader * wlanheader = NULL; | 1638 | struct WlanHeader * wlanheader; |
1597 | 1639 | ||
1598 | //check if msglen > 0 | 1640 | //check if msglen > 0 |
1599 | GNUNET_assert(msgbuf_size > 0); | 1641 | GNUNET_assert(msgbuf_size > 0); |
@@ -1603,7 +1645,7 @@ wlan_plugin_send(void *cls, const struct GNUNET_PeerIdentity * target, | |||
1603 | { | 1645 | { |
1604 | if (wlan_plugin_address_suggested(plugin, addr, addrlen) == GNUNET_OK) | 1646 | if (wlan_plugin_address_suggested(plugin, addr, addrlen) == GNUNET_OK) |
1605 | { | 1647 | { |
1606 | session = get_Session(plugin, addr); | 1648 | session = get_session(plugin, addr); |
1607 | } | 1649 | } |
1608 | else | 1650 | else |
1609 | { | 1651 | { |
@@ -1677,7 +1719,7 @@ wlan_plugin_send(void *cls, const struct GNUNET_PeerIdentity * target, | |||
1677 | #endif | 1719 | #endif |
1678 | 1720 | ||
1679 | //queue session | 1721 | //queue session |
1680 | queue_Session(plugin, session); | 1722 | queue_session(plugin, session); |
1681 | 1723 | ||
1682 | check_fragment_queue(plugin); | 1724 | check_fragment_queue(plugin); |
1683 | //FIXME not the correct size | 1725 | //FIXME not the correct size |
@@ -1686,23 +1728,58 @@ wlan_plugin_send(void *cls, const struct GNUNET_PeerIdentity * target, | |||
1686 | } | 1728 | } |
1687 | 1729 | ||
1688 | /** | 1730 | /** |
1689 | * function to get the first message in the fragement queue (out) of a session | 1731 | * Iterate over the fragment messages of the given session. |
1690 | * @param session pointer to the session | 1732 | * |
1691 | * @return pointer to the struct FragmentMessage | 1733 | * @param cls argument to give to iterator |
1734 | * @param node node to iterate over | ||
1735 | * @param element value stored at the node | ||
1736 | * @param cost cost associated with the node | ||
1737 | * @return GNUNET_YES if we should continue to iterate, | ||
1738 | * GNUNET_NO if not. | ||
1692 | */ | 1739 | */ |
1693 | static struct FragmentMessage * | 1740 | static int |
1694 | get_fragment_message_from_session(struct Session * session) | 1741 | free_fragment_message_from_session(void *cls, |
1742 | struct GNUNET_CONTAINER_HeapNode *node, void *element, | ||
1743 | GNUNET_CONTAINER_HeapCostType cost) | ||
1695 | { | 1744 | { |
1696 | struct FragmentMessage * fm = session->plugin->pending_Fragment_Messages_head; | 1745 | struct Plugin_Session_pair * pair = (struct Plugin_Session_pair *) cls; |
1697 | while (fm != NULL) | 1746 | struct FragmentMessage * fm = (struct FragmentMessage*) element; |
1747 | |||
1748 | if (fm->session == pair->session) | ||
1698 | { | 1749 | { |
1699 | if (fm->session == session) | 1750 | |
1700 | { | 1751 | free_fragment_message(pair->plugin, fm); |
1701 | return fm; | ||
1702 | } | ||
1703 | fm = fm->next; | ||
1704 | } | 1752 | } |
1705 | return NULL; | 1753 | return GNUNET_YES; |
1754 | |||
1755 | } | ||
1756 | |||
1757 | /** | ||
1758 | * Search for fragment message with given id and session | ||
1759 | * | ||
1760 | * @param cls argument to give to iterator | ||
1761 | * @param node node to iterate over | ||
1762 | * @param element value stored at the node | ||
1763 | * @param cost cost associated with the node | ||
1764 | * @return GNUNET_YES if we should continue to iterate, | ||
1765 | * GNUNET_NO if not. | ||
1766 | */ | ||
1767 | static int | ||
1768 | search_fragment_message_from_session_and_id(void *cls, | ||
1769 | struct GNUNET_CONTAINER_HeapNode *node, void *element, | ||
1770 | GNUNET_CONTAINER_HeapCostType cost) | ||
1771 | { | ||
1772 | struct Session_id_pair * pair = (struct Session_id_pair *) cls; | ||
1773 | struct FragmentMessage * fm = (struct FragmentMessage*) element; | ||
1774 | |||
1775 | if ((fm->session == pair->session) | ||
1776 | && (fm->message_id_out == pair->message_id)) | ||
1777 | { | ||
1778 | return_val = fm; | ||
1779 | return GNUNET_NO; | ||
1780 | } | ||
1781 | return GNUNET_YES; | ||
1782 | |||
1706 | } | 1783 | } |
1707 | 1784 | ||
1708 | /** | 1785 | /** |
@@ -1712,22 +1789,17 @@ get_fragment_message_from_session(struct Session * session) | |||
1712 | * @return pointer to the struct FragmentMessage | 1789 | * @return pointer to the struct FragmentMessage |
1713 | */ | 1790 | */ |
1714 | static struct FragmentMessage * | 1791 | static struct FragmentMessage * |
1715 | get_fragment_message_from_session_and_id(struct Session * session, | 1792 | get_fragment_message_from_session_and_id(struct Plugin * plugin, |
1716 | uint32_t message_id) | 1793 | struct Session * session, uint32_t message_id) |
1717 | { | 1794 | { |
1718 | struct FragmentMessage * fm = session->plugin->pending_Fragment_Messages_head; | 1795 | struct Session_id_pair pair; |
1719 | while (fm != NULL) | 1796 | pair.session = session; |
1720 | { | 1797 | pair.message_id = message_id; |
1721 | if ((fm->session == session) && (fm->message_id_out == message_id)) | 1798 | GNUNET_CONTAINER_heap_iterate(plugin->pending_Fragment_Messages, |
1722 | { | 1799 | &search_fragment_message_from_session_and_id, &pair); |
1723 | return fm; | 1800 | return return_val; |
1724 | } | ||
1725 | fm = fm->next; | ||
1726 | } | ||
1727 | return NULL; | ||
1728 | } | 1801 | } |
1729 | 1802 | ||
1730 | |||
1731 | /** | 1803 | /** |
1732 | * function to get the receive message of a session | 1804 | * function to get the receive message of a session |
1733 | * @param plugin pointer to the plugin struct | 1805 | * @param plugin pointer to the plugin struct |
@@ -1749,7 +1821,6 @@ get_receive_message_from_session(struct Plugin * plugin, | |||
1749 | return NULL; | 1821 | return NULL; |
1750 | } | 1822 | } |
1751 | 1823 | ||
1752 | |||
1753 | /** | 1824 | /** |
1754 | * Function to dispose the fragments received for a message and the message | 1825 | * Function to dispose the fragments received for a message and the message |
1755 | * @param plugin pointer to the plugin struct | 1826 | * @param plugin pointer to the plugin struct |
@@ -1780,6 +1851,67 @@ free_receive_message(struct Plugin* plugin, | |||
1780 | GNUNET_free(rx_message); | 1851 | GNUNET_free(rx_message); |
1781 | } | 1852 | } |
1782 | 1853 | ||
1854 | static void | ||
1855 | free_session(struct Plugin * plugin, struct Sessionqueue * queue) | ||
1856 | { | ||
1857 | struct Sessionqueue * pendingsession = plugin->pending_Sessions; | ||
1858 | struct PendingMessage * pm; | ||
1859 | struct Receive_Message_Queue * receive_queue; | ||
1860 | struct Plugin_Session_pair pair; | ||
1861 | |||
1862 | //session found | ||
1863 | //is this session pending for send | ||
1864 | while (pendingsession != NULL) | ||
1865 | { | ||
1866 | if (pendingsession->content == queue->content) | ||
1867 | { | ||
1868 | plugin->pendingsessions--; | ||
1869 | GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions, | ||
1870 | plugin->pending_Sessions_tail, pendingsession); | ||
1871 | GNUNET_free(pendingsession); | ||
1872 | break; | ||
1873 | } | ||
1874 | pendingsession = pendingsession->next; | ||
1875 | } | ||
1876 | |||
1877 | //is something of this session in the fragment queue? | ||
1878 | pair.plugin = plugin; | ||
1879 | pair.session = queue->content; | ||
1880 | GNUNET_CONTAINER_heap_iterate(plugin->pending_Fragment_Messages, | ||
1881 | &free_fragment_message_from_session, &pair); | ||
1882 | |||
1883 | //dispose all received fragments | ||
1884 | receive_queue = get_receive_message_from_session(plugin, queue->content); | ||
1885 | while (receive_queue != NULL) | ||
1886 | { | ||
1887 | free_receive_message(plugin, receive_queue); | ||
1888 | receive_queue = get_receive_message_from_session(plugin, queue->content); | ||
1889 | } | ||
1890 | |||
1891 | // remove PendingMessage | ||
1892 | pm = queue->content->pending_message; | ||
1893 | if (pm != NULL) | ||
1894 | { | ||
1895 | GNUNET_free_non_null(pm->msg); | ||
1896 | GNUNET_free(pm); | ||
1897 | } | ||
1898 | |||
1899 | // remove PendingMessage | ||
1900 | pm = queue->content->pending_message2; | ||
1901 | if (pm != NULL) | ||
1902 | { | ||
1903 | GNUNET_free_non_null(pm->msg); | ||
1904 | GNUNET_free(pm); | ||
1905 | } | ||
1906 | |||
1907 | GNUNET_free(queue->content); | ||
1908 | GNUNET_CONTAINER_DLL_remove(plugin->sessions, plugin->sessions_tail, queue); | ||
1909 | GNUNET_free(queue); | ||
1910 | plugin->session_count--; | ||
1911 | |||
1912 | check_fragment_queue(plugin); | ||
1913 | |||
1914 | } | ||
1783 | 1915 | ||
1784 | /** | 1916 | /** |
1785 | * Function that can be used to force the plugin to disconnect | 1917 | * Function that can be used to force the plugin to disconnect |
@@ -1794,10 +1926,6 @@ wlan_plugin_disconnect(void *cls, const struct GNUNET_PeerIdentity *target) | |||
1794 | { | 1926 | { |
1795 | struct Plugin *plugin = cls; | 1927 | struct Plugin *plugin = cls; |
1796 | struct Sessionqueue * queue = plugin->sessions; | 1928 | struct Sessionqueue * queue = plugin->sessions; |
1797 | struct Sessionqueue * pendingsession = plugin->pending_Sessions; | ||
1798 | struct PendingMessage * pm = NULL; | ||
1799 | struct FragmentMessage * fm; | ||
1800 | struct Receive_Message_Queue * receive_queue; | ||
1801 | 1929 | ||
1802 | // just look at all the session for the needed one | 1930 | // just look at all the session for the needed one |
1803 | while (queue != NULL) | 1931 | while (queue != NULL) |
@@ -1807,53 +1935,7 @@ wlan_plugin_disconnect(void *cls, const struct GNUNET_PeerIdentity *target) | |||
1807 | if (memcmp(target, &(queue->content->target), | 1935 | if (memcmp(target, &(queue->content->target), |
1808 | sizeof(struct GNUNET_PeerIdentity)) == 0) | 1936 | sizeof(struct GNUNET_PeerIdentity)) == 0) |
1809 | { | 1937 | { |
1810 | //session found | 1938 | free_session(plugin, queue); |
1811 | //is this session pending for send | ||
1812 | while (pendingsession != NULL) | ||
1813 | { | ||
1814 | if (pendingsession->content == queue->content) | ||
1815 | { | ||
1816 | plugin->pendingsessions--; | ||
1817 | GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions, | ||
1818 | plugin->pending_Sessions_tail, pendingsession); | ||
1819 | GNUNET_free(pendingsession); | ||
1820 | break; | ||
1821 | } | ||
1822 | pendingsession = pendingsession->next; | ||
1823 | } | ||
1824 | |||
1825 | //is something of this session in the fragment queue? | ||
1826 | fm = get_fragment_message_from_session(queue->content); | ||
1827 | while (fm != NULL) | ||
1828 | { | ||
1829 | free_fragment_message(plugin, fm); | ||
1830 | fm = get_fragment_message_from_session(queue->content); | ||
1831 | } | ||
1832 | check_next_fragment_timeout(plugin); | ||
1833 | |||
1834 | //dispose all received fragments | ||
1835 | receive_queue = get_receive_message_from_session(plugin, | ||
1836 | queue->content); | ||
1837 | while (receive_queue != NULL) | ||
1838 | { | ||
1839 | free_receive_message(plugin, receive_queue); | ||
1840 | receive_queue = get_receive_message_from_session(plugin, | ||
1841 | queue->content); | ||
1842 | } | ||
1843 | |||
1844 | // remove PendingMessage | ||
1845 | pm = queue->content->pending_message; | ||
1846 | if (pm != NULL) | ||
1847 | { | ||
1848 | GNUNET_free_non_null(pm->msg); | ||
1849 | GNUNET_free(pm); | ||
1850 | } | ||
1851 | |||
1852 | GNUNET_free(queue->content); | ||
1853 | GNUNET_CONTAINER_DLL_remove(plugin->sessions, plugin->sessions_tail, queue); | ||
1854 | GNUNET_free(queue); | ||
1855 | plugin->session_count--; | ||
1856 | |||
1857 | return; | 1939 | return; |
1858 | } | 1940 | } |
1859 | // try next | 1941 | // try next |
@@ -1899,55 +1981,24 @@ wlan_plugin_address_pretty_printer(void *cls, const char *type, | |||
1899 | asc(asc_cls, ret); | 1981 | asc(asc_cls, ret); |
1900 | } | 1982 | } |
1901 | 1983 | ||
1902 | |||
1903 | |||
1904 | /** | ||
1905 | * Function called for a quick conversion of the binary address to | ||
1906 | * a numeric address. Note that the caller must not free the | ||
1907 | * address and that the next call to this function is allowed | ||
1908 | * to override the address again. | ||
1909 | * | ||
1910 | * @param cls closure | ||
1911 | * @param addr binary address | ||
1912 | * @param addrlen length of the address | ||
1913 | * @return string representing the same address | ||
1914 | */ | ||
1915 | static const char* | ||
1916 | wlan_plugin_address_to_string(void *cls, const void *addr, size_t addrlen) | ||
1917 | { | ||
1918 | static char ret[40]; | ||
1919 | const struct MacAddress *mac; | ||
1920 | |||
1921 | if (addrlen != sizeof(struct MacAddress)) | ||
1922 | { | ||
1923 | GNUNET_break (0); | ||
1924 | return NULL; | ||
1925 | } | ||
1926 | mac = addr; | ||
1927 | GNUNET_snprintf(ret, sizeof(ret), "%s Mac-Address %X:%X:%X:%X:%X:%X", | ||
1928 | PROTOCOL_PREFIX, mac->mac[0], mac->mac[1], mac->mac[2], mac->mac[3], | ||
1929 | mac->mac[4], mac->mac[5]); | ||
1930 | return ret; | ||
1931 | } | ||
1932 | |||
1933 | /** | 1984 | /** |
1934 | * function to check if bitfield is representation of fragments of the message | 1985 | * function to check if bitfield is representation of fragments of the message |
1935 | * @param rec_message message to check | 1986 | * @param rec_message message to check |
1936 | */ | 1987 | */ |
1937 | 1988 | ||
1938 | void | 1989 | void |
1939 | check_message_fragment_bitfield(struct Receive_Message_Queue * rec_message) | 1990 | check_message_fragment_bitfield(struct Receive_Message_Queue * rx_msg) |
1940 | { | 1991 | { |
1941 | uint64_t checkfragments = 0; | 1992 | uint64_t checkfragments = 0; |
1942 | struct Receive_Fragment_Queue * rec_queue = rec_message->frag_head; | 1993 | struct Receive_Fragment_Queue * rx_frag = rx_msg->frag_head; |
1943 | 1994 | ||
1944 | while (rec_queue != NULL) | 1995 | while (rx_frag != NULL) |
1945 | { | 1996 | { |
1946 | setBit((char*) &checkfragments, rec_queue->num); | 1997 | setBit((char*) &checkfragments, rx_frag->num); |
1947 | rec_queue = rec_queue->next; | 1998 | rx_frag = rx_frag->next; |
1948 | 1999 | ||
1949 | } | 2000 | } |
1950 | GNUNET_assert(checkfragments == rec_message->received_fragments); | 2001 | GNUNET_assert(checkfragments == rx_msg->received_fragments); |
1951 | } | 2002 | } |
1952 | 2003 | ||
1953 | /** | 2004 | /** |
@@ -1959,15 +2010,15 @@ check_message_fragment_bitfield(struct Receive_Message_Queue * rec_message) | |||
1959 | */ | 2010 | */ |
1960 | 2011 | ||
1961 | static const int | 2012 | static const int |
1962 | is_double_msg(struct Receive_Message_Queue * rec_message, | 2013 | is_double_msg(struct Receive_Message_Queue * rx_msg, |
1963 | struct FragmentationHeader * fh) | 2014 | struct FragmentationHeader * fh) |
1964 | { | 2015 | { |
1965 | //test if bitfield is okay | 2016 | //test if bitfield is okay |
1966 | #if DEBUG_wlan | 2017 | #if DEBUG_wlan |
1967 | check_message_fragment_bitfield(rec_message); | 2018 | check_message_fragment_bitfield(rx_msg); |
1968 | #endif | 2019 | #endif |
1969 | 2020 | ||
1970 | return testBit((char *) &rec_message->received_fragments, ntohs( | 2021 | return testBit((char *) &rx_msg->received_fragments, ntohs( |
1971 | fh->fragment_off_or_num)); | 2022 | fh->fragment_off_or_num)); |
1972 | 2023 | ||
1973 | } | 2024 | } |
@@ -1986,8 +2037,7 @@ insert_fragment_in_queue(struct Receive_Message_Queue * rx_message, | |||
1986 | GNUNET_assert(rx_frag != NULL); | 2037 | GNUNET_assert(rx_frag != NULL); |
1987 | 2038 | ||
1988 | struct Receive_Fragment_Queue * rx_frag2 = rx_message->frag_head; | 2039 | struct Receive_Fragment_Queue * rx_frag2 = rx_message->frag_head; |
1989 | struct WlanHeader * wlanheader = NULL; | 2040 | struct WlanHeader * wlanheader; |
1990 | |||
1991 | 2041 | ||
1992 | //this is the first fragment of the message (fragment id 0) | 2042 | //this is the first fragment of the message (fragment id 0) |
1993 | if (rx_frag->num == 0) | 2043 | if (rx_frag->num == 0) |
@@ -2015,10 +2065,6 @@ insert_fragment_in_queue(struct Receive_Message_Queue * rx_message, | |||
2015 | setBit((char *) &rx_message->received_fragments, rx_frag->num); | 2065 | setBit((char *) &rx_message->received_fragments, rx_frag->num); |
2016 | } | 2066 | } |
2017 | 2067 | ||
2018 | |||
2019 | |||
2020 | |||
2021 | |||
2022 | /** | 2068 | /** |
2023 | * handels the data after all fragments are put together | 2069 | * handels the data after all fragments are put together |
2024 | * @param plugin | 2070 | * @param plugin |
@@ -2026,14 +2072,14 @@ insert_fragment_in_queue(struct Receive_Message_Queue * rx_message, | |||
2026 | * @param hdr pointer to the data | 2072 | * @param hdr pointer to the data |
2027 | */ | 2073 | */ |
2028 | static void | 2074 | static void |
2029 | wlan_data_massage_handler(struct Plugin * plugin, | 2075 | wlan_data_message_handler(struct Plugin * plugin, |
2030 | struct Session_light * session_light, | 2076 | struct Session_light * session_light, |
2031 | const struct GNUNET_MessageHeader * hdr) | 2077 | const struct GNUNET_MessageHeader * hdr) |
2032 | { | 2078 | { |
2033 | struct WlanHeader * wlanheader = NULL; | 2079 | struct WlanHeader * wlanheader; |
2034 | struct Session * session = NULL; | 2080 | struct Session * session; |
2035 | const char * tempmsg = NULL; | 2081 | const char * tempmsg; |
2036 | const struct GNUNET_MessageHeader * temp_hdr = NULL; | 2082 | const struct GNUNET_MessageHeader * temp_hdr; |
2037 | struct GNUNET_PeerIdentity tmptarget; | 2083 | struct GNUNET_PeerIdentity tmptarget; |
2038 | 2084 | ||
2039 | if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_DATA) | 2085 | if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_DATA) |
@@ -2042,7 +2088,7 @@ wlan_data_massage_handler(struct Plugin * plugin, | |||
2042 | #if DEBUG_wlan | 2088 | #if DEBUG_wlan |
2043 | GNUNET_log( | 2089 | GNUNET_log( |
2044 | GNUNET_ERROR_TYPE_DEBUG, | 2090 | GNUNET_ERROR_TYPE_DEBUG, |
2045 | "Func wlan_data_massage_handler got GNUNET_MESSAGE_TYPE_WLAN_DATA size: %u\n", | 2091 | "Func wlan_data_message_handler got GNUNET_MESSAGE_TYPE_WLAN_DATA size: %u\n", |
2046 | ntohs(hdr->size)); | 2092 | ntohs(hdr->size)); |
2047 | #endif | 2093 | #endif |
2048 | 2094 | ||
@@ -2136,13 +2182,11 @@ wlan_data_massage_handler(struct Plugin * plugin, | |||
2136 | else | 2182 | else |
2137 | { | 2183 | { |
2138 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 2184 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
2139 | "wlan_data_massage_handler got wrong message type\n"); | 2185 | "wlan_data_message_handler got wrong message type\n"); |
2140 | return; | 2186 | return; |
2141 | } | 2187 | } |
2142 | } | 2188 | } |
2143 | 2189 | ||
2144 | |||
2145 | |||
2146 | /** | 2190 | /** |
2147 | * Function to check if all fragments of a message have been received | 2191 | * Function to check if all fragments of a message have been received |
2148 | * @param plugin the plugin handle | 2192 | * @param plugin the plugin handle |
@@ -2152,7 +2196,7 @@ wlan_data_massage_handler(struct Plugin * plugin, | |||
2152 | */ | 2196 | */ |
2153 | 2197 | ||
2154 | static void | 2198 | static void |
2155 | check_rec_finished_msg(struct Plugin* plugin, | 2199 | check_rx_finished_msg(struct Plugin* plugin, |
2156 | struct Session_light * session_light, struct Session * session, | 2200 | struct Session_light * session_light, struct Session * session, |
2157 | struct Receive_Message_Queue * rx_message) | 2201 | struct Receive_Message_Queue * rx_message) |
2158 | { | 2202 | { |
@@ -2160,8 +2204,8 @@ check_rec_finished_msg(struct Plugin* plugin, | |||
2160 | 2204 | ||
2161 | struct Receive_Fragment_Queue * rx_frag = rx_message->frag_head; | 2205 | struct Receive_Fragment_Queue * rx_frag = rx_message->frag_head; |
2162 | int packetsize = rx_message->rec_size; | 2206 | int packetsize = rx_message->rec_size; |
2163 | int sum = 0; | 2207 | int sum; |
2164 | int aktnum = 0; | 2208 | int aktnum; |
2165 | uint64_t bitfield = 0; | 2209 | uint64_t bitfield = 0; |
2166 | char * msg; | 2210 | char * msg; |
2167 | 2211 | ||
@@ -2171,6 +2215,7 @@ check_rec_finished_msg(struct Plugin* plugin, | |||
2171 | return; | 2215 | return; |
2172 | } | 2216 | } |
2173 | // test if message has at least the size of the WlanHeader and a GNUNET_MessageHeader | 2217 | // test if message has at least the size of the WlanHeader and a GNUNET_MessageHeader |
2218 | |||
2174 | else if (packetsize < sizeof(struct WlanHeader) | 2219 | else if (packetsize < sizeof(struct WlanHeader) |
2175 | + sizeof(struct GNUNET_MessageHeader)) | 2220 | + sizeof(struct GNUNET_MessageHeader)) |
2176 | { | 2221 | { |
@@ -2191,7 +2236,7 @@ check_rec_finished_msg(struct Plugin* plugin, | |||
2191 | bitfield = bitfield >> (63 - rx_message->frag_tail->num); | 2236 | bitfield = bitfield >> (63 - rx_message->frag_tail->num); |
2192 | if (rx_message->received_fragments == bitfield) | 2237 | if (rx_message->received_fragments == bitfield) |
2193 | { | 2238 | { |
2194 | 2239 | sum = 0; | |
2195 | while (rx_frag != NULL) | 2240 | while (rx_frag != NULL) |
2196 | { | 2241 | { |
2197 | sum += rx_frag->size; | 2242 | sum += rx_frag->size; |
@@ -2222,7 +2267,7 @@ check_rec_finished_msg(struct Plugin* plugin, | |||
2222 | 2267 | ||
2223 | free_receive_message(plugin, rx_message); | 2268 | free_receive_message(plugin, rx_message); |
2224 | //call wlan_process_helper to process the message | 2269 | //call wlan_process_helper to process the message |
2225 | wlan_data_massage_handler(plugin, session_light, | 2270 | wlan_data_message_handler(plugin, session_light, |
2226 | (struct GNUNET_MessageHeader*) msg); | 2271 | (struct GNUNET_MessageHeader*) msg); |
2227 | //wlan_data_helper (plugin, session_light, (struct GNUNET_MessageHeader*) msg); | 2272 | //wlan_data_helper (plugin, session_light, (struct GNUNET_MessageHeader*) msg); |
2228 | 2273 | ||
@@ -2250,12 +2295,13 @@ process_data(void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | |||
2250 | #if DEBUG_wlan | 2295 | #if DEBUG_wlan |
2251 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2296 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2252 | "Calling plugin->env->receive for session %p; %s; size: %u\n", session, | 2297 | "Calling plugin->env->receive for session %p; %s; size: %u\n", session, |
2253 | wlan_plugin_address_to_string(NULL, session->addr, 6), htons(hdr->size)); | 2298 | wlan_plugin_address_to_string(NULL, session->addr.mac, 6), htons( |
2299 | hdr->size)); | ||
2254 | #endif | 2300 | #endif |
2255 | 2301 | ||
2256 | plugin->env->receive(plugin->env->cls, &(session->target), hdr, | 2302 | plugin->env->receive(plugin->env->cls, &(session->target), hdr, |
2257 | (const struct GNUNET_TRANSPORT_ATS_Information *) &distance, 2, session, | 2303 | (const struct GNUNET_TRANSPORT_ATS_Information *) &distance, 2, session, |
2258 | (const char*) &session->addr, sizeof(session->addr)); | 2304 | (const char*) &session->addr, sizeof(session->addr)); |
2259 | } | 2305 | } |
2260 | 2306 | ||
2261 | /** | 2307 | /** |
@@ -2310,8 +2356,6 @@ get_receive_message(struct Plugin * plugin, struct Session * session, | |||
2310 | return NULL; | 2356 | return NULL; |
2311 | } | 2357 | } |
2312 | 2358 | ||
2313 | |||
2314 | |||
2315 | /** | 2359 | /** |
2316 | * function to insert a received fragment into the right fragment queue of the right message | 2360 | * function to insert a received fragment into the right fragment queue of the right message |
2317 | * @param plugin pointer to the plugin struct | 2361 | * @param plugin pointer to the plugin struct |
@@ -2369,7 +2413,8 @@ insert_fragment_in_in_message_queue(struct Plugin * plugin, | |||
2369 | 2413 | ||
2370 | GNUNET_log( | 2414 | GNUNET_log( |
2371 | GNUNET_ERROR_TYPE_INFO, | 2415 | GNUNET_ERROR_TYPE_INFO, |
2372 | "WLAN fragment message_id and session message_id do not exist, max MESSAGES_IN_QUEUE_PER_SESSION reached\n"); | 2416 | "WLAN fragment message_id and session message_id do not exist, max MESSAGES_IN_QUEUE_PER_SESSION reached, akt in message_id %u\n", |
2417 | get_receive_message_from_session(plugin, session)->message_id_in); | ||
2373 | setBit((char *) &retval, ntohs(fh->fragment_off_or_num)); | 2418 | setBit((char *) &retval, ntohs(fh->fragment_off_or_num)); |
2374 | return retval; | 2419 | return retval; |
2375 | } | 2420 | } |
@@ -2378,7 +2423,6 @@ insert_fragment_in_in_message_queue(struct Plugin * plugin, | |||
2378 | if (is_double_msg(rx_message, fh) != GNUNET_YES) | 2423 | if (is_double_msg(rx_message, fh) != GNUNET_YES) |
2379 | { | 2424 | { |
2380 | 2425 | ||
2381 | |||
2382 | //report size | 2426 | //report size |
2383 | rx_frag = GNUNET_malloc(sizeof (struct Receive_Fragment_Queue) + | 2427 | rx_frag = GNUNET_malloc(sizeof (struct Receive_Fragment_Queue) + |
2384 | ntohs(fh->header.size) - sizeof(struct FragmentationHeader)); | 2428 | ntohs(fh->header.size) - sizeof(struct FragmentationHeader)); |
@@ -2401,7 +2445,7 @@ insert_fragment_in_in_message_queue(struct Plugin * plugin, | |||
2401 | rx_message->received_fragments, session); | 2445 | rx_message->received_fragments, session); |
2402 | #endif | 2446 | #endif |
2403 | 2447 | ||
2404 | check_rec_finished_msg(plugin, session_light, session, rx_message); | 2448 | check_rx_finished_msg(plugin, session_light, session, rx_message); |
2405 | } | 2449 | } |
2406 | else | 2450 | else |
2407 | { | 2451 | { |
@@ -2425,13 +2469,13 @@ wlan_data_helper(void *cls, struct Session_light * session_light, | |||
2425 | const struct GNUNET_MessageHeader * hdr, const struct Radiotap_rx * rxinfo) | 2469 | const struct GNUNET_MessageHeader * hdr, const struct Radiotap_rx * rxinfo) |
2426 | { | 2470 | { |
2427 | struct Plugin *plugin = cls; | 2471 | struct Plugin *plugin = cls; |
2428 | struct Session * session = NULL; | 2472 | struct Session * session; |
2429 | 2473 | ||
2430 | struct FragmentationHeader * fh = NULL; | 2474 | struct FragmentationHeader * fh; |
2431 | struct FragmentationAckHeader * fah = NULL; | 2475 | struct FragmentationAckHeader * fah; |
2432 | struct FragmentMessage * fm = NULL; | 2476 | struct FragmentMessage * fm; |
2433 | 2477 | ||
2434 | const char * tempmsg = NULL; | 2478 | const char * tempmsg; |
2435 | 2479 | ||
2436 | uint64_t fragment_bitfield = 0; | 2480 | uint64_t fragment_bitfield = 0; |
2437 | 2481 | ||
@@ -2448,12 +2492,12 @@ wlan_data_helper(void *cls, struct Session_light * session_light, | |||
2448 | GNUNET_ERROR_TYPE_DEBUG, | 2492 | GNUNET_ERROR_TYPE_DEBUG, |
2449 | "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT size: %u; %s\n", | 2493 | "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT size: %u; %s\n", |
2450 | ntohs(hdr->size), wlan_plugin_address_to_string(NULL, | 2494 | ntohs(hdr->size), wlan_plugin_address_to_string(NULL, |
2451 | session_light->addr, 6)); | 2495 | session_light->addr.mac, 6)); |
2452 | #endif | 2496 | #endif |
2453 | 2497 | ||
2454 | if (session_light->session == NULL) | 2498 | if (session_light->session == NULL) |
2455 | { | 2499 | { |
2456 | session_light->session = get_Session(plugin, &session_light->addr); | 2500 | session_light->session = get_session(plugin, &session_light->addr); |
2457 | } | 2501 | } |
2458 | GNUNET_assert(GNUNET_HELLO_get_id( | 2502 | GNUNET_assert(GNUNET_HELLO_get_id( |
2459 | (const struct GNUNET_HELLO_Message *) &hdr[1], | 2503 | (const struct GNUNET_HELLO_Message *) &hdr[1], |
@@ -2462,6 +2506,7 @@ wlan_data_helper(void *cls, struct Session_light * session_light, | |||
2462 | } | 2506 | } |
2463 | 2507 | ||
2464 | //FRAGMENT | 2508 | //FRAGMENT |
2509 | |||
2465 | else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT) | 2510 | else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT) |
2466 | { | 2511 | { |
2467 | 2512 | ||
@@ -2481,7 +2526,7 @@ wlan_data_helper(void *cls, struct Session_light * session_light, | |||
2481 | "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT with message_id %u with fragment number %i, size: %u; %s\n", | 2526 | "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT with message_id %u with fragment number %i, size: %u; %s\n", |
2482 | ntohl(fh->message_id), ntohs(fh->fragment_off_or_num), ntohs( | 2527 | ntohl(fh->message_id), ntohs(fh->fragment_off_or_num), ntohs( |
2483 | hdr->size), wlan_plugin_address_to_string(NULL, | 2528 | hdr->size), wlan_plugin_address_to_string(NULL, |
2484 | session_light->addr, 6)); | 2529 | session_light->addr.mac, 6)); |
2485 | #endif | 2530 | #endif |
2486 | 2531 | ||
2487 | if (getcrc16(tempmsg, ntohs(fh->header.size)) != ntohs(fh->message_crc)) | 2532 | if (getcrc16(tempmsg, ntohs(fh->header.size)) != ntohs(fh->message_crc)) |
@@ -2504,7 +2549,7 @@ wlan_data_helper(void *cls, struct Session_light * session_light, | |||
2504 | GNUNET_ERROR_TYPE_INFO, | 2549 | GNUNET_ERROR_TYPE_INFO, |
2505 | "WLAN client not in session list, fragment num %u, message id %u\n", | 2550 | "WLAN client not in session list, fragment num %u, message id %u\n", |
2506 | ntohs(fh->fragment_off_or_num), ntohl(fh->message_id)); | 2551 | ntohs(fh->fragment_off_or_num), ntohl(fh->message_id)); |
2507 | wlan_data_massage_handler(plugin, session_light, | 2552 | wlan_data_message_handler(plugin, session_light, |
2508 | (struct GNUNET_MessageHeader *) tempmsg); | 2553 | (struct GNUNET_MessageHeader *) tempmsg); |
2509 | session = session_light->session; | 2554 | session = session_light->session; |
2510 | //test if a session was created | 2555 | //test if a session was created |
@@ -2516,11 +2561,12 @@ wlan_data_helper(void *cls, struct Session_light * session_light, | |||
2516 | } | 2561 | } |
2517 | 2562 | ||
2518 | add_ack_for_send(plugin, session, fragment_bitfield, fh); | 2563 | add_ack_for_send(plugin, session, fragment_bitfield, fh); |
2519 | check_next_fragment_timeout(plugin); | 2564 | set_next_send(plugin); |
2520 | 2565 | ||
2521 | } | 2566 | } |
2522 | 2567 | ||
2523 | //ACK | 2568 | //ACK |
2569 | |||
2524 | else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT_ACK) | 2570 | else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT_ACK) |
2525 | { | 2571 | { |
2526 | 2572 | ||
@@ -2529,7 +2575,7 @@ wlan_data_helper(void *cls, struct Session_light * session_light, | |||
2529 | GNUNET_ERROR_TYPE_DEBUG, | 2575 | GNUNET_ERROR_TYPE_DEBUG, |
2530 | "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT_ACK size: %u; %s\n", | 2576 | "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT_ACK size: %u; %s\n", |
2531 | ntohs(hdr->size), wlan_plugin_address_to_string(NULL, | 2577 | ntohs(hdr->size), wlan_plugin_address_to_string(NULL, |
2532 | session_light->addr, 6)); | 2578 | session_light->addr.mac, 6)); |
2533 | #endif | 2579 | #endif |
2534 | 2580 | ||
2535 | GNUNET_assert(session_light != NULL); | 2581 | GNUNET_assert(session_light != NULL); |
@@ -2540,13 +2586,23 @@ wlan_data_helper(void *cls, struct Session_light * session_light, | |||
2540 | } | 2586 | } |
2541 | session = session_light->session; | 2587 | session = session_light->session; |
2542 | fah = (struct FragmentationAckHeader *) hdr; | 2588 | fah = (struct FragmentationAckHeader *) hdr; |
2543 | fm = get_fragment_message_from_session_and_id(session, ntohl( | 2589 | fm = get_fragment_message_from_session_and_id(plugin, session, ntohl( |
2544 | fah->message_id)); | 2590 | fah->message_id)); |
2591 | |||
2545 | if (fm != NULL) | 2592 | if (fm != NULL) |
2546 | { | 2593 | { |
2547 | 2594 | ||
2548 | fm->ack_bitfield = fm->ack_bitfield | GNUNET_ntohll(fah->fragment_field); | 2595 | fm->ack_bitfield = fm->ack_bitfield | GNUNET_ntohll( |
2596 | fah->fragment_field); | ||
2597 | fm->next_ack = GNUNET_TIME_relative_to_absolute(get_ack_timeout(fm)); | ||
2598 | |||
2599 | #if DEBUG_wlan_retransmission | ||
2600 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Got ack for: %u; %u\n", | ||
2601 | fm->message_id_out, fm->ack_bitfield); | ||
2602 | #endif | ||
2549 | check_finished_fragment(plugin, fm); | 2603 | check_finished_fragment(plugin, fm); |
2604 | set_next_send(plugin); | ||
2605 | |||
2550 | } | 2606 | } |
2551 | else | 2607 | else |
2552 | { | 2608 | { |
@@ -2564,7 +2620,7 @@ wlan_data_helper(void *cls, struct Session_light * session_light, | |||
2564 | GNUNET_ERROR_TYPE_INFO, | 2620 | GNUNET_ERROR_TYPE_INFO, |
2565 | "WLAN packet inside the WLAN helper packet has not the right type: %u size: %u\n", | 2621 | "WLAN packet inside the WLAN helper packet has not the right type: %u size: %u\n", |
2566 | ntohs(hdr->type), ntohs(hdr->size)); | 2622 | ntohs(hdr->type), ntohs(hdr->size)); |
2567 | GNUNET_assert(0); | 2623 | GNUNET_break(0); |
2568 | return; | 2624 | return; |
2569 | } | 2625 | } |
2570 | 2626 | ||
@@ -2603,7 +2659,7 @@ wlan_process_helper(void *cls, void *client, | |||
2603 | const struct GNUNET_MessageHeader * temp_hdr = NULL; | 2659 | const struct GNUNET_MessageHeader * temp_hdr = NULL; |
2604 | 2660 | ||
2605 | int datasize = 0; | 2661 | int datasize = 0; |
2606 | int pos = 0; | 2662 | int pos; |
2607 | 2663 | ||
2608 | switch (ntohs(hdr->type)) | 2664 | switch (ntohs(hdr->type)) |
2609 | { | 2665 | { |
@@ -2635,8 +2691,8 @@ wlan_process_helper(void *cls, void *client, | |||
2635 | //process only if it is an broadcast or for this computer both with the gnunet bssid | 2691 | //process only if it is an broadcast or for this computer both with the gnunet bssid |
2636 | 2692 | ||
2637 | //check for bssid | 2693 | //check for bssid |
2638 | if (memcmp(&(wlanIeeeHeader->i_addr3), &mac_bssid, sizeof(struct MacAddress)) | 2694 | if (memcmp(&(wlanIeeeHeader->i_addr3), &mac_bssid, |
2639 | == 0) | 2695 | sizeof(struct MacAddress)) == 0) |
2640 | { | 2696 | { |
2641 | //check for broadcast or mac | 2697 | //check for broadcast or mac |
2642 | if (memcmp(&(wlanIeeeHeader->i_addr1), &bc_all_mac, | 2698 | if (memcmp(&(wlanIeeeHeader->i_addr1), &bc_all_mac, |
@@ -2654,11 +2710,10 @@ wlan_process_helper(void *cls, void *client, | |||
2654 | 2710 | ||
2655 | session_light = GNUNET_malloc(sizeof(struct Session_light)); | 2711 | session_light = GNUNET_malloc(sizeof(struct Session_light)); |
2656 | memcpy(&session_light->addr, &(wlanIeeeHeader->i_addr2), | 2712 | memcpy(&session_light->addr, &(wlanIeeeHeader->i_addr2), |
2657 | sizeof(struct MacAddress)); | 2713 | sizeof(struct MacAddress)); |
2658 | //session_light->session = search_session(plugin,session_light->addr); | 2714 | //session_light->session = search_session(plugin,session_light->addr); |
2659 | 2715 | ||
2660 | pos = 0; | 2716 | pos = 0; |
2661 | temp_hdr = (struct GNUNET_MessageHeader *) &wlanIeeeHeader[1]; | ||
2662 | while (pos < datasize) | 2717 | while (pos < datasize) |
2663 | { | 2718 | { |
2664 | temp_hdr = (struct GNUNET_MessageHeader *) &wlanIeeeHeader[1] | 2719 | temp_hdr = (struct GNUNET_MessageHeader *) &wlanIeeeHeader[1] |
@@ -2836,6 +2891,8 @@ libgnunet_plugin_transport_wlan_done(void *cls) | |||
2836 | { | 2891 | { |
2837 | struct GNUNET_TRANSPORT_PluginFunctions *api = cls; | 2892 | struct GNUNET_TRANSPORT_PluginFunctions *api = cls; |
2838 | struct Plugin *plugin = api->cls; | 2893 | struct Plugin *plugin = api->cls; |
2894 | struct Sessionqueue * queue = plugin->sessions; | ||
2895 | struct FragmentMessage * fm; | ||
2839 | 2896 | ||
2840 | #if DEBUG_wlan | 2897 | #if DEBUG_wlan |
2841 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2898 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
@@ -2850,7 +2907,21 @@ libgnunet_plugin_transport_wlan_done(void *cls) | |||
2850 | if (plugin->data_tokenizer != NULL) | 2907 | if (plugin->data_tokenizer != NULL) |
2851 | GNUNET_SERVER_mst_destroy(plugin->data_tokenizer); | 2908 | GNUNET_SERVER_mst_destroy(plugin->data_tokenizer); |
2852 | 2909 | ||
2910 | |||
2911 | fm = (struct FragmentMessage *) GNUNET_CONTAINER_heap_peek(plugin->pending_Fragment_Messages); | ||
2912 | while (fm != NULL){ | ||
2913 | free_fragment_message(plugin, fm); | ||
2914 | fm = (struct FragmentMessage *) GNUNET_CONTAINER_heap_peek(plugin->pending_Fragment_Messages); | ||
2915 | } | ||
2916 | |||
2917 | //free sessions | ||
2918 | while (queue != NULL) | ||
2919 | { | ||
2920 | free_session(plugin, queue); | ||
2921 | } | ||
2922 | |||
2853 | GNUNET_free_non_null(plugin->interface); | 2923 | GNUNET_free_non_null(plugin->interface); |
2924 | GNUNET_CONTAINER_heap_destroy(plugin->pending_Fragment_Messages); | ||
2854 | GNUNET_free (plugin); | 2925 | GNUNET_free (plugin); |
2855 | GNUNET_free (api); | 2926 | GNUNET_free (api); |
2856 | return NULL; | 2927 | return NULL; |
@@ -2880,6 +2951,8 @@ libgnunet_plugin_transport_wlan_init(void *cls) | |||
2880 | plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK; | 2951 | plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK; |
2881 | plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK; | 2952 | plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK; |
2882 | plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK; | 2953 | plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK; |
2954 | plugin->pending_Fragment_Messages = GNUNET_CONTAINER_heap_create( | ||
2955 | GNUNET_CONTAINER_HEAP_ORDER_MIN); | ||
2883 | 2956 | ||
2884 | plugin->suid_tokenizer = GNUNET_SERVER_mst_create(&wlan_process_helper, | 2957 | plugin->suid_tokenizer = GNUNET_SERVER_mst_create(&wlan_process_helper, |
2885 | plugin); | 2958 | plugin); |
diff --git a/src/transport/wlan/loopback_helper.c b/src/transport/wlan/loopback_helper.c index ec9096d6f..aa3b6d8af 100644 --- a/src/transport/wlan/loopback_helper.c +++ b/src/transport/wlan/loopback_helper.c | |||
@@ -27,7 +27,7 @@ | |||
27 | #include "loopback_helper.h" | 27 | #include "loopback_helper.h" |
28 | #include "helper_common.h" | 28 | #include "helper_common.h" |
29 | 29 | ||
30 | extern int first; | 30 | int first; |
31 | 31 | ||
32 | static void | 32 | static void |
33 | sigfunc(int sig) | 33 | sigfunc(int sig) |
@@ -114,8 +114,8 @@ testmode(int argc, char *argv[]) | |||
114 | struct stat st; | 114 | struct stat st; |
115 | int erg; | 115 | int erg; |
116 | 116 | ||
117 | FILE *fpin; | 117 | FILE *fpin = NULL; |
118 | FILE *fpout; | 118 | FILE *fpout = NULL; |
119 | 119 | ||
120 | int fdpin; | 120 | int fdpin; |
121 | int fdpout; | 121 | int fdpout; |
@@ -165,13 +165,13 @@ testmode(int argc, char *argv[]) | |||
165 | if (NULL == fpin) | 165 | if (NULL == fpin) |
166 | { | 166 | { |
167 | fprintf(stderr, "fopen of read FIFO_FILE1\n"); | 167 | fprintf(stderr, "fopen of read FIFO_FILE1\n"); |
168 | goto end2; | 168 | goto end; |
169 | } | 169 | } |
170 | fpout = fopen(FIFO_FILE2, "w"); | 170 | fpout = fopen(FIFO_FILE2, "w"); |
171 | if (NULL == fpout) | 171 | if (NULL == fpout) |
172 | { | 172 | { |
173 | fprintf(stderr, "fopen of write FIFO_FILE2\n"); | 173 | fprintf(stderr, "fopen of write FIFO_FILE2\n"); |
174 | goto end1; | 174 | goto end; |
175 | } | 175 | } |
176 | 176 | ||
177 | } | 177 | } |
@@ -183,34 +183,35 @@ testmode(int argc, char *argv[]) | |||
183 | if (NULL == fpout) | 183 | if (NULL == fpout) |
184 | { | 184 | { |
185 | fprintf(stderr, "fopen of write FIFO_FILE1\n"); | 185 | fprintf(stderr, "fopen of write FIFO_FILE1\n"); |
186 | goto end1; | 186 | goto end; |
187 | } | 187 | } |
188 | fpin = fopen(FIFO_FILE2, "r"); | 188 | fpin = fopen(FIFO_FILE2, "r"); |
189 | if (NULL == fpin) | 189 | if (NULL == fpin) |
190 | { | 190 | { |
191 | fprintf(stderr, "fopen of read FIFO_FILE2\n"); | 191 | fprintf(stderr, "fopen of read FIFO_FILE2\n"); |
192 | goto end1; | 192 | goto end; |
193 | } | 193 | } |
194 | 194 | ||
195 | |||
196 | } | 195 | } |
197 | 196 | ||
198 | fdpin = fileno(fpin); | 197 | fdpin = fileno(fpin); |
198 | GNUNET_assert(fpin >= 0); | ||
199 | |||
199 | if (fdpin >= FD_SETSIZE) | 200 | if (fdpin >= FD_SETSIZE) |
200 | { | 201 | { |
201 | fprintf(stderr, "File fdpin number too large (%d > %u)\n", fdpin, | 202 | fprintf(stderr, "File fdpin number too large (%d > %u)\n", fdpin, |
202 | (unsigned int) FD_SETSIZE); | 203 | (unsigned int) FD_SETSIZE); |
203 | close(fdpin); | 204 | goto end; |
204 | return -1; | ||
205 | } | 205 | } |
206 | 206 | ||
207 | fdpout = fileno(fpout); | 207 | fdpout = fileno(fpout); |
208 | GNUNET_assert(fdpout >= 0 ); | ||
209 | |||
208 | if (fdpout >= FD_SETSIZE) | 210 | if (fdpout >= FD_SETSIZE) |
209 | { | 211 | { |
210 | fprintf(stderr, "File fdpout number too large (%d > %u)\n", fdpout, | 212 | fprintf(stderr, "File fdpout number too large (%d > %u)\n", fdpout, |
211 | (unsigned int) FD_SETSIZE); | 213 | (unsigned int) FD_SETSIZE); |
212 | close(fdpout); | 214 | goto end; |
213 | return -1; | ||
214 | 215 | ||
215 | } | 216 | } |
216 | 217 | ||
@@ -300,7 +301,7 @@ testmode(int argc, char *argv[]) | |||
300 | //wait | 301 | //wait |
301 | tv.tv_sec = 2; | 302 | tv.tv_sec = 2; |
302 | tv.tv_usec = 0; | 303 | tv.tv_usec = 0; |
303 | retval = select(0, NULL, NULL, NULL, &tv); | 304 | select(0, NULL, NULL, NULL, &tv); |
304 | 305 | ||
305 | while (0 == closeprog) | 306 | while (0 == closeprog) |
306 | { | 307 | { |
@@ -346,7 +347,8 @@ testmode(int argc, char *argv[]) | |||
346 | if (0 > retval) | 347 | if (0 > retval) |
347 | { | 348 | { |
348 | fprintf(stderr, "select failed: %s\n", strerror(errno)); | 349 | fprintf(stderr, "select failed: %s\n", strerror(errno)); |
349 | exit(1); | 350 | closeprog = 1; |
351 | break; | ||
350 | } | 352 | } |
351 | 353 | ||
352 | if (FD_ISSET(STDOUT_FILENO, &wfds)) | 354 | if (FD_ISSET(STDOUT_FILENO, &wfds)) |
@@ -358,7 +360,7 @@ testmode(int argc, char *argv[]) | |||
358 | { | 360 | { |
359 | closeprog = 1; | 361 | closeprog = 1; |
360 | fprintf(stderr, "Write ERROR to STDOUT\n"); | 362 | fprintf(stderr, "Write ERROR to STDOUT\n"); |
361 | exit(1); | 363 | break; |
362 | } | 364 | } |
363 | else | 365 | else |
364 | { | 366 | { |
@@ -424,7 +426,7 @@ testmode(int argc, char *argv[]) | |||
424 | { | 426 | { |
425 | closeprog = 1; | 427 | closeprog = 1; |
426 | fprintf(stderr, "Read ERROR to fdpin: %s\n", strerror(errno)); | 428 | fprintf(stderr, "Read ERROR to fdpin: %s\n", strerror(errno)); |
427 | closeprog = 1; | 429 | break; |
428 | } | 430 | } |
429 | else if (0 < readsize) | 431 | else if (0 < readsize) |
430 | { | 432 | { |
@@ -445,8 +447,11 @@ testmode(int argc, char *argv[]) | |||
445 | 447 | ||
446 | GNUNET_SERVER_mst_destroy(stdin_mst); | 448 | GNUNET_SERVER_mst_destroy(stdin_mst); |
447 | GNUNET_SERVER_mst_destroy(file_in_mst); | 449 | GNUNET_SERVER_mst_destroy(file_in_mst); |
448 | end1: fclose(fpout); | 450 | |
449 | end2: fclose(fpin); | 451 | end: if (fpout != NULL) |
452 | fclose(fpout); | ||
453 | if (fpin != NULL) | ||
454 | fclose(fpin); | ||
450 | 455 | ||
451 | if (1 == first) | 456 | if (1 == first) |
452 | { | 457 | { |