/**
 * Close the existing connection to PEERINFO and reconnect.
 *
 * @param h handle to the service
 */
static void
reconnect (struct GNUNET_PEERINFO_Handle *h)
{
  if (GNUNET_SCHEDULER_NO_TASK != h->r_task)
  {
    GNUNET_SCHEDULER_cancel (h->r_task);
    h->r_task = GNUNET_SCHEDULER_NO_TASK;
  }
  if (NULL != h->th)
  {
    GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
    h->th = NULL;
  }
  if (NULL != h->client)
  {
    GNUNET_CLIENT_disconnect (h->client);
    h->client = NULL;
  }
  h->in_receive = GNUNET_NO;
  h->client = GNUNET_CLIENT_connect ("peerinfo", h->cfg);
  if (NULL == h->client)
  {
    h->r_task =
        GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &reconnect_task,
                                      h);
    return;
  }
  trigger_transmit (h);
}
Beispiel #2
0
/**
 * Close down any existing connection to the ARM service and
 * try re-establishing it later.
 *
 * @param h our handle
 */
static void
reconnect_arm_later (struct GNUNET_ARM_Handle *h)
{
  if (GNUNET_NO != h->currently_down)
    return;
  if (NULL != h->cth)
  {
    GNUNET_CLIENT_notify_transmit_ready_cancel (h->cth);
    h->cth = NULL;
  }
  if (NULL != h->client)
  {
    GNUNET_CLIENT_disconnect (h->client);
    h->client = NULL;
  }
  h->currently_down = GNUNET_YES;
  GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == h->reconnect_task);
  h->reconnect_task =
      GNUNET_SCHEDULER_add_delayed (h->retry_backoff, &reconnect_arm_task, h);
  /* Don't clear pending messages on disconnection, deliver them later
  clear_pending_messages (h, GNUNET_ARM_REQUEST_DISCONNECTED);
  GNUNET_assert (NULL == h->control_pending_head);
  */
  h->retry_backoff = GNUNET_TIME_STD_BACKOFF (h->retry_backoff);
  if (NULL != h->conn_status)
    h->conn_status (h->conn_status_cls, GNUNET_NO);
}
Beispiel #3
0
/**
 * Cancel a PSYCstore operation. Note that the operation MAY still
 * be executed; this merely cancels the continuation; if the request
 * was already transmitted, the service may still choose to complete
 * the operation.
 *
 * @param op Operation to cancel.
 */
void
GNUNET_PSYCSTORE_operation_cancel (struct GNUNET_PSYCSTORE_OperationHandle *op)
{
  struct GNUNET_PSYCSTORE_Handle *h = op->h;

  if (h->transmit_head != NULL && (h->transmit_head != op || NULL == h->client))
  {
    /* request not active, can simply remove */
    GNUNET_CONTAINER_DLL_remove (h->transmit_head, h->transmit_tail, op);
    GNUNET_free (op);
    return;
  }
  if (NULL != h->th)
  {
    /* request active but not yet with service, can still abort */
    GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
    h->th = NULL;
    GNUNET_CONTAINER_DLL_remove (h->transmit_head, h->transmit_tail, op);
    GNUNET_free (op);
    transmit_next (h);
    return;
  }
  /* request active with service, simply ensure continuations are not called */
  op->res_cb = NULL;
  op->data_cb = NULL;
}
Beispiel #4
0
/**
 * Disconnect from DV service.
 *
 * @param sh service handle
 */
void
GNUNET_DV_service_disconnect (struct GNUNET_DV_ServiceHandle *sh)
{
  struct GNUNET_DV_TransmitHandle *pos;

  if (NULL == sh)
    return;
  if (NULL != sh->th)
  {
    GNUNET_CLIENT_notify_transmit_ready_cancel (sh->th);
    sh->th = NULL;
  }
  while (NULL != (pos = sh->th_head))
  {
    GNUNET_CONTAINER_DLL_remove (sh->th_head,
				 sh->th_tail,
				 pos);
    GNUNET_free (pos);
  }
  if (NULL != sh->client)
  {
    GNUNET_CLIENT_disconnect (sh->client);
    sh->client = NULL;
  }
  GNUNET_CONTAINER_multipeermap_iterate (sh->peers,
					 &cleanup_send_cb,
					 sh);
  GNUNET_CONTAINER_multipeermap_destroy (sh->peers);
  GNUNET_free (sh);
}
Beispiel #5
0
/**
 * Try reconnecting to the DHT service.
 *
 * @param handle handle to dht to (possibly) disconnect and reconnect
 */
static void
do_disconnect (struct GNUNET_DHT_Handle *handle)
{
  struct GNUNET_DHT_PutHandle *ph;
  struct GNUNET_DHT_PutHandle *next;

  if (NULL == handle->client)
    return;
  GNUNET_assert (NULL == handle->reconnect_task);
  if (NULL != handle->th)
    GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th);
  handle->th = NULL;
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Disconnecting from DHT service, will try to reconnect in %s\n",
              GNUNET_STRINGS_relative_time_to_string (handle->retry_time,
						      GNUNET_YES));
  GNUNET_CLIENT_disconnect (handle->client);
  handle->client = NULL;

  /* signal disconnect to all PUT requests that were transmitted but waiting
     for the put confirmation */
  next = handle->put_head;
  while (NULL != (ph = next))
  {
    next = ph->next;
    if (NULL == ph->pending)
    {
      if (NULL != ph->cont)
	ph->cont (ph->cont_cls, GNUNET_SYSERR);
      GNUNET_DHT_put_cancel (ph);
    }
  }
  handle->reconnect_task =
      GNUNET_SCHEDULER_add_delayed (handle->retry_time, &try_reconnect, handle);
}
Beispiel #6
0
/**
 * Disconnect from the ARM service (if connected) and destroy the context.
 *
 * @param h the handle that was being used
 */
void
GNUNET_ARM_monitor_disconnect_and_free (struct GNUNET_ARM_MonitorHandle *h)
{
  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;
  }
  if (NULL != h->init_timeout_task_id)
  {
    GNUNET_SCHEDULER_cancel (h->init_timeout_task_id);
    h->init_timeout_task_id = NULL;
  }
  if (NULL != h->monitor)
  {
    GNUNET_CLIENT_disconnect (h->monitor);
    h->monitor = NULL;
  }
  if (NULL != h->reconnect_task)
  {
    GNUNET_SCHEDULER_cancel (h->reconnect_task);
    h->reconnect_task = NULL;
  }
  GNUNET_CONFIGURATION_destroy (h->cfg);
  GNUNET_free (h);
}
Beispiel #7
0
/**
 * Close down any existing connection to the ARM service and
 * try re-establishing it later.
 *
 * @param h our handle
 */
static void
reconnect_arm_monitor_later (struct GNUNET_ARM_MonitorHandle *h)
{
  if (NULL != h->cth)
  {
    GNUNET_CLIENT_notify_transmit_ready_cancel (h->cth);
    h->cth = NULL;
  }

  if (NULL != h->monitor)
  {
    GNUNET_CLIENT_disconnect (h->monitor);
    h->monitor = NULL;
  }

  if (NULL != h->init_timeout_task_id)
  {
    GNUNET_SCHEDULER_cancel (h->init_timeout_task_id);
    h->init_timeout_task_id = NULL;
  }

  GNUNET_assert (NULL == h->reconnect_task);
  h->reconnect_task =
      GNUNET_SCHEDULER_add_delayed (h->retry_backoff, &reconnect_arm_monitor_task, h);

  h->retry_backoff = GNUNET_TIME_STD_BACKOFF (h->retry_backoff);
}
Beispiel #8
0
/**
 * Disconnect and then reconnect to the DV service.
 *
 * @param sh service handle
 */
static void
reconnect (struct GNUNET_DV_ServiceHandle *sh)
{
  if (NULL != sh->th)
  {
    GNUNET_CLIENT_notify_transmit_ready_cancel (sh->th);
    sh->th = NULL;
  }
  LOG (GNUNET_ERROR_TYPE_DEBUG,
       "Disconnecting from DV service at %p\n",
       sh->client);
  if (NULL != sh->client)
  {
    GNUNET_CLIENT_disconnect (sh->client);
    sh->client = NULL;
  }
  GNUNET_CONTAINER_multipeermap_iterate (sh->peers,
					 &cleanup_send_cb,
					 sh);
  LOG (GNUNET_ERROR_TYPE_DEBUG,
       "Connecting to DV service\n");
  sh->client = GNUNET_CLIENT_connect ("dv", sh->cfg);
  if (NULL == sh->client)
  {
    GNUNET_break (0);
    return;
  }
  sh->th = GNUNET_CLIENT_notify_transmit_ready (sh->client,
						sizeof (struct GNUNET_MessageHeader),
						GNUNET_TIME_UNIT_FOREVER_REL,
						GNUNET_YES,
						&transmit_start,
						sh);
}
Beispiel #9
0
/**
 * Destroy connection with the service.  This will automatically
 * cancel any pending "receive" request (however, the handler will
 * *NOT* be called, not even with a NULL message).  Any pending
 * transmission request will also be cancelled UNLESS the callback for
 * the transmission request has already been called, in which case the
 * transmission 'finish_pending_write' argument determines whether or
 * not the write is guaranteed to complete before the socket is fully
 * destroyed (unless, of course, there is an error with the server in
 * which case the message may still be lost).
 *
 * @param client handle to the service connection
 */
void
GNUNET_CLIENT_disconnect (struct GNUNET_CLIENT_Connection *client)
{
  if (GNUNET_YES == client->in_receive)
  {
    GNUNET_CONNECTION_receive_cancel (client->connection);
    client->in_receive = GNUNET_NO;
  }
  if (NULL != client->th)
  {
    GNUNET_CLIENT_notify_transmit_ready_cancel (client->th);
    client->th = NULL;
  }
  if (NULL != client->connection)
  {
    GNUNET_CONNECTION_destroy (client->connection);
    client->connection = NULL;
  }
  if (GNUNET_SCHEDULER_NO_TASK != client->receive_task)
  {
    GNUNET_SCHEDULER_cancel (client->receive_task);
    client->receive_task = GNUNET_SCHEDULER_NO_TASK;
  }
  if (NULL != client->tag)
  {
    GNUNET_free (client->tag);
    client->tag = NULL;
  }
  client->receiver_handler = NULL;
  GNUNET_array_grow (client->received_buf, client->received_size, 0);
  GNUNET_free (client->service_name);
  GNUNET_free (client);
}
Beispiel #10
0
Datei: mq.c Projekt: tg-x/gnunet
static void
connection_client_cancel_impl (struct GNUNET_MQ_Handle *mq,
                               void *impl_state)
{
  struct ClientConnectionState *state = impl_state;
  GNUNET_assert (NULL != state->th);
  GNUNET_CLIENT_notify_transmit_ready_cancel (state->th);
  state->th = NULL;
}
/**
 * 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);
}
Beispiel #12
0
/**
 * Disconnect from the datastore service (and free
 * associated resources).
 *
 * @param h handle to the datastore
 * @param drop set to GNUNET_YES to delete all data in datastore (!)
 */
void
GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h, int drop)
{
  struct GNUNET_DATASTORE_QueueEntry *qe;

  LOG (GNUNET_ERROR_TYPE_DEBUG, "Datastore disconnect\n");
  if (NULL != h->th)
  {
    GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
    h->th = NULL;
  }
  if (h->client != NULL)
  {
    GNUNET_CLIENT_disconnect (h->client);
    h->client = NULL;
  }
  if (h->reconnect_task != GNUNET_SCHEDULER_NO_TASK)
  {
    GNUNET_SCHEDULER_cancel (h->reconnect_task);
    h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
  }
  while (NULL != (qe = h->queue_head))
  {
    GNUNET_assert (NULL != qe->response_proc);
    qe->response_proc (h, NULL);
  }
  if (GNUNET_YES == drop)
  {
    h->client = GNUNET_CLIENT_connect ("datastore", h->cfg);
    if (h->client != NULL)
    {
      if (NULL !=
          GNUNET_CLIENT_notify_transmit_ready (h->client,
                                               sizeof (struct
                                                       GNUNET_MessageHeader),
                                               GNUNET_TIME_UNIT_MINUTES,
                                               GNUNET_YES, &transmit_drop, h))
        return;
      GNUNET_CLIENT_disconnect (h->client);
      h->client = NULL;
    }
    GNUNET_break (0);
  }
  GNUNET_STATISTICS_destroy (h->stats, GNUNET_NO);
  h->stats = NULL;
  GNUNET_free (h);
}
Beispiel #13
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);
  }
}
Beispiel #14
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);
}
Beispiel #15
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);
}
Beispiel #16
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);
}
Beispiel #17
0
/**
 * Disconnect from network size estimation service
 *
 * @param h handle to destroy
 */
void
GNUNET_NSE_disconnect (struct GNUNET_NSE_Handle *h)
{
    GNUNET_assert (h != NULL);
    if (h->reconnect_task != GNUNET_SCHEDULER_NO_TASK)
    {
        GNUNET_SCHEDULER_cancel (h->reconnect_task);
        h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
    }
    if (h->th != NULL)
    {
        GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
        h->th = NULL;
    }
    if (h->client != NULL)
    {
        GNUNET_CLIENT_disconnect (h->client);
        h->client = NULL;
    }
    GNUNET_free (h);
}
Beispiel #18
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);
}
Beispiel #19
0
/**
 * Disconnect from PSYCstore service
 *
 * @param h Handle to destroy
 */
void
GNUNET_PSYCSTORE_disconnect (struct GNUNET_PSYCSTORE_Handle *h)
{
  GNUNET_assert (NULL != h);
  if (h->reconnect_task != NULL)
  {
    GNUNET_SCHEDULER_cancel (h->reconnect_task);
    h->reconnect_task = NULL;
  }
  if (NULL != h->th)
  {
    GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
    h->th = NULL;
  }
  if (NULL != h->client)
  {
    GNUNET_CLIENT_disconnect (h->client);
    h->client = NULL;
  }
  GNUNET_free (h);
}
Beispiel #20
0
/**
 * Disconnect from the service (communication error) and reconnect later.
 *
 * @param vh handle to reconnect.
 */
static void
reconnect (struct GNUNET_VPN_Handle *vh)
{
  struct GNUNET_VPN_RedirectionRequest *rr;

  if (NULL != vh->th)
  {
    GNUNET_CLIENT_notify_transmit_ready_cancel (vh->th);
    vh->th = NULL;
  }  
  GNUNET_CLIENT_disconnect (vh->client);
  vh->client = NULL;
  vh->request_id_gen = 0;
  for (rr = vh->rr_head; NULL != rr; rr = rr->next)
    rr->request_id = 0;
  vh->backoff = GNUNET_TIME_relative_max (GNUNET_TIME_UNIT_MILLISECONDS,
					  GNUNET_TIME_relative_min (GNUNET_TIME_relative_multiply (vh->backoff, 2),
								    GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)));
  vh->rt = GNUNET_SCHEDULER_add_delayed (vh->backoff,
					 &connect_task, 
					 vh);
}
Beispiel #21
0
/**
 * Disconnect from identity service
 *
 * @param h handle to destroy
 */
void
GNUNET_IDENTITY_disconnect (struct GNUNET_IDENTITY_Handle *h)
{
  struct GNUNET_IDENTITY_Operation *op;

  GNUNET_assert (NULL != h);
  if (h->reconnect_task != NULL)
  {
    GNUNET_SCHEDULER_cancel (h->reconnect_task);
    h->reconnect_task = NULL;
  }
  if (NULL != h->th)
  {
    GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
    h->th = NULL;
  }
  if (NULL != h->egos)
  {
    GNUNET_CONTAINER_multihashmap_iterate (h->egos,
					   &free_ego,
					   h);
    GNUNET_CONTAINER_multihashmap_destroy (h->egos);
    h->egos = NULL;
  }
  while (NULL != (op = h->op_head))
  {
    GNUNET_break (NULL == op->cont);
    GNUNET_CONTAINER_DLL_remove (h->op_head,
				 h->op_tail,
				 op);
    GNUNET_free (op);
  }
  if (NULL != h->client)
  {
    GNUNET_CLIENT_disconnect (h->client);
    h->client = NULL;
  }
  GNUNET_free (h);
}
Beispiel #22
0
/**
 * Close down any existing connection to the CORE service and
 * try re-establishing it later.
 *
 * @param h our handle
 */
static void
reconnect_later (struct GNUNET_CORE_Handle *h)
{
  struct ControlMessage *cm;
  struct PeerRecord *pr;

  GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == h->reconnect_task);
  if (NULL != h->cth)
  {
    GNUNET_CLIENT_notify_transmit_ready_cancel (h->cth);
    h->cth = NULL;
  }
  if (NULL != h->client)
  {
    GNUNET_CLIENT_disconnect (h->client);
    h->client = NULL;
  }
  h->currently_down = GNUNET_YES;
  GNUNET_assert (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK);
  h->reconnect_task =
      GNUNET_SCHEDULER_add_delayed (h->retry_backoff,
                                    &reconnect_task, h);
  while (NULL != (cm = h->control_pending_head))
  {
    GNUNET_CONTAINER_DLL_remove (h->control_pending_head,
                                 h->control_pending_tail, cm);
    if (NULL != cm->th)
      cm->th->cm = NULL;
    if (NULL != cm->cont)
      cm->cont (cm->cont_cls, GNUNET_NO);
    GNUNET_free (cm);
  }
  GNUNET_CONTAINER_multipeermap_iterate (h->peers,
                                         &disconnect_and_free_peer_entry, h);
  while (NULL != (pr = h->ready_peer_head))
    GNUNET_CONTAINER_DLL_remove (h->ready_peer_head, h->ready_peer_tail, pr);
  GNUNET_assert (h->control_pending_head == NULL);
  h->retry_backoff = GNUNET_TIME_STD_BACKOFF (h->retry_backoff);
}
Beispiel #23
0
/**
 * Reschedule a connect attempt to the service.
 *
 * @param h transport service to reconnect
 */
static void
reschedule_connect (struct GNUNET_PSYCSTORE_Handle *h)
{
  GNUNET_assert (h->reconnect_task == NULL);

  if (NULL != h->th)
  {
    GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
    h->th = NULL;
  }
  if (NULL != h->client)
  {
    GNUNET_CLIENT_disconnect (h->client);
    h->client = NULL;
  }
  h->in_receive = GNUNET_NO;
  LOG (GNUNET_ERROR_TYPE_DEBUG,
       "Scheduling task to reconnect to PSYCstore service in %s.\n",
       GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, GNUNET_YES));
  h->reconnect_task =
      GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
  h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
}
Beispiel #24
0
/**
 * Reschedule a connect attempt to the service.
 *
 * @param h transport service to reconnect
 */
static void
reschedule_connect (struct GNUNET_NSE_Handle *h)
{
    GNUNET_assert (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK);

    if (NULL != h->th)
    {
        GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
        h->th = NULL;
    }
    if (NULL != h->client)
    {
        GNUNET_CLIENT_disconnect (h->client);
        h->client = NULL;
    }

    LOG (GNUNET_ERROR_TYPE_DEBUG,
         "Scheduling task to reconnect to nse service in %llu ms.\n",
         h->reconnect_delay.rel_value);
    h->reconnect_task =
        GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
    h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
}
Beispiel #25
0
/**
 * Cancel an identity operation. Note that the operation MAY still
 * be executed; this merely cancels the continuation; if the request
 * was already transmitted, the service may still choose to complete
 * the operation.
 *
 * @param op operation to cancel
 */
void
GNUNET_IDENTITY_cancel (struct GNUNET_IDENTITY_Operation *op)
{
  struct GNUNET_IDENTITY_Handle *h = op->h;

  if ( (h->op_head != op) ||
       (NULL == h->client) )
  {
    /* request not active, can simply remove */
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "Client aborted non-head operation, simply removing it\n");
    GNUNET_CONTAINER_DLL_remove (h->op_head,
				 h->op_tail,
				 op);
    GNUNET_free (op);
    return;
  }
  if (NULL != h->th)
  {
    /* request active but not yet with service, can still abort */
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "Client aborted head operation prior to transmission, aborting it\n");
    GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
    h->th = NULL;
    GNUNET_CONTAINER_DLL_remove (h->op_head,
				 h->op_tail,
				 op);
    GNUNET_free (op);
    transmit_next (h);
    return;
  }
  /* request active with service, simply ensure continuations are not called */
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Client aborted active request, NULLing continuation\n");
  op->cont = NULL;
  op->cb = NULL;
}
Beispiel #26
0
/**
 * Disconnect from the peerinfo service.  Note that all iterators must
 * have completed or have been cancelled by the time this function is
 * called (otherwise, calling this function is a serious error).
 * Furthermore, if 'GNUNET_PEERINFO_add_peer' operations are still
 * pending, they will be cancelled silently on disconnect.
 *
 * @param h handle to disconnect
 */
void
GNUNET_PEERINFO_disconnect (struct GNUNET_PEERINFO_Handle *h)
{
  struct GNUNET_PEERINFO_AddContext *ac;
  struct GNUNET_PEERINFO_IteratorContext *ic;

  while (NULL != (ic = h->ic_head))
  {
    GNUNET_break (GNUNET_YES == ic->in_receive);
    ic->in_receive = GNUNET_NO;
    GNUNET_PEERINFO_iterate_cancel (ic);
  }
  while (NULL != (ac = h->ac_head))
  {
    GNUNET_CONTAINER_DLL_remove (h->ac_head, h->ac_tail, ac);
    if (NULL != ac->cont)
      ac->cont (ac->cont_cls, _("aborted due to explicit disconnect request"));
    GNUNET_free (ac);
  }
  if (NULL != h->th)
  {
    GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
    h->th = NULL;
  }
  if (NULL != h->client)
  {
    GNUNET_CLIENT_disconnect (h->client);
    h->client = NULL;
  }
  if (GNUNET_SCHEDULER_NO_TASK != h->r_task)
  {
    GNUNET_SCHEDULER_cancel (h->r_task);
    h->r_task = GNUNET_SCHEDULER_NO_TASK;
  }
  GNUNET_free (h);
}
Beispiel #27
0
/**
 * Disconnect from the DNS service.
 *
 * @param dh handle with the connection to disconnect
 */
static void
disconnect (struct GNUNET_DNS_Handle *dh)
{
  struct ReplyQueueEntry *qe;

  if (NULL != dh->dns_transmit_handle)
  {
    GNUNET_CLIENT_notify_transmit_ready_cancel (dh->dns_transmit_handle);
    dh->dns_transmit_handle = NULL;
  }
  if (NULL != dh->dns_connection)
  {
    GNUNET_CLIENT_disconnect (dh->dns_connection);
    dh->dns_connection = NULL;
  }
  while (NULL != (qe = dh->rq_head))
  {
    GNUNET_CONTAINER_DLL_remove (dh->rq_head,
				 dh->rq_tail,
				 qe);
    GNUNET_free (qe);
  }
  dh->in_receive = GNUNET_NO;
}
Beispiel #28
0
/**
 * Request for a service to be started.
 *
 * @param h handle to ARM
 * @param service_name name of the service
 * @param std_inheritance inheritance of std streams
 * @param timeout how long to wait before failing for good
 * @param cont callback to invoke after request is sent or not sent
 * @param cont_cls closure for callback
 */
void
GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h,
				  const char *service_name,
				  enum GNUNET_OS_InheritStdioFlags std_inheritance,
				  struct GNUNET_TIME_Relative timeout,
				  GNUNET_ARM_ResultCallback cont,
				  void *cont_cls)
{
  struct ARMControlMessage *cm;
  size_t slen;

  LOG (GNUNET_ERROR_TYPE_DEBUG,
       "Asked to start service `%s' within %s\n", service_name,
       GNUNET_STRINGS_relative_time_to_string (timeout, GNUNET_NO));
  if (0 == strcasecmp ("arm", service_name))
  {
    /* Possible cases:
     * 1) We're connected to ARM already. Invoke the callback immediately.
     * 2) We're not connected to ARM.
     *    Cancel any reconnection attempts temporarily, then perform
     *    a service test.
     */
    if (GNUNET_NO == h->currently_down)
    {
      LOG (GNUNET_ERROR_TYPE_DEBUG, "ARM is already running\n");
      if (NULL != cont)
        cont (cont_cls, GNUNET_ARM_REQUEST_SENT_OK, "arm", GNUNET_ARM_RESULT_IS_STARTED_ALREADY);
    }
    else if (GNUNET_NO == h->service_test_is_active)
    {
      if (NULL != h->cth)
      {
        GNUNET_CLIENT_notify_transmit_ready_cancel (h->cth);
        h->cth = NULL;
      }
      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;
      }

      LOG (GNUNET_ERROR_TYPE_DEBUG,
          "Not connected to ARM, will do a service test\n");

      slen = strlen ("arm") + 1;
      cm = GNUNET_malloc (sizeof (struct ARMControlMessage) + slen);
      cm->h = h;
      cm->result_cont = cont;
      cm->cont_cls = cont_cls;
      cm->timeout = GNUNET_TIME_relative_to_absolute (timeout);
      cm->std_inheritance = std_inheritance;
      memcpy (&cm[1], service_name, slen);
      h->service_test_is_active = GNUNET_YES;
      GNUNET_CLIENT_service_test ("arm", h->cfg, timeout, &arm_service_report,
				  cm);
    }
    else
    {
      /* Service test is already running - tell user to chill out and try
       * again later.
       */
      LOG (GNUNET_ERROR_TYPE_DEBUG, "Service test is already in progress, we're busy\n");
      if (NULL != cont)
        cont (cont_cls, GNUNET_ARM_REQUEST_BUSY, NULL, 0);
    }
    return;
  }
  change_service (h, service_name, timeout, cont, cont_cls,
		  GNUNET_MESSAGE_TYPE_ARM_START);
}