Example #1
0
/**
 * We got a response or disconnect after asking regex
 * to do the search.  Handle it.
 *
 * @param cls the `struct GNUNET_REGEX_Search` to handle reply for
 * @param msg NULL on disconnect, otherwise presumably a response
 */
static void
handle_search_response (void *cls,
			const struct GNUNET_MessageHeader *msg)
{
  struct GNUNET_REGEX_Search *s = cls;
  const struct ResultMessage *result;
  uint16_t size;
  uint16_t gpl;
  uint16_t ppl;

  if (NULL == msg)
  {
    GNUNET_CLIENT_disconnect (s->client);
    s->client = GNUNET_CLIENT_connect ("regex", s->cfg);
    retry_search (s);
    return;
  }
  size = ntohs (msg->size);
  if ( (GNUNET_MESSAGE_TYPE_REGEX_RESULT == ntohs (msg->type)) &&
       (size >= sizeof (struct ResultMessage)) )
  {
    result = (const struct ResultMessage *) msg;
    gpl = ntohs (result->get_path_length);
    ppl = ntohs (result->put_path_length);
    if (size == (sizeof (struct ResultMessage) +
		 (gpl + ppl) * sizeof (struct GNUNET_PeerIdentity)))
    {
      const struct GNUNET_PeerIdentity *pid;

      GNUNET_CLIENT_receive (s->client,
			     &handle_search_response, s,
			     GNUNET_TIME_UNIT_FOREVER_REL);
      pid = &result->id;
      LOG (GNUNET_ERROR_TYPE_DEBUG,
           "Got regex result %s\n",
           GNUNET_i2s (pid));
      s->callback (s->callback_cls,
		   pid,
		   &pid[1], gpl,
		   &pid[1 + gpl], ppl);
      return;
    }
  }
  GNUNET_break (0);
  GNUNET_CLIENT_disconnect (s->client);
  s->client = GNUNET_CLIENT_connect ("regex", s->cfg);
  retry_search (s);
}
Example #2
0
/**
 * Task to re-try connecting to peerinfo.
 *
 * @param cls the `struct GNUNET_PEERINFO_NotifyContext *`
 */
static void
reconnect (void *cls)
{
  struct GNUNET_PEERINFO_NotifyContext *nc = cls;
  struct GNUNET_MQ_MessageHandler handlers[] = {
    GNUNET_MQ_hd_var_size (notification,
                           GNUNET_MESSAGE_TYPE_PEERINFO_INFO,
                           struct InfoMessage,
                           nc),
    GNUNET_MQ_hd_fixed_size (end_iteration,
                             GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END,
                             struct GNUNET_MessageHeader,
                             nc),
    GNUNET_MQ_handler_end ()
  };
  struct GNUNET_MQ_Envelope *env;
  struct NotifyMessage *nm;

  nc->task = NULL;
  nc->mq = GNUNET_CLIENT_connect (nc->cfg,
                                  "peerinfo",
                                  handlers,
                                  &mq_error_handler,
                                  nc);
  if (NULL == nc->mq)
    return;
  env = GNUNET_MQ_msg (nm,
                       GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY);
  nm->include_friend_only = htonl (nc->include_friend_only);
  GNUNET_MQ_send (nc->mq,
                  env);
}
Example #3
0
static void
task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  struct sockaddr_in sa;
  struct sockaddr *sap[2];
  socklen_t slens[2];

  sap[0] = (struct sockaddr *) &sa;
  slens[0] = sizeof (sa);
  sap[1] = NULL;
  slens[1] = 0;
  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 = htons (PORT);
  server =
      GNUNET_SERVER_create (NULL, NULL, sap, slens,
                            GNUNET_TIME_relative_multiply
                            (GNUNET_TIME_UNIT_MILLISECONDS, 250), GNUNET_NO);
  GNUNET_assert (server != NULL);
  handlers[0].callback_cls = cls;
  GNUNET_SERVER_add_handlers (server, handlers);
  GNUNET_SERVER_disconnect_notify (server, &notify_disconnect, cls);
  cfg = GNUNET_CONFIGURATION_create ();
  GNUNET_CONFIGURATION_set_value_number (cfg, "test", "PORT", PORT);
  GNUNET_CONFIGURATION_set_value_string (cfg, "test", "HOSTNAME", "localhost");
  GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
                                         "localhost");
  client = GNUNET_CLIENT_connect ("test", cfg);
  GNUNET_assert (client != NULL);

  test_mq (client);
}
Example #4
0
/**
 * 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);
}
/**
 * Return information about pending address validation operations for a specific
 * or all peers
 *
 * @param cfg configuration to use
 * @param peer a specific peer identity to obtain validation entries for,
 *      NULL for all peers
 * @param one_shot #GNUNET_YES to return all entries and then end (with NULL+NULL),
 *                 #GNUNET_NO to monitor validation entries continuously
 * @param timeout how long is the lookup allowed to take at most
 * @param validation_callback function to call with the results
 * @param validation_callback_cls closure for peer_address_callback
 */
struct GNUNET_TRANSPORT_ValidationMonitoringContext *
GNUNET_TRANSPORT_monitor_validation_entries (const struct GNUNET_CONFIGURATION_Handle *cfg,
                                             const struct GNUNET_PeerIdentity *peer,
                                             int one_shot,
                                             struct GNUNET_TIME_Relative timeout,
                                             GNUNET_TRANSPORT_ValidationIterateCallback validation_callback,
                                             void *validation_callback_cls)
{
  struct GNUNET_TRANSPORT_ValidationMonitoringContext *val_ctx;
  struct GNUNET_CLIENT_Connection *client;

  client = GNUNET_CLIENT_connect ("transport", cfg);
  if (NULL == client)
    return NULL;
  if (GNUNET_YES != one_shot)
    timeout = GNUNET_TIME_UNIT_FOREVER_REL;
  val_ctx = GNUNET_new (struct GNUNET_TRANSPORT_ValidationMonitoringContext);
  val_ctx->cb = validation_callback;
  val_ctx->cb_cls = validation_callback_cls;
  val_ctx->cfg = cfg;
  val_ctx->timeout = GNUNET_TIME_relative_to_absolute (timeout);
  if (NULL != peer)
    val_ctx->peer = *peer;
  val_ctx->one_shot = one_shot;
  val_ctx->client = client;
  send_val_mon_request (val_ctx);

  return val_ctx;
}
Example #6
0
/**
 * Connect to the set service in order to listen for requests.
 *
 * @param cls the `struct GNUNET_SET_ListenHandle *` to connect
 * @param tc task context if invoked as a task, NULL otherwise
 */
static void
listen_connect (void *cls,
                const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  static const struct GNUNET_MQ_MessageHandler mq_handlers[] = {
    { &handle_request, GNUNET_MESSAGE_TYPE_SET_REQUEST },
    GNUNET_MQ_HANDLERS_END
  };
  struct GNUNET_SET_ListenHandle *lh = cls;
  struct GNUNET_MQ_Envelope *mqm;
  struct GNUNET_SET_ListenMessage *msg;

  if ( (NULL != tc) &&
       (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) )
  {
    LOG (GNUNET_ERROR_TYPE_DEBUG,
         "Listener not reconnecting due to shutdown\n");
    return;
  }
  lh->reconnect_task = NULL;
  GNUNET_assert (NULL == lh->client);
  lh->client = GNUNET_CLIENT_connect ("set", lh->cfg);
  if (NULL == lh->client)
    return;
  GNUNET_assert (NULL == lh->mq);
  lh->mq = GNUNET_MQ_queue_for_connection_client (lh->client,
                                                  mq_handlers,
                                                  &handle_client_listener_error, lh);
  mqm = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SET_LISTEN);
  msg->operation = htonl (lh->operation);
  msg->app_id = lh->app_id;
  GNUNET_MQ_send (lh->mq, mqm);
}
Example #7
0
/**
 * Reconnect to GNS service.
 *
 * @param handle the handle to the GNS service
 */
static void
reconnect (struct GNUNET_GNS_Handle *handle)
{
    struct GNUNET_MQ_MessageHandler handlers[] = {
        GNUNET_MQ_hd_var_size (result,
        GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT,
        struct LookupResultMessage,
        handle),
        GNUNET_MQ_hd_var_size (rev_result,
        GNUNET_MESSAGE_TYPE_GNS_REVERSE_LOOKUP_RESULT,
        struct ReverseLookupResultMessage,
        handle),
        GNUNET_MQ_handler_end ()
    };
    struct GNUNET_GNS_LookupRequest *lh;
    struct GNUNET_GNS_ReverseLookupRequest *rlh;

    GNUNET_assert (NULL == handle->mq);
    LOG (GNUNET_ERROR_TYPE_DEBUG,
         "Trying to connect to GNS\n");
    handle->mq = GNUNET_CLIENT_connect (handle->cfg,
                                        "gns",
                                        handlers,
                                        &mq_error_handler,
                                        handle);
    if (NULL == handle->mq)
        return;
    for (lh = handle->lookup_head; NULL != lh; lh = lh->next)
        GNUNET_MQ_send_copy (handle->mq,
                             lh->env);
    for (rlh = handle->rev_lookup_head; NULL != rlh; rlh = rlh->next)
        GNUNET_MQ_send_copy (handle->mq,
                             rlh->env);
}
Example #8
0
static struct GNUNET_SET_Handle *
create_internal (const struct GNUNET_CONFIGURATION_Handle *cfg,
                 enum GNUNET_SET_OperationType op,
                 uint32_t *cookie)
{
  static const struct GNUNET_MQ_MessageHandler mq_handlers[] = {
    { &handle_result,
      GNUNET_MESSAGE_TYPE_SET_RESULT,
      0 },
    { &handle_iter_element,
      GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT,
      0 },
    { &handle_iter_done,
      GNUNET_MESSAGE_TYPE_SET_ITER_DONE,
      sizeof (struct GNUNET_MessageHeader) },
    { &handle_copy_lazy,
      GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_RESPONSE,
      sizeof (struct GNUNET_SET_CopyLazyResponseMessage) },
    GNUNET_MQ_HANDLERS_END
  };
  struct GNUNET_SET_Handle *set;
  struct GNUNET_MQ_Envelope *mqm;
  struct GNUNET_SET_CreateMessage *create_msg;
  struct GNUNET_SET_CopyLazyConnectMessage *copy_msg;

  set = GNUNET_new (struct GNUNET_SET_Handle);
  set->client = GNUNET_CLIENT_connect ("set", cfg);
  set->cfg = cfg;
  if (NULL == set->client)
  {
    GNUNET_free (set);
    return NULL;
  }
  set->mq = GNUNET_MQ_queue_for_connection_client (set->client,
                                                   mq_handlers,
                                                   &handle_client_set_error,
                                                   set);
  GNUNET_assert (NULL != set->mq);

  if (NULL == cookie)
  {
    LOG (GNUNET_ERROR_TYPE_DEBUG,
         "Creating new set (operation %u)\n",
         op);
    mqm = GNUNET_MQ_msg (create_msg,
                         GNUNET_MESSAGE_TYPE_SET_CREATE);
    create_msg->operation = htonl (op);
  }
  else
  {
    LOG (GNUNET_ERROR_TYPE_DEBUG,
         "Creating new set (lazy copy)\n",
         op);
    mqm = GNUNET_MQ_msg (copy_msg,
                         GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT);
    copy_msg->cookie = *cookie;
  }
  GNUNET_MQ_send (set->mq, mqm);
  return set;
}
Example #9
0
/**
 * Connect to the PEERSTORE service.
 *
 * @param cfg configuration to use
 * @return NULL on error
 */
struct GNUNET_PEERSTORE_Handle *
GNUNET_PEERSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
{
  struct GNUNET_PEERSTORE_Handle *h;

  h = GNUNET_new (struct GNUNET_PEERSTORE_Handle);

  h->client = GNUNET_CLIENT_connect ("peerstore", cfg);
  if (NULL == h->client)
  {
    GNUNET_free (h);
    return NULL;
  }
  h->cfg = cfg;
  h->disconnecting = GNUNET_NO;
  h->mq =
      GNUNET_MQ_queue_for_connection_client (h->client, mq_handlers,
                                             &handle_client_error, h);
  if (NULL == h->mq)
  {
    GNUNET_CLIENT_disconnect (h->client);
    GNUNET_free (h);
    return NULL;
  }
  LOG (GNUNET_ERROR_TYPE_DEBUG, "New connection created\n");
  return h;
}
/**
 * Return information about a specific peer or all peers currently known to
 * transport service once or in monitoring mode. To obtain information about
 * a specific peer, a peer identity can be passed. To obtain information about
 * all peers currently known to transport service, NULL can be passed as peer
 * identity.
 *
 * For each peer, the callback is called with information about the address used
 * to communicate with this peer, the state this peer is currently in and the
 * the current timeout for this state.
 *
 * Upon completion, the 'GNUNET_TRANSPORT_PeerIterateCallback' is called one
 * more time with 'NULL'. After this, the operation must no longer be
 * explicitly canceled.
 *
 * The #GNUNET_TRANSPORT_monitor_peers_cancel call MUST not be called in the
 * the peer_callback!
 *
 * @param cfg configuration to use
 * @param peer a specific peer identity to obtain information for,
 *      NULL for all peers
 * @param one_shot GNUNET_YES to return the current state and then end (with NULL+NULL),
 *                 GNUNET_NO to monitor peers continuously
 * @param timeout how long is the lookup allowed to take at most
 * @param peer_callback function to call with the results
 * @param peer_callback_cls closure for peer_address_callback
 */
struct GNUNET_TRANSPORT_PeerMonitoringContext *
GNUNET_TRANSPORT_monitor_peers (const struct GNUNET_CONFIGURATION_Handle *cfg,
    const struct GNUNET_PeerIdentity *peer,
    int one_shot,
    struct GNUNET_TIME_Relative timeout,
    GNUNET_TRANSPORT_PeerIterateCallback peer_callback,
    void *peer_callback_cls)
{
  struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx;
  struct GNUNET_CLIENT_Connection *client;

  client = GNUNET_CLIENT_connect ("transport", cfg);
  if (client == NULL)
    return NULL;
  if (GNUNET_YES != one_shot)
    timeout = GNUNET_TIME_UNIT_FOREVER_REL;
  pal_ctx = GNUNET_new (struct GNUNET_TRANSPORT_PeerMonitoringContext);
  pal_ctx->cb = peer_callback;
  pal_ctx->cb_cls = peer_callback_cls;
  pal_ctx->cfg = cfg;
  pal_ctx->timeout = GNUNET_TIME_relative_to_absolute (timeout);
  if (NULL != peer)
    pal_ctx->peer = *peer;
  pal_ctx->one_shot = one_shot;
  pal_ctx->client = client;
  send_peer_mon_request (pal_ctx);

  return pal_ctx;
}
static void
kill_task (void *cbData, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  static struct GNUNET_CLIENT_Connection *doNothingConnection = NULL;

  if (NULL != cbData)
    {
      waitedFor = GNUNET_TIME_absolute_get_duration (startedWaitingAt);

#if LOG_BACKOFF
      FPRINTF (killLogFilePtr, "Waited for: %llu ms\n",
	       (unsigned long long) waitedFor.rel_value);
#endif
    }
  else
    {
      waitedFor.rel_value = 0;
    }
  /* Connect to the doNothing task */
  doNothingConnection = GNUNET_CLIENT_connect ("do-nothing", cfg);
  GNUNET_assert (doNothingConnection != NULL);
  if (trialCount == 12)
    {
      GNUNET_CLIENT_disconnect (doNothingConnection);
      GNUNET_ARM_stop_service (arm, "do-nothing", TIMEOUT, &arm_notify_stop,
			       NULL);
      ok = 0;
      return;
    }
  /* Use the created connection to kill the doNothingTask */
  arm_service_shutdown (doNothingConnection, TIMEOUT, &shutdown_cont, NULL);
}
Example #12
0
File: dv_api.c Project: tg-x/gnunet
/**
 * 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);
}
Example #13
0
/**
 * Iterate over all indexed files.
 *
 * @param h handle to the file sharing subsystem
 * @param iterator function to call on each indexed file
 * @param iterator_cls closure for iterator
 * @return NULL on error ('iter' is not called)
 */
struct GNUNET_FS_GetIndexedContext *
GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
                             GNUNET_FS_IndexedFileProcessor iterator,
                             void *iterator_cls)
{
  struct GNUNET_CLIENT_Connection *client;
  struct GNUNET_FS_GetIndexedContext *gic;
  struct GNUNET_MessageHeader msg;

  client = GNUNET_CLIENT_connect ("fs", h->cfg);
  if (NULL == client)
  {
    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                _("Failed to not connect to `%s' service.\n"), "fs");
    return NULL;
  }
  gic = GNUNET_new (struct GNUNET_FS_GetIndexedContext);
  gic->h = h;
  gic->client = client;
  gic->iterator = iterator;
  gic->iterator_cls = iterator_cls;
  msg.size = htons (sizeof (struct GNUNET_MessageHeader));
  msg.type = htons (GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET);
  GNUNET_assert (GNUNET_OK ==
                 GNUNET_CLIENT_transmit_and_get_response (client, &msg,
                                                          GNUNET_CONSTANTS_SERVICE_TIMEOUT,
                                                          GNUNET_YES,
                                                          &handle_index_info,
                                                          gic));
  return gic;
}
Example #14
0
/**
 * Search for a peer offering a regex matching certain string in the DHT.
 * The search runs until #GNUNET_REGEX_search_cancel() is called, even if results
 * are returned.
 *
 * @param cfg configuration to use
 * @param string String to match against the regexes in the DHT.
 * @param callback Callback for found peers.
 * @param callback_cls Closure for @c callback.
 * @return Handle to stop search and free resources.
 *         Must be freed by calling #GNUNET_REGEX_search_cancel().
 */
struct GNUNET_REGEX_Search *
GNUNET_REGEX_search (const struct GNUNET_CONFIGURATION_Handle *cfg,
		     const char *string,
                     GNUNET_REGEX_Found callback,
                     void *callback_cls)
{
  struct GNUNET_REGEX_Search *s;
  size_t slen;

  LOG (GNUNET_ERROR_TYPE_DEBUG,
       "Starting regex search for %s\n",
       string);
  slen = strlen (string) + 1;
  s = GNUNET_new (struct GNUNET_REGEX_Search);
  s->cfg = cfg;
  s->client = GNUNET_CLIENT_connect ("regex", cfg);
  if (NULL == s->client)
  {
    GNUNET_free (s);
    return NULL;
  }
  s->callback = callback;
  s->callback_cls = callback_cls;
  s->msg = GNUNET_malloc (sizeof (struct RegexSearchMessage) + slen);
  s->msg->header.type = htons (GNUNET_MESSAGE_TYPE_REGEX_SEARCH);
  s->msg->header.size = htons (sizeof (struct RegexSearchMessage) + slen);
  memcpy (&s->msg[1], string, slen);
  retry_search (s);
  return s;
}
Example #15
0
/**
 * Establish blacklist connection to transport service.
 *
 * @param br overall handle
 */
static void
reconnect (struct GNUNET_TRANSPORT_Blacklist *br)
{
  struct GNUNET_MQ_MessageHandler handlers[] = {
    GNUNET_MQ_hd_fixed_size (query,
                             GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY,
                             struct BlacklistMessage,
                             br),
    GNUNET_MQ_handler_end ()
  };
  struct GNUNET_MQ_Envelope *env;
  struct GNUNET_MessageHeader *req;

  if (NULL != br->mq)
    GNUNET_MQ_destroy (br->mq);
  br->mq = GNUNET_CLIENT_connect (br->cfg,
                                  "transport",
                                  handlers,
                                  &mq_error_handler,
                                  br);
  if (NULL == br->mq)
    return;
  env = GNUNET_MQ_msg (req,
                       GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT);
  GNUNET_MQ_send (br->mq,
                  env);
}
Example #16
0
/**
 * Try again to connect to the identity service.
 *
 * @param cls handle to the identity service.
 * @param tc scheduler context
 */
static void
reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  struct GNUNET_IDENTITY_Handle *h = cls;
  struct GNUNET_IDENTITY_Operation *op;
  struct GNUNET_MessageHeader msg;

  h->reconnect_task = NULL;
  LOG (GNUNET_ERROR_TYPE_DEBUG,
       "Connecting to identity service.\n");
  GNUNET_assert (NULL == h->client);
  h->client = GNUNET_CLIENT_connect ("identity", h->cfg);
  GNUNET_assert (NULL != h->client);
  if ( (NULL == h->op_head) ||
       (GNUNET_MESSAGE_TYPE_IDENTITY_START != ntohs (h->op_head->msg->type)) )
  {
    op = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_Operation) +
			sizeof (struct GNUNET_MessageHeader));
    op->h = h;
    op->msg = (const struct GNUNET_MessageHeader *) &op[1];
    msg.size = htons (sizeof (msg));
    msg.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_START);
    memcpy (&op[1], &msg, sizeof (msg));
    GNUNET_CONTAINER_DLL_insert (h->op_head,
				 h->op_tail,
				 op);
  }
  transmit_next (h);
  GNUNET_assert (NULL != h->th);
}
/**
 * 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);
}
Example #18
0
/**
 * First task run by the scheduler.  Initializes the server and
 * a client and asks for a transmission from the client to the
 * server.
 *
 * @param cls NULL
 */
static void
task (void *cls)
{
  struct sockaddr_in sa;
  struct sockaddr *sap[2];
  socklen_t slens[2];
  struct GNUNET_MQ_Envelope *env;
  struct GNUNET_MessageHeader *msg;
  struct GNUNET_MQ_MessageHandler chandlers[] = {
    GNUNET_MQ_hd_fixed_size (reply,
                             MY_TYPE,
                             struct GNUNET_MessageHeader,
                             cls),
    GNUNET_MQ_handler_end ()
  };

  sap[0] = (struct sockaddr *) &sa;
  slens[0] = sizeof (sa);
  sap[1] = NULL;
  slens[1] = 0;
  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 = htons (PORT);
  server = GNUNET_SERVER_create (NULL, NULL,
                                 sap, slens,
                                 TIMEOUT, GNUNET_NO);
  GNUNET_assert (server != NULL);
  GNUNET_SERVER_add_handlers (server, handlers);
  cfg = GNUNET_CONFIGURATION_create ();
  GNUNET_CONFIGURATION_set_value_number (cfg,
                                         "test-server",
                                         "PORT",
                                         PORT);
  GNUNET_CONFIGURATION_set_value_string (cfg,
                                         "test-server",
                                         "HOSTNAME",
                                         "localhost");
  GNUNET_CONFIGURATION_set_value_string (cfg,
                                         "resolver",
                                         "HOSTNAME",
                                         "localhost");
  mq = GNUNET_CLIENT_connect (cfg,
                              "test-server",
                              chandlers,
                              &mq_error_handler,
                              NULL);
  GNUNET_assert (NULL != mq);
  ok = 2;
  env = GNUNET_MQ_msg (msg,
                       MY_TYPE);
  GNUNET_MQ_send (mq,
                  env);
}
Example #19
0
/**
 * Connect to the peerinfo service.
 *
 * @param cfg configuration to use
 * @return NULL on error (configuration related, actual connection
 *         establishment may happen asynchronously).
 */
struct GNUNET_PEERINFO_Handle *
GNUNET_PEERINFO_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
{
  struct GNUNET_PEERINFO_Handle *h;

  h = GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_Handle));
  h->client = GNUNET_CLIENT_connect ("peerinfo", cfg);
  h->cfg = cfg;
  return h;
}
Example #20
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);
}
Example #21
0
static void
task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  struct sockaddr_in sa;
  struct sockaddr *sap[2];
  socklen_t slens[2];

  /* test that ill-configured client fails instantly */
  GNUNET_assert (NULL == GNUNET_CLIENT_connect ("invalid-service", cfg));

  /* test IPC between client and server */
  sap[0] = (struct sockaddr *) &sa;
  slens[0] = sizeof (sa);
  sap[1] = NULL;
  slens[1] = 0;
  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 = htons (PORT);
  server =
      GNUNET_SERVER_create (NULL, NULL, sap, slens,
                            GNUNET_TIME_relative_multiply
                            (GNUNET_TIME_UNIT_MILLISECONDS, 10000), GNUNET_NO);
  GNUNET_assert (server != NULL);
  handlers[0].callback_cls = cls;
  handlers[1].callback_cls = cls;
  GNUNET_SERVER_add_handlers (server, handlers);
  client = GNUNET_CLIENT_connect (MYNAME, cfg);
  GNUNET_assert (client != NULL);
  GNUNET_assert (NULL !=
                 GNUNET_CLIENT_notify_transmit_ready (client,
                                                      sizeof (struct
                                                              GNUNET_MessageHeader),
                                                      GNUNET_TIME_relative_multiply
                                                      (GNUNET_TIME_UNIT_SECONDS,5),
                                                      GNUNET_NO, &make_msg,
                                                      NULL));
  GNUNET_CLIENT_receive (client, &recv_bounce, cls,
                         GNUNET_TIME_relative_multiply
                         (GNUNET_TIME_UNIT_MILLISECONDS, 10000));
}
Example #22
0
/**
 * Reconnect to GNS service.
 *
 * @param handle the handle to the GNS service
 */
static void
reconnect (struct GNUNET_GNS_Handle *handle)
{
  GNUNET_assert (NULL == handle->client);
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
	      "Trying to connect to GNS\n");
  handle->client = GNUNET_CLIENT_connect ("gns", handle->cfg);
  GNUNET_assert (NULL != handle->client);
  process_pending_messages (handle);
}
/**
 * Task run to re-establish the connection.
 *
 * @param cls our 'struct GNUNET_TRANSPORT_PeerAddressLookupContext*'
 * @param tc scheduler context, unused
 */
static void
do_peer_connect (void *cls,
           const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls;

  pal_ctx->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
  pal_ctx->client = GNUNET_CLIENT_connect ("transport", pal_ctx->cfg);
  GNUNET_assert (NULL != pal_ctx->client);
  send_peer_mon_request (pal_ctx);
}
/**
 * Task run to re-establish the connection.
 *
 * @param cls our `struct GNUNET_TRANSPORT_ValidationMonitoringContext *`
 * @param tc scheduler context, unused
 */
static void
do_val_connect (void *cls,
                const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  struct GNUNET_TRANSPORT_ValidationMonitoringContext *val_ctx = cls;

  val_ctx->reconnect_task = NULL;
  val_ctx->client = GNUNET_CLIENT_connect ("transport", val_ctx->cfg);
  GNUNET_assert (NULL != val_ctx->client);
  send_val_mon_request (val_ctx);
}
Example #25
0
/**
 * Our current client connection went down.  Clean it up
 * and try to reconnect!
 *
 * @param h our handle to the core service
 */
static void
reconnect (struct GNUNET_CORE_Handle *h)
{
  struct ControlMessage *cm;
  struct InitMessage *init;
  uint32_t opt;
  uint16_t msize;
  uint16_t *ts;
  unsigned int hpos;

  GNUNET_assert (NULL == h->client);
  GNUNET_assert (GNUNET_YES == h->currently_down);
  GNUNET_assert (NULL != h->cfg);
  h->client = GNUNET_CLIENT_connect ("core", h->cfg);
  if (NULL == h->client)
  {
    reconnect_later (h);
    return;
  }
  msize = h->hcnt * sizeof (uint16_t) + sizeof (struct InitMessage);
  cm = GNUNET_malloc (sizeof (struct ControlMessage) + msize);
  cm->cont = &init_done_task;
  cm->cont_cls = h;
  init = (struct InitMessage *) &cm[1];
  init->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_INIT);
  init->header.size = htons (msize);
  opt = 0;
  if (h->inbound_notify != NULL)
  {
    if (h->inbound_hdr_only)
      opt |= GNUNET_CORE_OPTION_SEND_HDR_INBOUND;
    else
      opt |= GNUNET_CORE_OPTION_SEND_FULL_INBOUND;
  }
  if (h->outbound_notify != NULL)
  {
    if (h->outbound_hdr_only)
      opt |= GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND;
    else
      opt |= GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND;
  }
  LOG (GNUNET_ERROR_TYPE_INFO,
       "(Re)connecting to CORE service, monitoring messages of type %u\n",
       opt);

  init->options = htonl (opt);
  ts = (uint16_t *) & init[1];
  for (hpos = 0; hpos < h->hcnt; hpos++)
    ts[hpos] = htons (h->handlers[hpos].type);
  GNUNET_CONTAINER_DLL_insert (h->control_pending_head, h->control_pending_tail,
                               cm);
  trigger_next_request (h, GNUNET_YES);
}
Example #26
0
/**
 * Test if NAT has been punched
 *
 * @param ah auto setup context
 */
static void
test_nat_punched (struct GNUNET_NAT_AutoHandle *ah)
{

  struct GNUNET_CLIENT_Connection *client;
  struct GNUNET_NAT_TestMessage msg;


  if (ah->stun_ip)
  {
    LOG (GNUNET_ERROR_TYPE_INFO,
         "Asking gnunet-nat-server to connect to `%s'\n",
         ah->stun_ip);


    msg.header.size = htons (sizeof (struct GNUNET_NAT_TestMessage));
    msg.header.type = htons (GNUNET_MESSAGE_TYPE_NAT_TEST);
    msg.dst_ipv4 = inet_addr(ah->stun_ip);
    msg.dport = htons(ah->stun_port);
    msg.data = port;
    msg.is_tcp = htonl ((uint32_t) GNUNET_NO);

    client = GNUNET_CLIENT_connect ("gnunet-nat-server", ah->cfg);
    if (NULL == client)
    {
      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                  _("Failed to connect to `gnunet-nat-server'\n"));
      return;
    }

    GNUNET_break (GNUNET_OK ==
                  GNUNET_CLIENT_transmit_and_get_response (client, &msg.header,
                                                           NAT_SERVER_TIMEOUT,
                                                           GNUNET_YES, NULL,
                                                           NULL));
    if (NULL != ltask4)
    {
      GNUNET_SCHEDULER_cancel (ltask4);
      ltask4 = GNUNET_SCHEDULER_add_read_net (NAT_SERVER_TIMEOUT,
                                              lsock4, &do_udp_read, ah);
    }

  }
  else
  {
    LOG (GNUNET_ERROR_TYPE_INFO,
         "We don't have a STUN IP");
    next_phase(ah);
  }


}
/**
 * Connect to the testbed logger service
 *
 * @param cfg configuration to use
 * @return the handle which can be used for sending data to the service; NULL
 *           upon any error
 */
struct GNUNET_TESTBED_LOGGER_Handle *
GNUNET_TESTBED_LOGGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
{
  struct GNUNET_TESTBED_LOGGER_Handle *h;
  struct GNUNET_CLIENT_Connection *client;

  client = GNUNET_CLIENT_connect ("testbed-logger", cfg);
  if (NULL == client)
    return NULL;
  h = GNUNET_new (struct GNUNET_TESTBED_LOGGER_Handle);
  h->client = client;
  return h;
}
Example #28
0
/**
 * Try again to connect to the PSYCstore service.
 *
 * @param cls Handle to the PSYCstore service.
 * @param tc Scheduler context.
 */
static void
reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  struct GNUNET_PSYCSTORE_Handle *h = cls;

  h->reconnect_task = NULL;
  LOG (GNUNET_ERROR_TYPE_DEBUG,
       "Connecting to PSYCstore service.\n");
  GNUNET_assert (NULL == h->client);
  h->client = GNUNET_CLIENT_connect ("psycstore", h->cfg);
  GNUNET_assert (NULL != h->client);
  transmit_next (h);
}
Example #29
0
/**
 * Try to (re)connect to the DHT service.
 *
 * @param handle DHT handle to reconnect
 * @return #GNUNET_YES on success, #GNUNET_NO on failure.
 */
static int
try_connect (struct GNUNET_DHT_Handle *handle)
{
  if (NULL != handle->client)
    return GNUNET_OK;
  handle->in_receive = GNUNET_NO;
  handle->client = GNUNET_CLIENT_connect ("dht", handle->cfg);
  if (NULL == handle->client)
  {
    LOG (GNUNET_ERROR_TYPE_WARNING,
         _("Failed to connect to the DHT service!\n"));
    return GNUNET_NO;
  }
  return GNUNET_YES;
}
Example #30
0
/**
 * Connect to the VPN service
 *
 * @param cfg configuration to use
 * @return VPN handle 
 */
struct GNUNET_VPN_Handle *
GNUNET_VPN_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
{
  struct GNUNET_VPN_Handle *vh;

  vh = GNUNET_malloc (sizeof (struct GNUNET_VPN_Handle));
  vh->cfg = cfg;
  vh->client = GNUNET_CLIENT_connect ("vpn", cfg);
  if (NULL == vh->client)
  {
    GNUNET_free (vh);
    return NULL;
  }
  return vh;
}