return GNUNET_SYSERR;
}
- ret = papi->send_with_session (papi->cls,
- n->session,
- msgbuf, msgbuf_size,
- 0,
- timeout,
- cont, cont_cls);
+ ret = papi->send (papi->cls,
+ n->session,
+ msgbuf, msgbuf_size,
+ 0,
+ timeout,
+ cont, cont_cls);
if ((ret == -1) && (cont != NULL))
cont (cont_cls, &n->id, GNUNET_SYSERR);
if (session != NULL)
{
- ret = papi->send_with_session (papi->cls, session,
+ ret = papi->send (papi->cls, session,
message_buf, tsize,
PING_PRIORITY, ACCEPTABLE_PING_DELAY,
NULL, NULL);
return;
}
- papi->send_with_session (papi->cls, session,
+ papi->send (papi->cls, session,
(const char *) pong, ntohs (pong->header.size),
PONG_PRIORITY, ACCEPTABLE_PING_DELAY,
NULL, NULL);
}
else
{
- ret = papi->send_with_session (papi->cls, session,
+ ret = papi->send (papi->cls, session,
(const char *) pong, ntohs (pong->header.size),
PONG_PRIORITY, ACCEPTABLE_PING_DELAY,
NULL, NULL);
}
-/**
- * Function that can be used by the transport service to transmit
- * a message using the plugin. Note that in the case of a
- * peer disconnecting, the continuation MUST be called
- * prior to the disconnect notification itself. This function
- * will be called with this peer's HELLO message to initiate
- * a fresh connection to another peer.
- *
- * @param cls closure
- * @param target who should receive this message
- * @param msgbuf the message to transmit
- * @param msgbuf_size number of bytes in 'msgbuf'
- * @param priority how important is the message (most plugins will
- * ignore message priority and just FIFO)
- * @param to how long to wait at most for the transmission (does not
- * require plugins to discard the message after the timeout,
- * just advisory for the desired delay; most plugins will ignore
- * this as well)
- * @param session which session must be used (or NULL for "any")
- * @param addr the address to use (can be NULL if the plugin
- * is "on its own" (i.e. re-use existing TCP connection))
- * @param addrlen length of the address in bytes
- * @param force_address GNUNET_YES if the plugin MUST use the given address,
- * GNUNET_NO means the plugin may use any other address and
- * GNUNET_SYSERR means that only reliable existing
- * bi-directional connections should be used (regardless
- * of address)
- * @param cont continuation to call once the message has
- * been transmitted (or if the transport is ready
- * for the next transmission call; or if the
- * peer disconnected...); can be NULL
- * @param cont_cls closure for cont
- * @return number of bytes used (on the physical network, with overheads);
- * -1 on hard errors (i.e. address invalid); 0 is a legal value
- * and does NOT mean that the message was not transmitted (DV)
- */
-static ssize_t
-http_plugin_send_old (void *cls, const struct GNUNET_PeerIdentity *target,
- const char *msgbuf, size_t msgbuf_size, unsigned int priority,
- struct GNUNET_TIME_Relative to, struct Session *session,
- const void *addr, size_t addrlen, int force_address,
- GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
-{
- struct Plugin *plugin = cls;
- struct HTTP_Message *msg;
- struct Session *s;
-
- GNUNET_assert (plugin != NULL);
-
- int res = GNUNET_SYSERR;
-
-#if DEBUG_HTTP
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Sending %u bytes to peer `%s' on address `%s' %X %i\n",
- msgbuf_size, GNUNET_i2s (target), ((addr != NULL) &&
- (addrlen !=
- 0)) ?
- http_plugin_address_to_string (plugin, addr,
- addrlen) : "<inbound>",
- session, force_address);
-#endif
-
-
-
- if (addrlen != 0)
- GNUNET_assert ((addrlen == sizeof (struct IPv4HttpAddress)) ||
- (addrlen == sizeof (struct IPv6HttpAddress)));
- /* look for existing connection */
- s = lookup_session_old (plugin, target, session, addr, addrlen, 1);
-#if DEBUG_HTTP
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "%s existing session: %s\n",
- (s != NULL) ? "Found" : "NOT Found", ((s != NULL) &&
- (s->inbound ==
- GNUNET_YES)) ?
- "inbound" : "outbound");
-#endif
- /* create new outbound connection */
- if (s == NULL)
- {
- if (plugin->max_connections <= plugin->cur_connections)
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, plugin->name,
- "Maximum number of connections reached, "
- "cannot connect to peer `%s'\n", GNUNET_i2s (target));
- return res;
- }
-
-#if DEBUG_HTTP
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Initiiating new connection to peer `%s'\n",
- GNUNET_i2s (target));
-#endif
-/* AAAAAAAAAAAAAAAAAAA */
- int res = GNUNET_OK;
- struct GNUNET_ATS_Information ats;
- if ((addrlen == sizeof (struct IPv4HttpAddress)) && (addr != NULL))
- {
- struct IPv4HttpAddress *a4 = (struct IPv4HttpAddress *) addr;
- struct sockaddr_in s4;
-
- s4.sin_family = AF_INET;
- s4.sin_addr.s_addr = a4->ipv4_addr;
- s4.sin_port = a4->u4_port;
-#if HAVE_SOCKADDR_IN_SIN_LEN
- s4.sin_len = sizeof (struct sockaddr_in);
-#endif
- ats = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) &s4, sizeof (struct sockaddr_in));
-
- if ((ntohs (a4->u4_port) == 0) || (plugin->ipv4 == GNUNET_NO))
- res = GNUNET_SYSERR;
- }
- if ((addrlen == sizeof (struct IPv6HttpAddress)) && (addr != NULL))
- {
- struct IPv6HttpAddress *a6 = (struct IPv6HttpAddress *) addr;
- struct sockaddr_in6 s6;
-
- s6.sin6_family = AF_INET6;
- s6.sin6_addr = a6->ipv6_addr;
- s6.sin6_port = a6->u6_port;
-#if HAVE_SOCKADDR_IN_SIN_LEN
- s6.sin6_len = sizeof (struct sockaddr_in6);
-#endif
- ats = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) &s6, sizeof (struct sockaddr_in6));
-
- if ((ntohs (a6->u6_port) == 0) || (plugin->ipv6 == GNUNET_NO))
- res = GNUNET_SYSERR;
- }
- if (res == GNUNET_OK)
- {
- s = create_session (plugin, target, addr, addrlen, cont, cont_cls);
- s->ats_address_network_type = ats.value;
- GNUNET_CONTAINER_DLL_insert (plugin->head, plugin->tail, s);
- // initiate new connection
- res = client_connect (s);
- }
- if (res == GNUNET_SYSERR)
- {
- if (s != NULL)
- {
- GNUNET_CONTAINER_DLL_remove (plugin->head, plugin->tail, s);
- delete_session (s);
- }
- return GNUNET_SYSERR;
- }
- }
-
- /* real sending */
-
- msg = GNUNET_malloc (sizeof (struct HTTP_Message) + msgbuf_size);
- msg->next = NULL;
- msg->size = msgbuf_size;
- msg->pos = 0;
- msg->buf = (char *) &msg[1];
- msg->transmit_cont = cont;
- msg->transmit_cont_cls = cont_cls;
- memcpy (msg->buf, msgbuf, msgbuf_size);
-
- if (s->inbound == GNUNET_NO)
- {
-#if DEBUG_HTTP
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Using outbound client session %p to send to `%s'\n", s,
- GNUNET_i2s (target));
-#endif
-
- client_send (s, msg);
- res = msgbuf_size;
- }
- if (s->inbound == GNUNET_YES)
- {
-#if DEBUG_HTTP
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Using inbound server %p session to send to `%s'\n", s,
- GNUNET_i2s (target));
-#endif
-
- server_send (s, msg);
- res = msgbuf_size;
- }
- return res;
-}
-
/**
* Function that can be used to force the plugin to disconnect
plugin->env = env;
api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
api->cls = plugin;
- api->send = &http_plugin_send_old;
api->disconnect = &http_plugin_disconnect;
api->address_pretty_printer = &http_plugin_address_pretty_printer;
api->check_address = &http_plugin_address_suggested;
api->address_to_string = &http_plugin_address_to_string;
api->get_session = &http_get_session;
- api->send_with_session = &http_plugin_send;
+ api->send = &http_plugin_send;
#if BUILD_HTTPS
plugin->name = "transport-https";
}
-/**
- * Given two otherwise equivalent sessions, pick the better one.
- *
- * @param s1 one session (also default)
- * @param s2 other session
- * @return "better" session (more active)
- */
-static struct Session *
-select_better_session (struct Session *s1, struct Session *s2)
-{
- if (s1 == NULL)
- return s2;
- if (s2 == NULL)
- return s1;
- if ((s1->expecting_welcome == GNUNET_NO) &&
- (s2->expecting_welcome == GNUNET_YES))
- return s1;
- if ((s1->expecting_welcome == GNUNET_YES) &&
- (s2->expecting_welcome == GNUNET_NO))
- return s2;
- if (s1->last_activity.abs_value < s2->last_activity.abs_value)
- return s2;
- if (s1->last_activity.abs_value > s2->last_activity.abs_value)
- return s1;
- if ((GNUNET_YES == s1->inbound) && (GNUNET_NO == s2->inbound))
- return s1;
- if ((GNUNET_NO == s1->inbound) && (GNUNET_YES == s2->inbound))
- return s2;
- return s1;
-}
-
-
-
-/**
- * Function that can be used by the transport service to transmit
- * a message using the plugin. Note that in the case of a
- * peer disconnecting, the continuation MUST be called
- * prior to the disconnect notification itself. This function
- * will be called with this peer's HELLO message to initiate
- * a fresh connection to another peer.
- *
- * @param cls closure
- * @param target who should receive this message
- * @param msg the message to transmit
- * @param msgbuf_size number of bytes in 'msg'
- * @param priority how important is the message (most plugins will
- * ignore message priority and just FIFO)
- * @param timeout how long to wait at most for the transmission (does not
- * require plugins to discard the message after the timeout,
- * just advisory for the desired delay; most plugins will ignore
- * this as well)
- * @param session which session must be used (or NULL for "any")
- * @param addr the address to use (can be NULL if the plugin
- * is "on its own" (i.e. re-use existing TCP connection))
- * @param addrlen length of the address in bytes
- * @param force_address GNUNET_YES if the plugin MUST use the given address,
- * GNUNET_NO means the plugin may use any other address and
- * GNUNET_SYSERR means that only reliable existing
- * bi-directional connections should be used (regardless
- * of address)
- * @param cont continuation to call once the message has
- * been transmitted (or if the transport is ready
- * for the next transmission call; or if the
- * peer disconnected...); can be NULL
- * @param cont_cls closure for cont
- * @return number of bytes used (on the physical network, with overheads);
- * -1 on hard errors (i.e. address invalid); 0 is a legal value
- * and does NOT mean that the message was not transmitted (DV and NAT)
- */
-static ssize_t
-tcp_plugin_send_old (void *cls, const struct GNUNET_PeerIdentity *target,
- const char *msg, size_t msgbuf_size, uint32_t priority,
- struct GNUNET_TIME_Relative timeout, struct Session *session,
- const void *addr, size_t addrlen, int force_address,
- GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
-{
- struct Plugin *plugin = cls;
- struct Session *cand_session;
- struct Session *next;
- struct PendingMessage *pm;
- struct GNUNET_CONNECTION_Handle *sa;
- int af;
- const void *sb;
- size_t sbs;
- struct sockaddr_in a4;
- struct sockaddr_in6 a6;
- const struct IPv4TcpAddress *t4;
- const struct IPv6TcpAddress *t6;
- unsigned int is_natd;
-
- GNUNET_STATISTICS_update (plugin->env->stats,
- gettext_noop ("# bytes TCP was asked to transmit"),
- msgbuf_size, GNUNET_NO);
- /* FIXME: we could do this cheaper with a hash table
- * where we could restrict the iteration to entries that match
- * the target peer... */
- is_natd = GNUNET_NO;
- if (session == NULL)
- {
- cand_session = NULL;
- next = plugin->sessions;
- while (NULL != (session = next))
- {
- next = session->next;
- GNUNET_assert (session->client != NULL);
- if (0 !=
- memcmp (target, &session->target,
- sizeof (struct GNUNET_PeerIdentity)))
- continue;
- if (((GNUNET_SYSERR == force_address) &&
- (session->expecting_welcome == GNUNET_NO)) ||
- (GNUNET_NO == force_address))
- {
- cand_session = select_better_session (cand_session, session);
- continue;
- }
- if (GNUNET_SYSERR == force_address)
- continue;
- GNUNET_break (GNUNET_YES == force_address);
- if (addr == NULL)
- {
- GNUNET_break (0);
- break;
- }
- if ((addrlen != session->connect_alen) && (session->is_nat == GNUNET_NO))
- continue;
- if ((0 != memcmp (session->connect_addr, addr, addrlen)) &&
- (session->is_nat == GNUNET_NO))
- continue;
- cand_session = select_better_session (cand_session, session);
- }
- session = cand_session;
- }
- if ((session == NULL) && (addrlen == 0))
- {
-#if DEBUG_TCP
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
- "Asked to transmit to `%4s' without address and I have no existing connection (failing).\n",
- GNUNET_i2s (target));
-#endif
- GNUNET_STATISTICS_update (plugin->env->stats,
- gettext_noop
- ("# bytes discarded by TCP (no address and no connection)"),
- msgbuf_size, GNUNET_NO);
- return -1;
- }
- if (session == NULL)
- {
- if (addrlen == sizeof (struct IPv6TcpAddress))
- {
- GNUNET_assert (NULL != addr); /* make static analysis happy */
- t6 = addr;
- af = AF_INET6;
- memset (&a6, 0, sizeof (a6));
-#if HAVE_SOCKADDR_IN_SIN_LEN
- a6.sin6_len = sizeof (a6);
-#endif
- a6.sin6_family = AF_INET6;
- a6.sin6_port = t6->t6_port;
- if (t6->t6_port == 0)
- is_natd = GNUNET_YES;
- memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof (struct in6_addr));
- sb = &a6;
- sbs = sizeof (a6);
- }
- else if (addrlen == sizeof (struct IPv4TcpAddress))
- {
- GNUNET_assert (NULL != addr); /* make static analysis happy */
- t4 = addr;
- af = AF_INET;
- memset (&a4, 0, sizeof (a4));
-#if HAVE_SOCKADDR_IN_SIN_LEN
- a4.sin_len = sizeof (a4);
-#endif
- a4.sin_family = AF_INET;
- a4.sin_port = t4->t4_port;
- if (t4->t4_port == 0)
- is_natd = GNUNET_YES;
- a4.sin_addr.s_addr = t4->ipv4_addr;
- sb = &a4;
- sbs = sizeof (a4);
- }
- else
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "tcp",
- _("Address of unexpected length: %u\n"), addrlen);
- GNUNET_break (0);
- return -1;
- }
-
- if ((is_natd == GNUNET_YES) && (addrlen == sizeof (struct IPv6TcpAddress)))
- return -1; /* NAT client only works with IPv4 addresses */
- if (0 == plugin->max_connections)
- return -1; /* saturated */
-
- if ((is_natd == GNUNET_YES) && (NULL != plugin->nat) &&
- (GNUNET_NO ==
- GNUNET_CONTAINER_multihashmap_contains (plugin->nat_wait_conns,
- &target->hashPubKey)))
- {
-#if DEBUG_TCP_NAT
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
- _("Found valid IPv4 NAT address (creating session)!\n"));
-#endif
- session = create_session (plugin, target, NULL, GNUNET_YES);
- GNUNET_assert (session != NULL);
-
- /* create new message entry */
- pm = GNUNET_malloc (sizeof (struct PendingMessage) + msgbuf_size);
- /* FIXME: the memset of this malloc can be up to 2% of our total runtime */
- pm->msg = (const char *) &pm[1];
- memcpy (&pm[1], msg, msgbuf_size);
- /* FIXME: this memcpy can be up to 7% of our total run-time
- * (for transport service) */
- pm->message_size = msgbuf_size;
- pm->timeout = GNUNET_TIME_relative_to_absolute (timeout);
- pm->transmit_cont = cont;
- pm->transmit_cont_cls = cont_cls;
-
- /* append pm to pending_messages list */
- GNUNET_CONTAINER_DLL_insert_tail (session->pending_messages_head,
- session->pending_messages_tail, pm);
-
- GNUNET_assert (GNUNET_CONTAINER_multihashmap_put
- (plugin->nat_wait_conns, &target->hashPubKey, session,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) ==
- GNUNET_OK);
-#if DEBUG_TCP_NAT
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
- "Created NAT WAIT connection to `%4s' at `%s'\n",
- GNUNET_i2s (target), GNUNET_a2s (sb, sbs));
-#endif
- GNUNET_NAT_run_client (plugin->nat, &a4);
- return 0;
- }
- if ((is_natd == GNUNET_YES) &&
- (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_contains (plugin->nat_wait_conns,
- &target->hashPubKey)))
- {
- /* Only do one NAT punch attempt per peer identity */
- return -1;
- }
- sa = GNUNET_CONNECTION_create_from_sockaddr (af, sb, sbs);
- if (sa == NULL)
- {
-#if DEBUG_TCP
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
- "Failed to create connection to `%4s' at `%s'\n",
- GNUNET_i2s (target), GNUNET_a2s (sb, sbs));
-#endif
- GNUNET_STATISTICS_update (plugin->env->stats,
- gettext_noop
- ("# bytes discarded by TCP (failed to connect)"),
- msgbuf_size, GNUNET_NO);
- return -1;
- }
- GNUNET_assert (0 != plugin->max_connections);
- plugin->max_connections--;
-#if DEBUG_TCP_NAT
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
- "Asked to transmit to `%4s', creating fresh session using address `%s'.\n",
- GNUNET_i2s (target), GNUNET_a2s (sb, sbs));
-#endif
- session =
- create_session (plugin, target,
- GNUNET_SERVER_connect_socket (plugin->server, sa),
- GNUNET_NO);
- session->connect_addr = GNUNET_malloc (addrlen);
- memcpy (session->connect_addr, addr, addrlen);
- session->connect_alen = addrlen;
- if (addrlen != 0)
- {
- struct GNUNET_ATS_Information ats;
- ats = plugin->env->get_address_type (plugin->env->cls, sb ,sbs);
- session->ats_address_network_type = ats.value;
- }
- else
- GNUNET_break (0);
- }
- else /* session != NULL */
- {
- /* check if session is valid */
- struct Session *ses = plugin->sessions;
-
- if (0 !=
- memcmp (target, &session->target, sizeof (struct GNUNET_PeerIdentity)))
- {
- GNUNET_break (0);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Got session %p for `%s', but should be for peer `%s'!\n",
- session, GNUNET_i2s (&session->target),
- GNUNET_h2s (&target->hashPubKey));
- return -1;
- }
-
- while ((ses != NULL) && (ses != session))
- ses = ses->next;
- if (ses == NULL)
- {
- return -1;
- }
- }
- GNUNET_assert (session != NULL);
- GNUNET_assert (session->client != NULL);
- GNUNET_SERVER_client_set_timeout (session->client,
- GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
- GNUNET_STATISTICS_update (plugin->env->stats,
- gettext_noop ("# bytes currently in TCP buffers"),
- msgbuf_size, GNUNET_NO);
- /* create new message entry */
- pm = GNUNET_malloc (sizeof (struct PendingMessage) + msgbuf_size);
- pm->msg = (const char *) &pm[1];
- memcpy (&pm[1], msg, msgbuf_size);
- pm->message_size = msgbuf_size;
- pm->timeout = GNUNET_TIME_relative_to_absolute (timeout);
- pm->transmit_cont = cont;
- pm->transmit_cont_cls = cont_cls;
-
- /* append pm to pending_messages list */
- GNUNET_CONTAINER_DLL_insert_tail (session->pending_messages_head,
- session->pending_messages_tail, pm);
-#if DEBUG_TCP
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
- "Asked to transmit %u bytes to `%s', added message to list.\n",
- msgbuf_size, GNUNET_i2s (target));
-#endif
- process_pending_messages (session);
- return msgbuf_size;
-}
-
/**
* Function that can be used by the transport service to transmit
* a message using the plugin. Note that in the case of a
}
api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
api->cls = plugin;
- api->send = &tcp_plugin_send_old;
-
- api->send_with_session = &tcp_plugin_send;
+ api->send = &tcp_plugin_send;
api->get_session = &tcp_plugin_get_session;
api->disconnect = &tcp_plugin_disconnect;
};
+
/**
* Function that can be used by the transport service to transmit
- * a message using the plugin.
+ * a message using the plugin. Note that in the case of a
+ * peer disconnecting, the continuation MUST be called
+ * prior to the disconnect notification itself. This function
+ * will be called with this peer's HELLO message to initiate
+ * a fresh connection to another peer.
*
* @param cls closure
- * @param target who should receive this message
- * @param priority how important is the message
+ * @param session which session must be used
* @param msgbuf the message to transmit
* @param msgbuf_size number of bytes in 'msgbuf'
- * @param timeout when should we time out
- * @param session which session must be used (or NULL for "any")
- * @param addr the address to use (can be NULL if the plugin
- * is "on its own" (i.e. re-use existing TCP connection))
- * @param addrlen length of the address in bytes
- * @param force_address GNUNET_YES if the plugin MUST use the given address,
- * otherwise the plugin may use other addresses or
- * existing connections (if available)
+ * @param priority how important is the message (most plugins will
+ * ignore message priority and just FIFO)
+ * @param to how long to wait at most for the transmission (does not
+ * require plugins to discard the message after the timeout,
+ * just advisory for the desired delay; most plugins will ignore
+ * this as well)
* @param cont continuation to call once the message has
* been transmitted (or if the transport is ready
* for the next transmission call; or if the
- * peer disconnected...)
+ * peer disconnected...); can be NULL
* @param cont_cls closure for cont
* @return number of bytes used (on the physical network, with overheads);
* -1 on hard errors (i.e. address invalid); 0 is a legal value
* and does NOT mean that the message was not transmitted (DV)
*/
static ssize_t
-template_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
- const char *msgbuf, size_t msgbuf_size,
- unsigned int priority,
- struct GNUNET_TIME_Relative timeout,
- struct Session *session, const void *addr, size_t addrlen,
- int force_address,
- GNUNET_TRANSPORT_TransmitContinuation cont,
- void *cont_cls)
+template_plugin_send (void *cls,
+ struct Session *session,
+ const char *msgbuf, size_t msgbuf_size,
+ unsigned int priority,
+ struct GNUNET_TIME_Relative to,
+ GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
{
+ struct Plugin *plugin = cls;
int bytes_sent = 0;
+ GNUNET_assert (plugin != NULL);
+ GNUNET_assert (session != NULL);
+
/* struct Plugin *plugin = cls; */
return bytes_sent;
}
return mlen;
}
-static ssize_t udp_plugin_send_wrapper (void *cls,
- const struct
- GNUNET_PeerIdentity *
- target,
- const char *msgbuf,
- size_t msgbuf_size,
- uint32_t priority,
- struct
- GNUNET_TIME_Relative
- timeout,
- struct Session * session,
- const void *addr,
- size_t addrlen,
- int force_address,
- GNUNET_TRANSPORT_TransmitContinuation
- cont, void *cont_cls)
-{
- int ret;
- struct Session * s = NULL;
- struct GNUNET_HELLO_Address * ha = NULL;
-
- ha = GNUNET_HELLO_address_allocate(target, "", addr,addrlen);
- GNUNET_assert (ha != NULL);
- s = udp_plugin_get_session(cls, ha);
- GNUNET_assert (s != NULL);
- GNUNET_free (ha);
- ret = udp_plugin_send (cls, s, msgbuf, msgbuf_size, priority, timeout, cont, cont_cls);
-
- return ret;
-}
-
/**
* Our external IP address/port mapping has changed.
api->address_to_string = &udp_address_to_string;
api->check_address = &udp_plugin_check_address;
api->get_session = &udp_plugin_get_session;
- api->send = &udp_plugin_send_wrapper;
- api->send_with_session = &udp_plugin_send;
+ api->send = &udp_plugin_send;
LOG (GNUNET_ERROR_TYPE_DEBUG, "Setting up sockets\n");
res = setup_sockets (plugin, &serverAddrv6, &serverAddrv4);
}
-/**
- * Function that can be used by the transport service to transmit
- * a message using the plugin.
- *
- * @param cls closure
- * @param target who should receive this message (ignored by UNIX)
- * @param msgbuf one or more GNUNET_MessageHeader(s) strung together
- * @param msgbuf_size the size of the msgbuf to send
- * @param priority how important is the message (ignored by UNIX)
- * @param timeout when should we time out (give up) if we can not transmit?
- * @param session identifier used for this session (can be NULL)
- * @param addr the addr to send the message to, needs to be a sockaddr for us
- * @param addrlen the len of addr
- * @param force_address not used, we had better have an address to send to
- * because we are stateless!!
- * @param cont continuation to call once the message has
- * been transmitted (or if the transport is ready
- * for the next transmission call; or if the
- * peer disconnected...)
- * @param cont_cls closure for cont
- *
- * @return the number of bytes written (may return 0 and the message can
- * still be transmitted later!)
- */
-static ssize_t
-unix_plugin_send_old (void *cls, const struct GNUNET_PeerIdentity *target,
- const char *msgbuf, size_t msgbuf_size, unsigned int priority,
- struct GNUNET_TIME_Relative timeout, struct Session *session,
- const void *addr, size_t addrlen, int force_address,
- GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
-{
- struct Plugin *plugin = cls;
- struct UNIXMessage *message;
- struct UNIXMessageWrapper *wrapper;
- int ssize;
- struct gsi_ctx gsi;
-
- /* Build the message to be sent */
- wrapper = GNUNET_malloc (sizeof (struct UNIXMessageWrapper) + addrlen);
- message = GNUNET_malloc (sizeof (struct UNIXMessage) + msgbuf_size);
- ssize = sizeof (struct UNIXMessage) + msgbuf_size;
-
-#if DEBUG_UNIX
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asked to send message to `%s'\n",
- (char *) addr);
-#endif
-
- message->header.size = htons (ssize);
- message->header.type = htons (0);
- memcpy (&message->sender, plugin->env->my_identity,
- sizeof (struct GNUNET_PeerIdentity));
- memcpy (&message[1], msgbuf, msgbuf_size);
-
- if (session == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking for existing session\n");
- gsi.address = (char *) addr;
- gsi.addrlen = addrlen;
- gsi.res = NULL;
- GNUNET_CONTAINER_multihashmap_get_multiple (plugin->session_map, &target->hashPubKey, &get_session_it, &gsi);
- wrapper->session = gsi.res;
- if (gsi.res == NULL)
- {
- wrapper->session = GNUNET_malloc (sizeof (struct Session) + addrlen);
- wrapper->session->addr = &wrapper->session[1];
- wrapper->session->addrlen = addrlen;
- memcpy(wrapper->session->addr, addr, wrapper->session->addrlen);
- memcpy(&wrapper->session->target, target, sizeof (struct GNUNET_PeerIdentity));
- GNUNET_CONTAINER_multihashmap_put (plugin->session_map,
- &target->hashPubKey, wrapper->session,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created new session for `%s'\n", addr);
- }
- else
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found existing session\n");
-
- }
- else
- wrapper->session = session;
-
- wrapper->msg = message;
- wrapper->msgsize = ssize;
- wrapper->priority = priority;
- wrapper->timeout = timeout;
- wrapper->cont = cont;
- wrapper->cont_cls = cont_cls;
- wrapper->retry_counter = 0;
- GNUNET_CONTAINER_DLL_insert(plugin->msg_head, plugin->msg_tail, wrapper);
-
-#if DEBUG_UNIX
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent %d bytes to `%s'\n", ssize,
- (char *) addr);
-#endif
- return ssize;
-}
-
-
/**
* Demultiplexer for UNIX messages
*
api->cls = plugin;
api->get_session = &unix_plugin_get_session;
- api->send_with_session = &unix_plugin_send;
- api->send = &unix_plugin_send_old;
+ api->send = &unix_plugin_send;
api->disconnect = &unix_disconnect;
api->address_pretty_printer = &unix_plugin_address_pretty_printer;
api->address_to_string = &unix_address_to_string;
}
-/**
- * Function that can be used by the transport service to transmit
- * a message using the plugin.
- *
- * @param cls closure
- * @param target who should receive this message
- * @param priority how important is the message
- * @param msgbuf the message to transmit
- * @param msgbuf_size number of bytes in 'msgbuf'
- * @param timeout when should we time out
- * @param session which session must be used (or NULL for "any")
- * @param addr the address to use (can be NULL if the plugin
- * is "on its own" (i.e. re-use existing TCP connection))
- * @param addrlen length of the address in bytes
- * @param force_address GNUNET_YES if the plugin MUST use the given address,
- * otherwise the plugin may use other addresses or
- * existing connections (if available)
- * @param cont continuation to call once the message has
- * been transmitted (or if the transport is ready
- * for the next transmission call; or if the
- * peer disconnected...)
- * @param cont_cls closure for cont
- * @return number of bytes used (on the physical network, with overheads);
- * -1 on hard errors (i.e. address invalid); 0 is a legal value
- * and does NOT mean that the message was not transmitted (DV)
- */
-static ssize_t
-wlan_plugin_send_old (void *cls, const struct GNUNET_PeerIdentity *target,
- const char *msgbuf, size_t msgbuf_size, unsigned int priority,
- struct GNUNET_TIME_Relative timeout, struct Session *session,
- const void *addr, size_t addrlen, int force_address,
- GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
-{
- struct Plugin *plugin = cls;
- struct PendingMessage *newmsg;
- struct WlanHeader *wlanheader;
-
- GNUNET_assert (plugin != NULL);
- //check if msglen > 0
- GNUNET_assert (msgbuf_size > 0);
-
- //get session if needed
- if (session == NULL)
- {
- if (wlan_plugin_address_suggested (plugin, addr, addrlen) == GNUNET_OK)
- {
- session = get_session (plugin, addr, target);
- }
- else
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
- _("Wlan Address len %d is wrong\n"), addrlen);
- return -1;
- }
- }
-
- GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan messages queued"), 1,
- GNUNET_NO);
-
- //queue message:
-
- //queue message in session
- //test if there is no other message in the "queue"
- //FIXME: to many send requests
- if (session->pending_message_head != NULL)
- {
- newmsg = session->pending_message_head;
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "wlan_plugin_send: a pending message is already in the queue for this client\n remaining time to send this message is %u, queued fragment messages for this mac connection %u\n",
- GNUNET_TIME_absolute_get_remaining (newmsg->
- timeout).rel_value,
- session->mac->fragment_messages_out_count);
- }
-
- newmsg = GNUNET_malloc (sizeof (struct PendingMessage));
- newmsg->msg = GNUNET_malloc (msgbuf_size + sizeof (struct WlanHeader));
- wlanheader = newmsg->msg;
- //copy msg to buffer, not fragmented / segmented yet, but with message header
- wlanheader->header.size = htons (msgbuf_size + sizeof (struct WlanHeader));
- wlanheader->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA);
- memcpy (&(wlanheader->target), target, sizeof (struct GNUNET_PeerIdentity));
- memcpy (&(wlanheader->source), plugin->env->my_identity,
- sizeof (struct GNUNET_PeerIdentity));
- wlanheader->crc = 0;
- memcpy (&wlanheader[1], msgbuf, msgbuf_size);
- wlanheader->crc =
- htonl (GNUNET_CRYPTO_crc32_n
- ((char *) wlanheader, msgbuf_size + sizeof (struct WlanHeader)));
-
- newmsg->transmit_cont = cont;
- newmsg->transmit_cont_cls = cont_cls;
- newmsg->timeout = GNUNET_TIME_relative_to_absolute (timeout);
-
- newmsg->timeout.abs_value = newmsg->timeout.abs_value - 500;
-
- newmsg->message_size = msgbuf_size + sizeof (struct WlanHeader);
-
- GNUNET_CONTAINER_DLL_insert_tail (session->pending_message_head,
- session->pending_message_tail, newmsg);
-
-#if DEBUG_wlan
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "New message for %p with size (incl wlan header) %u added\n",
- session, newmsg->message_size);
-#endif
-#if DEBUG_wlan_msg_dump > 1
- hexdump (msgbuf, GNUNET_MIN (msgbuf_size, 256));
-#endif
- //queue session
- queue_session (plugin, session);
-
- check_fragment_queue (plugin);
- //FIXME not the correct size
- return msgbuf_size;
-
-}
-
/**
* function to free a mac endpoint
* @param plugin pointer to the plugin struct
api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
api->cls = plugin;
- api->send = &wlan_plugin_send_old;
- api->send_with_session = &wlan_plugin_send;
+ api->send = &wlan_plugin_send;
api->get_session = &wlan_plugin_get_session;
api->disconnect = &wlan_plugin_disconnect;
api->address_pretty_printer = &wlan_plugin_address_pretty_printer;