aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_unix.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-01-27 14:30:28 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-01-27 14:30:28 +0000
commit240e3109cde69be3752a44b8ed7799599171fc80 (patch)
tree94f4c2579aeabb9bd4a7f8506dca2a58161f8836 /src/transport/plugin_transport_unix.c
parent3d6d182f86ba766bc31223853508449dde5dee38 (diff)
downloadgnunet-240e3109cde69be3752a44b8ed7799599171fc80.tar.gz
gnunet-240e3109cde69be3752a44b8ed7799599171fc80.zip
removing retry code
removing unused structs removing UDP Address structs fixed PrettyPrinter (printed UDP addresses???)
Diffstat (limited to 'src/transport/plugin_transport_unix.c')
-rw-r--r--src/transport/plugin_transport_unix.c246
1 files changed, 57 insertions, 189 deletions
diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c
index 294ef5fd0..0c8722eab 100644
--- a/src/transport/plugin_transport_unix.c
+++ b/src/transport/plugin_transport_unix.c
@@ -85,6 +85,13 @@ struct UNIXMessage
85 85
86}; 86};
87 87
88struct Session
89{
90 void *addr;
91 size_t addrlen;
92 struct GNUNET_PeerIdentity target;
93};
94
88struct UNIXMessageWrapper 95struct UNIXMessageWrapper
89{ 96{
90 struct UNIXMessageWrapper *next; 97 struct UNIXMessageWrapper *next;
@@ -107,125 +114,9 @@ struct UNIXMessageWrapper
107 void *cont_cls; 114 void *cont_cls;
108}; 115};
109 116
110/**
111 * Network format for IPv4 addresses.
112 */
113struct IPv4UdpAddress
114{
115 /**
116 * IPv4 address, in network byte order.
117 */
118 uint32_t ipv4_addr GNUNET_PACKED;
119
120 /**
121 * Port number, in network byte order.
122 */
123 uint16_t u_port GNUNET_PACKED;
124};
125
126
127/**
128 * Network format for IPv6 addresses.
129 */
130struct IPv6UdpAddress
131{
132 /**
133 * IPv6 address.
134 */
135 struct in6_addr ipv6_addr GNUNET_PACKED;
136
137 /**
138 * Port number, in network byte order.
139 */
140 uint16_t u6_port GNUNET_PACKED;
141};
142GNUNET_NETWORK_STRUCT_END
143
144/* Forward definition */ 117/* Forward definition */
145struct Plugin; 118struct Plugin;
146 119
147struct PrettyPrinterContext
148{
149 GNUNET_TRANSPORT_AddressStringCallback asc;
150 void *asc_cls;
151 uint16_t port;
152};
153
154struct RetrySendContext
155{
156
157 /**
158 * Main plugin handle.
159 */
160 struct Plugin *plugin;
161
162 /**
163 * Address of recipient.
164 */
165 char *addr;
166
167 /**
168 * Length of address.
169 */
170 ssize_t addrlen;
171
172 /**
173 * Message to send.
174 */
175 char *msg;
176
177 /**
178 * Size of the message.
179 */
180 int msg_size;
181
182 /**
183 * Handle to send message out on.
184 */
185 struct GNUNET_NETWORK_Handle *send_handle;
186
187 /**
188 * Continuation to call on success or
189 * timeout.
190 */
191 GNUNET_TRANSPORT_TransmitContinuation cont;
192
193 /**
194 * Closure for continuation.
195 */
196 void *cont_cls;
197
198 /**
199 * The peer the message is destined for.
200 */
201 struct GNUNET_PeerIdentity target;
202
203 /**
204 * How long before not retrying any longer.
205 */
206 struct GNUNET_TIME_Absolute timeout;
207
208 /**
209 * How long the last message was delayed.
210 */
211 struct GNUNET_TIME_Relative delay;
212
213 /**
214 * The actual retry task.
215 */
216 GNUNET_SCHEDULER_TaskIdentifier retry_task;
217
218 /**
219 * The priority of the message.
220 */
221 unsigned int priority;
222
223 /**
224 * Entry in the DLL of retry items.
225 */
226 struct RetryList *retry_list_entry;
227};
228
229 120
230/** 121/**
231 * UNIX NAT "Session" 122 * UNIX NAT "Session"
@@ -310,6 +201,11 @@ struct Plugin
310 */ 201 */
311 struct PeerSession *sessions; 202 struct PeerSession *sessions;
312 203
204 /*
205 * Sessions
206 */
207 struct GNUNET_CONTAINER_MultiHashMap *session_map;
208
313 /** 209 /**
314 * ID of task used to update our addresses when one expires. 210 * ID of task used to update our addresses when one expires.
315 */ 211 */
@@ -423,15 +319,6 @@ find_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *peer)
423 return pos; 319 return pos;
424} 320}
425 321
426/* Forward Declaration */
427static ssize_t
428unix_real_send (void *cls, struct RetrySendContext *incoming_retry_context,
429 struct GNUNET_NETWORK_Handle *send_handle,
430 const struct GNUNET_PeerIdentity *target, const char *msgbuf,
431 size_t msgbuf_size, unsigned int priority,
432 struct GNUNET_TIME_Relative timeout, const void *addr,
433 size_t addrlen, GNUNET_TRANSPORT_TransmitContinuation cont,
434 void *cont_cls);
435 322
436/** 323/**
437 * Actually send out the message, assume we've got the address and 324 * Actually send out the message, assume we've got the address and
@@ -456,7 +343,7 @@ unix_real_send (void *cls, struct RetrySendContext *incoming_retry_context,
456 * @return the number of bytes written, -1 on errors 343 * @return the number of bytes written, -1 on errors
457 */ 344 */
458static ssize_t 345static ssize_t
459unix_real_send (void *cls, struct RetrySendContext *incoming_retry_context, 346unix_real_send (void *cls,
460 struct GNUNET_NETWORK_Handle *send_handle, 347 struct GNUNET_NETWORK_Handle *send_handle,
461 const struct GNUNET_PeerIdentity *target, const char *msgbuf, 348 const struct GNUNET_PeerIdentity *target, const char *msgbuf,
462 size_t msgbuf_size, unsigned int priority, 349 size_t msgbuf_size, unsigned int priority,
@@ -572,6 +459,26 @@ unix_real_send (void *cls, struct RetrySendContext *incoming_retry_context,
572 return sent; 459 return sent;
573} 460}
574 461
462struct gsi_ctx
463{
464 const struct GNUNET_HELLO_Address *address;
465 struct Session *res;
466};
467
468static int
469get_session_it (void *cls, const GNUNET_HashCode * key, void *value)
470{
471 struct gsi_ctx *gsi = cls;
472 struct Session *s = value;
473
474 if ((gsi->address->address_length == s->addrlen) &&
475 (0 == memcmp (gsi->address->address, s->addr, s->addrlen)))
476 {
477 gsi->res = s;
478 return GNUNET_NO;
479 }
480 return GNUNET_YES;
481}
575 482
576/** 483/**
577 * Creates a new outbound session the transport service will use to send data to the 484 * Creates a new outbound session the transport service will use to send data to the
@@ -581,12 +488,25 @@ unix_real_send (void *cls, struct RetrySendContext *incoming_retry_context,
581 * @param address the address 488 * @param address the address
582 * @return the session or NULL of max connections exceeded 489 * @return the session or NULL of max connections exceeded
583 */ 490 */
584
585static struct Session * 491static struct Session *
586unix_plugin_get_session (void *cls, 492unix_plugin_get_session (void *cls,
587 const struct GNUNET_HELLO_Address *address) 493 const struct GNUNET_HELLO_Address *address)
588{ 494{
589 struct Session * s = NULL; 495 struct Session * s = NULL;
496 struct Plugin *plugin = cls;
497 struct gsi_ctx gsi;
498
499 /* Checks */
500 GNUNET_assert (plugin != NULL);
501 GNUNET_assert (address != NULL);
502
503 /* Check if already existing */
504 gsi.address = address;
505 gsi.res = NULL;
506 GNUNET_CONTAINER_multihashmap_get_multiple (plugin->session_map, &address->peer.hashPubKey, &get_session_it, &gsi);
507
508 /* Create a new session */
509
590 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "To be implemented\n"); 510 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "To be implemented\n");
591 GNUNET_break (0); 511 GNUNET_break (0);
592 return s; 512 return s;
@@ -815,7 +735,7 @@ unix_plugin_select_write (struct Plugin * plugin)
815 int sent = 0; 735 int sent = 0;
816 struct UNIXMessageWrapper * msgw = plugin->msg_head; 736 struct UNIXMessageWrapper * msgw = plugin->msg_head;
817 737
818 sent = unix_real_send (plugin, NULL, 738 sent = unix_real_send (plugin,
819 plugin->unix_sock.desc, 739 plugin->unix_sock.desc,
820 &msgw->target, 740 &msgw->target,
821 (const char *) msgw->msg, 741 (const char *) msgw->msg,
@@ -1001,27 +921,6 @@ unix_check_address (void *cls, const void *addr, size_t addrlen)
1001 921
1002 922
1003/** 923/**
1004 * Append our port and forward the result.
1005 */
1006static void
1007append_port (void *cls, const char *hostname)
1008{
1009 struct PrettyPrinterContext *ppc = cls;
1010 char *ret;
1011
1012 if (hostname == NULL)
1013 {
1014 ppc->asc (ppc->asc_cls, NULL);
1015 GNUNET_free (ppc);
1016 return;
1017 }
1018 GNUNET_asprintf (&ret, "%s:%d", hostname, ppc->port);
1019 ppc->asc (ppc->asc_cls, ret);
1020 GNUNET_free (ret);
1021}
1022
1023
1024/**
1025 * Convert the transports address to a nice, human-readable 924 * Convert the transports address to a nice, human-readable
1026 * format. 925 * format.
1027 * 926 *
@@ -1043,49 +942,14 @@ unix_plugin_address_pretty_printer (void *cls, const char *type,
1043 GNUNET_TRANSPORT_AddressStringCallback asc, 942 GNUNET_TRANSPORT_AddressStringCallback asc,
1044 void *asc_cls) 943 void *asc_cls)
1045{ 944{
1046 struct PrettyPrinterContext *ppc; 945 if ((addr != NULL) && (addrlen > 0))
1047 const void *sb; 946 asc (asc_cls, (const char *) addr);
1048 size_t sbs;
1049 struct sockaddr_in a4;
1050 struct sockaddr_in6 a6;
1051 const struct IPv4UdpAddress *u4;
1052 const struct IPv6UdpAddress *u6;
1053 uint16_t port;
1054
1055 if (addrlen == sizeof (struct IPv6UdpAddress))
1056 {
1057 u6 = addr;
1058 memset (&a6, 0, sizeof (a6));
1059 a6.sin6_family = AF_INET6;
1060 a6.sin6_port = u6->u6_port;
1061 memcpy (&a6.sin6_addr, &u6->ipv6_addr, sizeof (struct in6_addr));
1062 port = ntohs (u6->u6_port);
1063 sb = &a6;
1064 sbs = sizeof (a6);
1065 }
1066 else if (addrlen == sizeof (struct IPv4UdpAddress))
1067 {
1068 u4 = addr;
1069 memset (&a4, 0, sizeof (a4));
1070 a4.sin_family = AF_INET;
1071 a4.sin_port = u4->u_port;
1072 a4.sin_addr.s_addr = u4->ipv4_addr;
1073 port = ntohs (u4->u_port);
1074 sb = &a4;
1075 sbs = sizeof (a4);
1076 }
1077 else 947 else
1078 { 948 {
1079 /* invalid address */ 949 GNUNET_break (0);
1080 GNUNET_break_op (0); 950 asc (asc_cls, "Invalid UNIX address");
1081 asc (asc_cls, NULL);
1082 return;
1083 } 951 }
1084 ppc = GNUNET_malloc (sizeof (struct PrettyPrinterContext)); 952
1085 ppc->asc = asc;
1086 ppc->asc_cls = asc_cls;
1087 ppc->port = port;
1088 GNUNET_RESOLVER_hostname_get (sb, sbs, !numeric, timeout, &append_port, ppc);
1089} 953}
1090 954
1091/** 955/**
@@ -1161,6 +1025,8 @@ libgnunet_plugin_transport_unix_init (void *cls)
1161 if (sockets_created == 0) 1025 if (sockets_created == 0)
1162 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to open UNIX sockets\n")); 1026 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to open UNIX sockets\n"));
1163 1027
1028 plugin->session_map = GNUNET_CONTAINER_multihashmap_create(10);
1029
1164 GNUNET_SCHEDULER_add_now (address_notification, plugin); 1030 GNUNET_SCHEDULER_add_now (address_notification, plugin);
1165 return api; 1031 return api;
1166} 1032}
@@ -1173,6 +1039,8 @@ libgnunet_plugin_transport_unix_done (void *cls)
1173 1039
1174 unix_transport_server_stop (plugin); 1040 unix_transport_server_stop (plugin);
1175 1041
1042 GNUNET_CONTAINER_multihashmap_destroy (plugin->session_map);
1043
1176 GNUNET_NETWORK_fdset_destroy (plugin->rs); 1044 GNUNET_NETWORK_fdset_destroy (plugin->rs);
1177 GNUNET_NETWORK_fdset_destroy (plugin->ws); 1045 GNUNET_NETWORK_fdset_destroy (plugin->ws);
1178 GNUNET_free (plugin->unix_socket_path); 1046 GNUNET_free (plugin->unix_socket_path);