+ /* RECV DIRECTION */
+ /* Check if session is connected to receive data, otherwise connect to peer */
+ if (ps->recv_connected == GNUNET_NO)
+ {
+ if (ps->recv_endpoint == NULL)
+ {
+ ps->recv_endpoint = curl_easy_init();
+#if DEBUG_CURL
+ curl_easy_setopt(ps->recv_endpoint, CURLOPT_VERBOSE, 1L);
+#endif
+ curl_easy_setopt(ps->recv_endpoint, CURLOPT_URL, ps->url);
+ curl_easy_setopt(ps->recv_endpoint, CURLOPT_HEADERFUNCTION, &curl_get_header_function);
+ curl_easy_setopt(ps->recv_endpoint, CURLOPT_WRITEHEADER, ps);
+ curl_easy_setopt(ps->recv_endpoint, CURLOPT_READFUNCTION, curl_send_cb);
+ curl_easy_setopt(ps->recv_endpoint, CURLOPT_READDATA, ps);
+ curl_easy_setopt(ps->recv_endpoint, CURLOPT_WRITEFUNCTION, curl_receive_cb);
+ curl_easy_setopt(ps->recv_endpoint, CURLOPT_WRITEDATA, ps);
+ curl_easy_setopt(ps->recv_endpoint, CURLOPT_TIMEOUT, (long) timeout.value);
+ curl_easy_setopt(ps->recv_endpoint, CURLOPT_PRIVATE, ps);
+ curl_easy_setopt(ps->recv_endpoint, CURLOPT_CONNECTTIMEOUT, HTTP_CONNECT_TIMEOUT);
+ curl_easy_setopt(ps->recv_endpoint, CURLOPT_BUFFERSIZE, GNUNET_SERVER_MAX_MESSAGE_SIZE);
+
+ mret = curl_multi_add_handle(plugin->multi_handle, ps->recv_endpoint);
+ if (mret != CURLM_OK)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("%s failed at %s:%d: `%s'\n"),
+ "curl_multi_add_handle", __FILE__, __LINE__,
+ curl_multi_strerror (mret));
+ return -1;
+ }
+ bytes_sent = send_schedule (plugin, NULL);
+#if DEBUG_CONNECTIONS
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: inbound not connected, initiating connection\n",ps);
+#endif
+ }
+ }
+
+ /* waiting for receive direction */
+ if (ps->recv_connected==GNUNET_NO)
+ return 0;
+
+ /* SEND DIRECTION */
+ /* Check if session is connected to send data, otherwise connect to peer */
+ if ((ps->send_connected == GNUNET_YES) && (ps->send_endpoint!= NULL))
+ {
+ if (ps->send_active == GNUNET_YES)
+ {
+#if DEBUG_CONNECTIONS
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: outbound active, enqueueing message\n",ps);
+#endif
+ return bytes_sent;
+ }
+ if (ps->send_active == GNUNET_NO)
+ {
+#if DEBUG_CONNECTIONS
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: outbound paused, unpausing existing connection and enqueueing message\n",ps);
+#endif
+ curl_easy_pause(ps->send_endpoint,CURLPAUSE_CONT);
+ ps->send_active=GNUNET_YES;
+ return bytes_sent;
+ }
+ }
+ /* not connected, initiate connection */
+ if ((ps->send_connected==GNUNET_NO) && (NULL == ps->send_endpoint))
+ ps->send_endpoint = curl_easy_init();
+ GNUNET_assert (ps->send_endpoint != NULL);
+ GNUNET_assert (NULL != ps->pending_msgs_tail);
+#if DEBUG_CONNECTIONS
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: outbound not connected, initiating connection\n",ps);
+#endif
+ ps->send_active = GNUNET_NO;
+ msg = ps->pending_msgs_tail;
+
+ #if DEBUG_CURL
+ curl_easy_setopt(ps->send_endpoint, CURLOPT_VERBOSE, 1L);
+ #endif
+ curl_easy_setopt(ps->send_endpoint, CURLOPT_URL, ps->url);
+ curl_easy_setopt(ps->send_endpoint, CURLOPT_PUT, 1L);
+ curl_easy_setopt(ps->send_endpoint, CURLOPT_HEADERFUNCTION, &curl_put_header_function);
+ curl_easy_setopt(ps->send_endpoint, CURLOPT_WRITEHEADER, ps);
+ curl_easy_setopt(ps->send_endpoint, CURLOPT_READFUNCTION, curl_send_cb);
+ curl_easy_setopt(ps->send_endpoint, CURLOPT_READDATA, ps);
+ curl_easy_setopt(ps->send_endpoint, CURLOPT_WRITEFUNCTION, curl_receive_cb);
+ curl_easy_setopt(ps->send_endpoint, CURLOPT_READDATA, ps);
+ curl_easy_setopt(ps->send_endpoint, CURLOPT_TIMEOUT, (long) timeout.value);
+ curl_easy_setopt(ps->send_endpoint, CURLOPT_PRIVATE, ps);
+ curl_easy_setopt(ps->send_endpoint, CURLOPT_CONNECTTIMEOUT, HTTP_CONNECT_TIMEOUT);
+ curl_easy_setopt(ps->send_endpoint, CURLOPT_BUFFERSIZE, GNUNET_SERVER_MAX_MESSAGE_SIZE);
+
+ mret = curl_multi_add_handle(plugin->multi_handle, ps->send_endpoint);
+ if (mret != CURLM_OK)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("%s failed at %s:%d: `%s'\n"),
+ "curl_multi_add_handle", __FILE__, __LINE__,
+ curl_multi_strerror (mret));
+ return -1;
+ }
+ bytes_sent = send_schedule (plugin, NULL);
+ return bytes_sent;