- "# bytes received via %s_client",
- plugin->protocol);
- GNUNET_STATISTICS_update (plugin->env->stats,
- stat_txt, ntohs(message->size), GNUNET_NO);
- GNUNET_free (stat_txt);
-
- s->next_receive =
- GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), delay);
-
- if (GNUNET_TIME_absolute_get ().abs_value_us < s->next_receive.abs_value_us)
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Client: peer `%s' address `%s' next read delayed for %s\n",
- GNUNET_i2s (&s->target),
- http_common_plugin_address_to_string (NULL,
- s->plugin->protocol, s->address->address,
- s->address->address_length),
- GNUNET_STRINGS_relative_time_to_string (delay,
- GNUNET_YES));
- }
- client_reschedule_session_timeout (s);
- return GNUNET_OK;
-}
-
-
-/**
- * Callback method used with libcurl when data for a PUT connection are
- * received. We do not expect data here, so we just dismiss it
- *
- * @param stream pointer where to write data
- * @param size size of an individual element
- * @param nmemb count of elements that can be written to the buffer
- * @param cls destination pointer, passed to the libcurl handle
- * @return bytes read from stream
- */
-static size_t
-client_receive_put (void *stream, size_t size, size_t nmemb, void *cls)
-{
- return size * nmemb;
-}
-
-
-/**
- * Callback method used with libcurl when data for a GET connection are
- * received. Forward to MST
- *
- * @param stream pointer where to write data
- * @param size size of an individual element
- * @param nmemb count of elements that can be written to the buffer
- * @param cls destination pointer, passed to the libcurl handle
- * @return bytes read from stream
- */
-static size_t
-client_receive (void *stream, size_t size, size_t nmemb, void *cls)
-{
- struct Session *s = cls;
- struct GNUNET_TIME_Absolute now;
- size_t len = size * nmemb;
-
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name,
- "Session %p / connection %p: Received %u bytes from peer `%s'\n",
- s, s->client_get,
- len, GNUNET_i2s (&s->target));
- now = GNUNET_TIME_absolute_get ();
- if (now.abs_value_us < s->next_receive.abs_value_us)
- {
- struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
- struct GNUNET_TIME_Relative delta =
- GNUNET_TIME_absolute_get_difference (now, s->next_receive);
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name,
- "Session %p / connection %p: No inbound bandwidth available! Next read was delayed for %s\n",
- s, s->client_get,
- GNUNET_STRINGS_relative_time_to_string (delta,
- GNUNET_YES));
- if (s->recv_wakeup_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (s->recv_wakeup_task);
- s->recv_wakeup_task = GNUNET_SCHEDULER_NO_TASK;
- }
- s->recv_wakeup_task =
- GNUNET_SCHEDULER_add_delayed (delta, &client_wake_up, s);
- return CURL_WRITEFUNC_PAUSE;
- }
- if (NULL == s->msg_tk)
- s->msg_tk = GNUNET_SERVER_mst_create (&client_receive_mst_cb, s);
- GNUNET_SERVER_mst_receive (s->msg_tk, s, stream, len, GNUNET_NO, GNUNET_NO);
- return len;
-}
-
-
-/**
- * Task performing curl operations
- *
- * @param cls plugin as closure
- * @param tc gnunet scheduler task context
- */
-static void
-client_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
-
-
-/**
- * Function setting up file descriptors and scheduling task to run
- *
- * @param plugin the plugin as closure
- * @param now schedule task in 1ms, regardless of what curl may say
- * @return #GNUNET_SYSERR for hard failure, #GNUNET_OK for ok
- */
-static int
-client_schedule (struct HTTP_Client_Plugin *plugin, int now)
-{
- fd_set rs;
- fd_set ws;
- fd_set es;
- int max;
- struct GNUNET_NETWORK_FDSet *grs;
- struct GNUNET_NETWORK_FDSet *gws;
- long to;
- CURLMcode mret;
- struct GNUNET_TIME_Relative timeout;
-
- /* Cancel previous scheduled task */
- if (plugin->client_perform_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (plugin->client_perform_task);
- plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK;
- }
- max = -1;
- FD_ZERO (&rs);
- FD_ZERO (&ws);
- FD_ZERO (&es);
- mret = curl_multi_fdset (plugin->curl_multi_handle, &rs, &ws, &es, &max);
- if (mret != CURLM_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"),
- "curl_multi_fdset", __FILE__, __LINE__,
- curl_multi_strerror (mret));
- return GNUNET_SYSERR;
- }
- mret = curl_multi_timeout (plugin->curl_multi_handle, &to);
- if (to == -1)
- timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1);
- else
- timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, to);
- if (now == GNUNET_YES)
- timeout = GNUNET_TIME_UNIT_MILLISECONDS;