Esempio n. 1
0
/**
 * Create SUSPEND event for the given unindex operation
 * and then clean up our state (without stop signal).
 *
 * @param cls the `struct GNUNET_FS_UnindexContext` to signal for
 */
void
GNUNET_FS_unindex_signal_suspend_ (void *cls)
{
  struct GNUNET_FS_UnindexContext *uc = cls;
  struct GNUNET_FS_ProgressInfo pi;

  /* FIXME: lots of duplication with unindex_stop here! */
  if (uc->dscan != NULL)
  {
    GNUNET_FS_directory_scan_abort (uc->dscan);
    uc->dscan = NULL;
  }
  if (NULL != uc->dqe)
  {
    GNUNET_DATASTORE_cancel (uc->dqe);
    uc->dqe = NULL;
  }
  if (uc->fhc != NULL)
  {
    GNUNET_CRYPTO_hash_file_cancel (uc->fhc);
    uc->fhc = NULL;
  }
  if (NULL != uc->ksk_uri)
  {
    GNUNET_FS_uri_destroy (uc->ksk_uri);
    uc->ksk_uri = NULL;
  }
  if (uc->client != NULL)
  {
    GNUNET_CLIENT_disconnect (uc->client);
    uc->client = NULL;
  }
  if (NULL != uc->dsh)
  {
    GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO);
    uc->dsh = NULL;
  }
  if (NULL != uc->tc)
  {
    GNUNET_FS_tree_encoder_finish (uc->tc, NULL);
    uc->tc = NULL;
  }
  if (uc->fh != NULL)
  {
    GNUNET_DISK_file_close (uc->fh);
    uc->fh = NULL;
  }
  GNUNET_FS_end_top (uc->h, uc->top);
  pi.status = GNUNET_FS_STATUS_UNINDEX_SUSPEND;
  GNUNET_FS_unindex_make_status_ (&pi, uc,
                                  (uc->state ==
                                   UNINDEX_STATE_COMPLETE) ? uc->file_size : 0);
  GNUNET_break (NULL == uc->client_info);
  GNUNET_free (uc->filename);
  GNUNET_free_non_null (uc->serialization);
  GNUNET_free_non_null (uc->emsg);
  GNUNET_free (uc);
}
/**
 * Receive a peerinfo information message, process it and
 * go for more.
 *
 * @param cls closure
 * @param msg message received, NULL on timeout or fatal error
 */
static void
process_notification (void *cls, const struct GNUNET_MessageHeader *msg)
{
  struct GNUNET_PEERINFO_NotifyContext *nc = cls;
  const struct InfoMessage *im;
  const struct GNUNET_HELLO_Message *hello;
  uint16_t ms;

  if (msg == NULL)
  {
    GNUNET_CLIENT_disconnect (nc->client);
    reconnect (nc, NULL);
    return;
  }
  ms = ntohs (msg->size);
  if ((ms < sizeof (struct InfoMessage)) ||
      (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_PEERINFO_INFO))
  {
    GNUNET_break (0);
    GNUNET_CLIENT_disconnect (nc->client);
    nc->client = GNUNET_CLIENT_connect ("peerinfo", nc->cfg);
    request_notifications (nc);
    return;
  }
  im = (const struct InfoMessage *) msg;
  hello = NULL;
  if (ms > sizeof (struct InfoMessage) + sizeof (struct GNUNET_MessageHeader))
  {
    hello = (const struct GNUNET_HELLO_Message *) &im[1];
    if (ms != sizeof (struct InfoMessage) + GNUNET_HELLO_size (hello))
    {
      GNUNET_break (0);
      GNUNET_CLIENT_disconnect (nc->client);
      nc->client = GNUNET_CLIENT_connect ("peerinfo", nc->cfg);
      request_notifications (nc);
      return;
    }
  }

  LOG (GNUNET_ERROR_TYPE_DEBUG,
       "Received information about peer `%s' from peerinfo database\n",
       GNUNET_i2s (&im->peer));
  nc->callback (nc->callback_cls, &im->peer, hello, NULL);
  receive_notifications (nc);
}
static void
finish_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
    GNUNET_assert (ok == 5);
    ok = 0;
    GNUNET_SERVER_destroy (server);
    GNUNET_CLIENT_disconnect (cc);
    GNUNET_CONFIGURATION_destroy (cfg);
}
Esempio n. 4
0
/**
 * Disconnect from service and then reconnect.
 *
 * @param h our handle
 */
static void
force_reconnect (struct GNUNET_NAMESTORE_Handle *h)
{
  h->reconnect = GNUNET_NO;
  GNUNET_CLIENT_disconnect (h->client);
  h->client = NULL;
  h->reconnect_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
                                    &reconnect_task,
                                    h);
}
Esempio n. 5
0
/**
 * We got a response (!?) or disconnect after asking regex
 * to do the announcement.  Retry.
 *
 * @param cls the 'struct GNUNET_REGEX_Announcement' to retry
 * @param msg NULL on disconnect
 */
static void
handle_a_reconnect (void *cls,
		    const struct GNUNET_MessageHeader *msg)
{
  struct GNUNET_REGEX_Announcement *a = cls;

  GNUNET_CLIENT_disconnect (a->client);
  a->client = GNUNET_CLIENT_connect ("regex", a->cfg);
  retry_announcement (a);
}
/**
 * Shutting down took too long, cancel receive and return error.
 *
 * @param cls closure
 * @param tc context information (why was this task triggered now)
 */
void
service_shutdown_cancel (void *cls,
			 const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  struct ShutdownContext *shutdown_ctx = cls;

  GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "service_shutdown_cancel called!\n");
  shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_SYSERR);
  GNUNET_CLIENT_disconnect (shutdown_ctx->sock);
  GNUNET_free (shutdown_ctx);
}
/**
 * Cut the existing connection and reconnect.
 *
 * @param val_ctx our context
 */
static void
reconnect_val_ctx (struct GNUNET_TRANSPORT_ValidationMonitoringContext *val_ctx)
{
  GNUNET_assert (GNUNET_NO == val_ctx->one_shot);
  GNUNET_CLIENT_disconnect (val_ctx->client);
  val_ctx->client = NULL;
  val_ctx->backoff = GNUNET_TIME_STD_BACKOFF (val_ctx->backoff);
  val_ctx->reconnect_task = GNUNET_SCHEDULER_add_delayed (val_ctx->backoff,
                                                          &do_val_connect,
                                                          val_ctx);
}
/**
 * Cut the existing connection and reconnect.
 *
 * @param pal_ctx our context
 */
static void
reconnect_peer_ctx (struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx)
{
  GNUNET_assert (GNUNET_NO == pal_ctx->one_shot);
  GNUNET_CLIENT_disconnect (pal_ctx->client);
  pal_ctx->client = NULL;
  pal_ctx->backoff = GNUNET_TIME_STD_BACKOFF (pal_ctx->backoff);
  pal_ctx->reconnect_task = GNUNET_SCHEDULER_add_delayed (pal_ctx->backoff,
							  &do_peer_connect,
							  pal_ctx);
}
/**
 * Handler receiving response to service shutdown requests.
 * First call with NULL: service misbehaving, or something.
 * First call with GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN:
 *   - service will shutdown
 * Second call with NULL:
 *   - service has now really shut down.
 *
 * @param cls closure
 * @param msg NULL, indicating socket closure.
 */
static void
service_shutdown_handler (void *cls, const struct GNUNET_MessageHeader *msg)
{
  struct ShutdownContext *shutdown_ctx = cls;

  if (msg == NULL) 
  {
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service shutdown complete.\n");
    if (shutdown_ctx->cont != NULL)
      shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_NO);
    
    GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task);
    GNUNET_CLIENT_disconnect (shutdown_ctx->sock);
    GNUNET_free (shutdown_ctx);
    return;
  }
  GNUNET_assert (ntohs (msg->size) ==
		 sizeof (struct GNUNET_MessageHeader));
  switch (ntohs (msg->type))
  {
  case GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN:
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
		"Received confirmation for service shutdown.\n");
    shutdown_ctx->confirmed = GNUNET_YES;
    GNUNET_CLIENT_receive (shutdown_ctx->sock,
			   &service_shutdown_handler, shutdown_ctx,
			   GNUNET_TIME_UNIT_FOREVER_REL);
    break;
  default:		/* Fall through */
    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
		"Service shutdown refused!\n");
    if (shutdown_ctx->cont != NULL)
      shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_YES);
    
    GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task);
    GNUNET_CLIENT_disconnect (shutdown_ctx->sock);
    GNUNET_free (shutdown_ctx);
    break;
  }
}
Esempio n. 10
0
/**
 * Process pending requests to the resolver.
 */
static void
process_requests ()
{
    struct GNUNET_RESOLVER_GetMessage *msg;
    char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1] GNUNET_ALIGN;
    struct GNUNET_RESOLVER_RequestHandle *rh;

    if (NULL == client)
    {
        reconnect ();
        return;
    }
    rh = req_head;
    if (NULL == rh)
    {
        /* nothing to do, release socket really soon if there is nothing
         * else happening... */
        s_task =
            GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
                                          &shutdown_task,
                                          NULL);
        return;
    }
    if (GNUNET_NO != rh->was_transmitted)
        return;                     /* waiting for reply */
    msg = (struct GNUNET_RESOLVER_GetMessage *) buf;
    msg->header.size =
        htons (sizeof (struct GNUNET_RESOLVER_GetMessage) + rh->data_len);
    msg->header.type = htons (GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST);
    msg->direction = htonl (rh->direction);
    msg->af = htonl (rh->af);
    memcpy (&msg[1],
            &rh[1],
            rh->data_len);
    LOG (GNUNET_ERROR_TYPE_DEBUG,
         "Transmitting DNS resolution request to DNS service\n");
    if (GNUNET_OK !=
            GNUNET_CLIENT_transmit_and_get_response (client,
                    &msg->header,
                    GNUNET_TIME_absolute_get_remaining (rh->timeout),
                    GNUNET_YES,
                    &handle_response,
                    rh))
    {
        GNUNET_CLIENT_disconnect (client);
        client = NULL;
        GNUNET_break (0);
        reconnect ();
        return;
    }
    rh->was_transmitted = GNUNET_YES;
}
Esempio n. 11
0
/**
 * Shutdown connection with the GNS service.
 *
 * @param handle handle of the GNS connection to stop
 */
void
GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle)
{
  GNUNET_CLIENT_disconnect (handle->client);
  if (GNUNET_SCHEDULER_NO_TASK != handle->reconnect_task)
  {
    GNUNET_SCHEDULER_cancel (handle->reconnect_task);
    handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
  }
  GNUNET_assert (NULL == handle->lookup_head);
  GNUNET_assert (NULL == handle->shorten_head);
  GNUNET_assert (NULL == handle->get_auth_head);
  GNUNET_free (handle);
}
/**
 * Stop notifying about changes.
 *
 * @param nc context to stop notifying
 */
void
GNUNET_PEERINFO_notify_cancel (struct GNUNET_PEERINFO_NotifyContext *nc)
{
  if (NULL != nc->init)
  {
    GNUNET_CLIENT_notify_transmit_ready_cancel (nc->init);
    nc->init = NULL;
  }
  if (NULL != nc->client)
    GNUNET_CLIENT_disconnect (nc->client);
  if (GNUNET_SCHEDULER_NO_TASK != nc->task)
    GNUNET_SCHEDULER_cancel (nc->task);
  GNUNET_free (nc);
}
Esempio n. 13
0
/**
 * Kill the connection to the service. This can be delayed in case of pending
 * STORE requests and the user explicitly asked to sync first. Otherwise it is
 * performed instantly.
 *
 * @param h Handle to the service.
 */
static void
do_disconnect (struct GNUNET_PEERSTORE_Handle *h)
{
  if (NULL != h->mq)
  {
    GNUNET_MQ_destroy (h->mq);
    h->mq = NULL;
  }
  if (NULL != h->client)
  {
    GNUNET_CLIENT_disconnect (h->client);
    h->client = NULL;
  }
  GNUNET_free (h);
}
/**
 * Return information about all current pending validation operations
 *
 * @param vic handle for the request to cancel
 */
void
GNUNET_TRANSPORT_monitor_validation_entries_cancel (struct GNUNET_TRANSPORT_ValidationMonitoringContext *vic)
{
  if (NULL != vic->client)
  {
    GNUNET_CLIENT_disconnect (vic->client);
    vic->client = NULL;
  }
  if (NULL != vic->reconnect_task)
  {
    GNUNET_SCHEDULER_cancel (vic->reconnect_task);
    vic->reconnect_task = NULL;
  }
  GNUNET_free (vic);
}
/**
 * Cut the existing connection and reconnect.
 *
 * @param val_ctx our context
 */
static void
reconnect_val_ctx (struct GNUNET_TRANSPORT_ValidationMonitoringContext *val_ctx)
{
  GNUNET_assert (GNUNET_NO == val_ctx->one_shot);
  GNUNET_CLIENT_disconnect (val_ctx->client);
  val_ctx->client = NULL;
  /* notify clients about (re)connect */
  val_ctx->cb (val_ctx->cb_cls, NULL,
               GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TIME_UNIT_ZERO_ABS,
               GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TRANSPORT_VS_TIMEOUT);
  val_ctx->backoff = GNUNET_TIME_STD_BACKOFF (val_ctx->backoff);
  val_ctx->reconnect_task = GNUNET_SCHEDULER_add_delayed (val_ctx->backoff,
                                                          &do_val_connect,
                                                          val_ctx);
}
Esempio n. 16
0
/**
 * Disconnect from the service and then try reconnecting to the datastore service
 * after some delay.
 *
 * @param h handle to datastore to disconnect and reconnect
 */
static void
do_disconnect (struct GNUNET_DATASTORE_Handle *h)
{
  if (h->client == NULL)
  {
    LOG (GNUNET_ERROR_TYPE_DEBUG,
         "client NULL in disconnect, will not try to reconnect\n");
    return;
  }
  GNUNET_CLIENT_disconnect (h->client);
  h->skip_next_messages = 0;
  h->client = NULL;
  h->reconnect_task =
      GNUNET_SCHEDULER_add_delayed (h->retry_time, &try_reconnect, h);
}
/**
 * Cancel request to monitor peers
 *
 * @param pic handle for the request to cancel
 */
void
GNUNET_TRANSPORT_monitor_peers_cancel (struct GNUNET_TRANSPORT_PeerMonitoringContext *pic)
{
  if (NULL != pic->client)
  {
    GNUNET_CLIENT_disconnect (pic->client);
    pic->client = NULL;
  }
  if (GNUNET_SCHEDULER_NO_TASK != pic->reconnect_task)
  {
    GNUNET_SCHEDULER_cancel (pic->reconnect_task);
    pic->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
  }
  GNUNET_free (pic);
}
Esempio n. 18
0
/**
 * Disconnect from the logger service.
 *
 * @param h the logger handle
 */
void
GNUNET_TESTBED_LOGGER_disconnect (struct GNUNET_TESTBED_LOGGER_Handle *h)
{
  struct MessageQueue *mq;

  if (GNUNET_SCHEDULER_NO_TASK != h->flush_completion_task)
    GNUNET_SCHEDULER_cancel (h->flush_completion_task);
  while (NULL != (mq = h->mq_head))
  {
    GNUNET_CONTAINER_DLL_remove (h->mq_head, h->mq_tail, mq);
    GNUNET_free (mq->msg);
    GNUNET_free (mq);
  }
  GNUNET_CLIENT_disconnect (h->client);
  GNUNET_free (h);
}
Esempio n. 19
0
/**
 * Handle request message for a listen operation
 *
 * @param cls the listen handle
 * @param mh the message
 */
static void
handle_request (void *cls,
                const struct GNUNET_MessageHeader *mh)
{
  struct GNUNET_SET_ListenHandle *lh = cls;
  const struct GNUNET_SET_RequestMessage *msg;
  struct GNUNET_SET_Request req;
  const struct GNUNET_MessageHeader *context_msg;
  uint16_t msize;
  struct GNUNET_MQ_Envelope *mqm;
  struct GNUNET_SET_RejectMessage *rmsg;

  LOG (GNUNET_ERROR_TYPE_DEBUG,
       "Processing incoming operation request\n");
  msize = ntohs (mh->size);
  if (msize < sizeof (struct GNUNET_SET_RequestMessage))
  {
    GNUNET_break (0);
    GNUNET_CLIENT_disconnect (lh->client);
    lh->client = NULL;
    GNUNET_MQ_destroy (lh->mq);
    lh->mq = NULL;
    lh->reconnect_task = GNUNET_SCHEDULER_add_delayed (lh->reconnect_backoff,
                                                       &listen_connect, lh);
    lh->reconnect_backoff = GNUNET_TIME_STD_BACKOFF (lh->reconnect_backoff);
    return;
  }
  /* we got another valid request => reset the backoff */
  lh->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS;
  msg = (const struct GNUNET_SET_RequestMessage *) mh;
  req.accept_id = ntohl (msg->accept_id);
  req.accepted = GNUNET_NO;
  context_msg = GNUNET_MQ_extract_nested_mh (msg);
  /* calling #GNUNET_SET_accept() in the listen cb will set req->accepted */
  lh->listen_cb (lh->listen_cls,
                 &msg->peer_id,
                 context_msg,
                 &req);
  if (GNUNET_YES == req.accepted)
    return; /* the accept-case is handled in #GNUNET_SET_accept() */
  LOG (GNUNET_ERROR_TYPE_DEBUG,
       "Rejecting request\n");
  mqm = GNUNET_MQ_msg (rmsg,
                       GNUNET_MESSAGE_TYPE_SET_REJECT);
  rmsg->accept_reject_id = msg->accept_id;
  GNUNET_MQ_send (lh->mq, mqm);
}
Esempio n. 20
0
/**
 * Our connection with the set service encountered an error,
 * re-initialize with exponential back-off.
 *
 * @param cls the `struct GNUNET_SET_ListenHandle *`
 * @param error reason for the disconnect
 */
static void
handle_client_listener_error (void *cls,
                              enum GNUNET_MQ_Error error)
{
  struct GNUNET_SET_ListenHandle *lh = cls;

  LOG (GNUNET_ERROR_TYPE_DEBUG,
       "Listener broke down (%d), re-connecting\n",
       (int) error);
  GNUNET_CLIENT_disconnect (lh->client);
  lh->client = NULL;
  GNUNET_MQ_destroy (lh->mq);
  lh->mq = NULL;
  lh->reconnect_task = GNUNET_SCHEDULER_add_delayed (lh->reconnect_backoff,
                                                     &listen_connect, lh);
  lh->reconnect_backoff = GNUNET_TIME_STD_BACKOFF (lh->reconnect_backoff);
}
Esempio n. 21
0
/**
 * Disconnect from service and then reconnect.
 *
 * @param handle our handle
 */
static void
force_reconnect (struct GNUNET_GNS_Handle *handle)
{
  struct GNUNET_GNS_ShortenRequest *st;
  struct GNUNET_GNS_LookupRequest *lh;
  struct GNUNET_GNS_GetAuthRequest *ga;
  struct PendingMessage *p;

  GNUNET_CLIENT_disconnect (handle->client);
  handle->client = NULL;
  handle->in_receive = GNUNET_NO;
  for (st = handle->shorten_head; NULL != st; st = st->next)
  {
    p = (struct PendingMessage *) &st[1];
    if (GNUNET_NO == p->transmitted)
      continue;
    p->transmitted = GNUNET_NO;
    GNUNET_CONTAINER_DLL_insert (handle->pending_head,
				 handle->pending_tail,
				 p);  
  }
  for (lh = handle->lookup_head; NULL != lh; lh = lh->next)
  {
    p = (struct PendingMessage *) &lh[1];
    if (GNUNET_NO == p->transmitted)
      continue;
    p->transmitted = GNUNET_NO;
    GNUNET_CONTAINER_DLL_insert (handle->pending_head,
				 handle->pending_tail,
				 p);  
  }
  for (ga = handle->get_auth_head; NULL != ga; ga = ga->next)
  {
    p = (struct PendingMessage *) &ga[1];
    if (GNUNET_NO == p->transmitted)
      continue;
    p->transmitted = GNUNET_NO;
    GNUNET_CONTAINER_DLL_insert (handle->pending_head,
				 handle->pending_tail,
				 p);  
  }
  handle->reconnect_backoff = GNUNET_TIME_STD_BACKOFF (handle->reconnect_backoff);
  handle->reconnect_task = GNUNET_SCHEDULER_add_delayed (handle->reconnect_backoff,
                                                    &reconnect_task,
                                                    handle);
}
Esempio n. 22
0
static void
recv_bounce (void *cls, const struct GNUNET_MessageHeader *got)
{
  int *ok = cls;
  struct GNUNET_MessageHeader msg;

  GNUNET_assert (got != NULL);  /* timeout */
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving bounce, checking content\n");
  msg.type = htons (MY_TYPE);
  msg.size = htons (sizeof (struct GNUNET_MessageHeader));
  GNUNET_assert (0 == memcmp (got, &msg, sizeof (struct GNUNET_MessageHeader)));
  GNUNET_CLIENT_disconnect (client);
  client = NULL;
  GNUNET_SERVER_destroy (server);
  server = NULL;
  *ok = 0;
}
Esempio n. 23
0
/**
 * Disconnect from the ARM service (if connected) and destroy the context.
 *
 * @param h the handle that was being used
 */
void
GNUNET_ARM_disconnect_and_free (struct GNUNET_ARM_Handle *h)
{
  struct ARMControlMessage *cm;

  LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from ARM service\n");
  if (NULL != h->cth)
  {
    GNUNET_CLIENT_notify_transmit_ready_cancel (h->cth);
    h->cth = NULL;
  }
  while ((NULL != (cm = h->control_pending_head))
         || (NULL != (cm = h->control_sent_head)) )
  {
    if (NULL != h->control_pending_head)
      GNUNET_CONTAINER_DLL_remove (h->control_pending_head,
                                   h->control_pending_tail, cm);
    else
      GNUNET_CONTAINER_DLL_remove (h->control_sent_head,
                                   h->control_sent_tail, cm);
    GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != cm->timeout_task_id);
    GNUNET_SCHEDULER_cancel (cm->timeout_task_id);
    if (NULL != cm->result_cont)
      cm->result_cont (cm->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED,
                       NULL, 0);
    /* FIXME: What about list callback? */
    GNUNET_free_non_null (cm->msg);
    GNUNET_free (cm);
  }
  if (NULL != h->client)
  {
    GNUNET_CLIENT_disconnect (h->client);
    h->client = NULL;
  }
  if (GNUNET_SCHEDULER_NO_TASK != h->reconnect_task)
  {
    GNUNET_SCHEDULER_cancel (h->reconnect_task);
    h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
  }
  if (GNUNET_NO == h->service_test_is_active)
  {
    GNUNET_CONFIGURATION_destroy (h->cfg);
    GNUNET_free (h);
  }
}
Esempio n. 24
0
static void
do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  if (NULL != client)
  {
    GNUNET_CLIENT_disconnect (client);
    client = NULL;
  }
  if (NULL != sctx)
  {
    GNUNET_SERVICE_stop (sctx);
    sctx = NULL;
  }
  else
  {
    GNUNET_SCHEDULER_shutdown ();
  }
}
Esempio n. 25
0
/**
 * Shutdown connection with the DHT service.
 *
 * @param handle handle of the DHT connection to stop
 */
void
GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle)
{
  struct PendingMessage *pm;
  struct GNUNET_DHT_PutHandle *ph;

  GNUNET_assert (NULL != handle);
  GNUNET_assert (0 ==
                 GNUNET_CONTAINER_multihashmap_size (handle->active_requests));
  if (NULL != handle->th)
  {
    GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th);
    handle->th = NULL;
  }
  while (NULL != (pm = handle->pending_head))
  {
    GNUNET_assert (GNUNET_YES == pm->in_pending_queue);
    GNUNET_CONTAINER_DLL_remove (handle->pending_head, handle->pending_tail,
                                 pm);
    pm->in_pending_queue = GNUNET_NO;
    GNUNET_assert (GNUNET_YES == pm->free_on_send);
    if (NULL != pm->cont)
      pm->cont (pm->cont_cls, NULL);
    GNUNET_free (pm);
  }
  while (NULL != (ph = handle->put_head))
  {
    GNUNET_break (NULL == ph->pending);
    if (NULL != ph->cont)
      ph->cont (ph->cont_cls, GNUNET_SYSERR);
    GNUNET_DHT_put_cancel (ph);
  }

  if (NULL != handle->client)
  {
    GNUNET_CLIENT_disconnect (handle->client);
    handle->client = NULL;
  }
  if (NULL != handle->reconnect_task)
    GNUNET_SCHEDULER_cancel (handle->reconnect_task);
  GNUNET_CONTAINER_multihashmap_destroy (handle->active_requests);
  GNUNET_free (handle);
}
Esempio n. 26
0
/**
 * Function called with the response from the
 * FS service to our unindexing request.
 *
 * @param cls closure, unindex context
 * @param msg NULL on timeout, otherwise the response
 */
static void
process_fs_response (void *cls, const struct GNUNET_MessageHeader *msg)
{
  struct GNUNET_FS_UnindexContext *uc = cls;
  struct GNUNET_FS_ProgressInfo pi;

  if (uc->client != NULL)
  {
    GNUNET_CLIENT_disconnect (uc->client);
    uc->client = NULL;
  }
  if (uc->state != UNINDEX_STATE_FS_NOTIFY)
  {
    uc->state = UNINDEX_STATE_ERROR;
    uc->emsg =
        GNUNET_strdup (_("Unexpected time for a response from `fs' service."));
    GNUNET_FS_unindex_sync_ (uc);
    signal_unindex_error (uc);
    return;
  }
  if (NULL == msg)
  {
    uc->state = UNINDEX_STATE_ERROR;
    uc->emsg = GNUNET_strdup (_("Timeout waiting for `fs' service."));
    GNUNET_FS_unindex_sync_ (uc);
    signal_unindex_error (uc);
    return;
  }
  if (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK)
  {
    uc->state = UNINDEX_STATE_ERROR;
    uc->emsg = GNUNET_strdup (_("Invalid response from `fs' service."));
    GNUNET_FS_unindex_sync_ (uc);
    signal_unindex_error (uc);
    return;
  }
  uc->state = UNINDEX_STATE_COMPLETE;
  pi.status = GNUNET_FS_STATUS_UNINDEX_COMPLETED;
  pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO;
  GNUNET_FS_unindex_sync_ (uc);
  GNUNET_FS_unindex_make_status_ (&pi, uc, uc->file_size);
}
Esempio n. 27
0
/**
 * Abort testing for service.
 *
 * @param th test handle
 */
void
GNUNET_CLIENT_service_test_cancel (struct GNUNET_CLIENT_TestHandle *th)
{
  if (NULL != th->th)
  {
    GNUNET_CLIENT_notify_transmit_ready_cancel (th->th);
    th->th = NULL;
  }
  if (NULL != th->client)
  {
    GNUNET_CLIENT_disconnect (th->client);
    th->client = NULL;
  }
  if (NULL != th->task)
  {
    GNUNET_SCHEDULER_cancel (th->task);
    th->task = NULL;
  }
  GNUNET_free (th);
}
Esempio n. 28
0
/**
 * Disconnect from the core service.  This function can only
 * be called *after* all pending #GNUNET_CORE_notify_transmit_ready()
 * requests have been explicitly canceled.
 *
 * @param handle connection to core to disconnect
 */
void
GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle)
{
  struct ControlMessage *cm;

  GNUNET_assert (NULL != handle);

  LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from CORE service\n");
  if (NULL != handle->cth)
  {
    GNUNET_CLIENT_notify_transmit_ready_cancel (handle->cth);
    handle->cth = NULL;
  }
  while (NULL != (cm = handle->control_pending_head))
  {
    GNUNET_CONTAINER_DLL_remove (handle->control_pending_head,
                                 handle->control_pending_tail, cm);
    if (NULL != cm->th)
      cm->th->cm = NULL;
    if (NULL != cm->cont)
      cm->cont (cm->cont_cls, GNUNET_SYSERR);
    GNUNET_free (cm);
  }
  if (NULL != handle->client)
  {
    GNUNET_CLIENT_disconnect (handle->client);
    handle->client = NULL;
  }
  GNUNET_CONTAINER_multipeermap_iterate (handle->peers,
                                         &disconnect_and_free_peer_entry,
                                         handle);
  if (handle->reconnect_task != GNUNET_SCHEDULER_NO_TASK)
  {
    GNUNET_SCHEDULER_cancel (handle->reconnect_task);
    handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
  }
  GNUNET_CONTAINER_multipeermap_destroy (handle->peers);
  handle->peers = NULL;
  GNUNET_break (handle->ready_peer_head == NULL);
  GNUNET_free (handle);
}
Esempio n. 29
0
static void
recv_cb (void *cls, struct GNUNET_SERVER_Client *argclient,
         const struct GNUNET_MessageHeader *message)
{
  void *addr;
  size_t addrlen;
  struct sockaddr_in sa;
  struct sockaddr_in *have;

  GNUNET_assert (GNUNET_OK ==
                 GNUNET_SERVER_client_get_address (argclient, &addr, &addrlen));

  GNUNET_assert (addrlen == sizeof (struct sockaddr_in));
  have = addr;
  memset (&sa, 0, sizeof (sa));
#if HAVE_SOCKADDR_IN_SIN_LEN
  sa.sin_len = sizeof (sa);
#endif
  sa.sin_family = AF_INET;
  sa.sin_port = have->sin_port;
  sa.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
  GNUNET_assert (0 == memcmp (&sa, addr, addrlen));
  GNUNET_free (addr);
  switch (ok)
  {
  case 2:
    ok++;
    GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
                                  (GNUNET_TIME_UNIT_MILLISECONDS, 50),
                                  &send_done, argclient);
    break;
  case 4:
    ok++;
    GNUNET_CLIENT_disconnect (client);
    GNUNET_SERVER_receive_done (argclient, GNUNET_OK);
    break;
  default:
    GNUNET_assert (0);
  }

}
Esempio n. 30
0
/**
 * Disconnect from the VPN service.
 *
 * @param vh VPN handle
 */
void
GNUNET_VPN_disconnect (struct GNUNET_VPN_Handle *vh)
{
  GNUNET_assert (NULL == vh->rr_head);
  if (NULL != vh->th)
  {
    GNUNET_CLIENT_notify_transmit_ready_cancel (vh->th);
    vh->th = NULL;
  }
  if (NULL != vh->client)
  {
    GNUNET_CLIENT_disconnect (vh->client);
    vh->client = NULL;
  }
  if (GNUNET_SCHEDULER_NO_TASK != vh->rt)
  {
    GNUNET_SCHEDULER_cancel (vh->rt);
    vh->rt = GNUNET_SCHEDULER_NO_TASK;
  }
  GNUNET_free (vh);
}