예제 #1
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;
}
예제 #2
0
파일: regex_api.c 프로젝트: tg-x/gnunet
/**
 * Try sending the announcement request to regex.  On
 * errors (i.e. regex died), try again.
 *
 * @param a the announcement to retry
 */
static void
retry_announcement (struct GNUNET_REGEX_Announcement *a)
{
  GNUNET_assert (NULL != a->client);
  GNUNET_assert (GNUNET_OK ==
		 GNUNET_CLIENT_transmit_and_get_response (a->client,
							  &a->msg.header,
							  GNUNET_TIME_UNIT_FOREVER_REL,
							  GNUNET_YES,
							  &handle_a_reconnect,
							  a));
}
예제 #3
0
파일: regex_api.c 프로젝트: tg-x/gnunet
/**
 * Try sending the search request to regex.  On
 * errors (i.e. regex died), try again.
 *
 * @param s the search to retry
 */
static void
retry_search (struct GNUNET_REGEX_Search *s)
{
  GNUNET_assert (NULL != s->client);
  GNUNET_assert (GNUNET_OK ==
		 GNUNET_CLIENT_transmit_and_get_response (s->client,
							  &s->msg->header,
							  GNUNET_TIME_UNIT_FOREVER_REL,
							  GNUNET_YES,
							  &handle_search_response,
							  s));
}
예제 #4
0
파일: nat_auto.c 프로젝트: muggenhor/GNUnet
/**
 * 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);
  }


}
예제 #5
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;
}
예제 #6
0
파일: nat_test.c 프로젝트: tg-x/gnunet
/**
 * Address-callback, used to send message to gnunet-nat-server.
 *
 * @param cls closure
 * @param add_remove #GNUNET_YES to mean the new public IP address, #GNUNET_NO to mean
 *     the previous (now invalid) one
 * @param addr either the previous or the new public IP address
 * @param addrlen actual length of the @a addr
 */
static void
addr_cb (void *cls,
         int add_remove,
         const struct sockaddr *addr,
         socklen_t addrlen)
{
  struct GNUNET_NAT_Test *h = cls;
  struct ClientActivity *ca;
  struct GNUNET_CLIENT_Connection *client;
  struct GNUNET_NAT_TestMessage msg;
  const struct sockaddr_in *sa;

  if (GNUNET_YES != add_remove)
    return;
  if (addrlen != sizeof (struct sockaddr_in))
  {
    LOG (GNUNET_ERROR_TYPE_DEBUG,
	 "NAT test ignores IPv6 address `%s' returned from NAT library\n",
	 GNUNET_a2s (addr, addrlen));
    return;                     /* ignore IPv6 here */
  }
  LOG (GNUNET_ERROR_TYPE_INFO,
       "Asking gnunet-nat-server to connect to `%s'\n",
       GNUNET_a2s (addr, addrlen));
  sa = (const struct sockaddr_in *) addr;
  msg.header.size = htons (sizeof (struct GNUNET_NAT_TestMessage));
  msg.header.type = htons (GNUNET_MESSAGE_TYPE_NAT_TEST);
  msg.dst_ipv4 = sa->sin_addr.s_addr;
  msg.dport = sa->sin_port;
  msg.data = h->data;
  msg.is_tcp = htonl ((uint32_t) h->is_tcp);

  client = GNUNET_CLIENT_connect ("gnunet-nat-server", h->cfg);
  if (NULL == client)
  {
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                _("Failed to connect to `gnunet-nat-server'\n"));
    return;
  }
  ca = GNUNET_new (struct ClientActivity);
  ca->client = client;
  GNUNET_CONTAINER_DLL_insert (h->ca_head, h->ca_tail, ca);
  GNUNET_break (GNUNET_OK ==
                GNUNET_CLIENT_transmit_and_get_response (client, &msg.header,
                                                         NAT_SERVER_TIMEOUT,
                                                         GNUNET_YES, NULL,
                                                         NULL));
}
/**
 * Send our subscription request to the service.
 *
 * @param val_ctx our context
 */
static void
send_val_mon_request (struct GNUNET_TRANSPORT_ValidationMonitoringContext *val_ctx)
{
  struct ValidationMonitorMessage msg;

  msg.header.size = htons (sizeof (struct ValidationMonitorMessage));
  msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_REQUEST);
  msg.one_shot = htonl (val_ctx->one_shot);
  msg.peer = val_ctx->peer;
  GNUNET_assert (GNUNET_OK ==
                 GNUNET_CLIENT_transmit_and_get_response (val_ctx->client,
                    &msg.header,
                    GNUNET_TIME_absolute_get_remaining (val_ctx->timeout),
                    GNUNET_YES,
                    &val_response_processor,
                    val_ctx));
}
/**
 * Send our subscription request to the service.
 *
 * @param pal_ctx our context
 */
static void
send_peer_mon_request (struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx)
{
  struct PeerMonitorMessage msg;

  msg.header.size = htons (sizeof (struct PeerMonitorMessage));
  msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST);
  msg.one_shot = htonl (pal_ctx->one_shot);
  msg.peer = pal_ctx->peer;
  GNUNET_assert (GNUNET_OK ==
                 GNUNET_CLIENT_transmit_and_get_response (pal_ctx->client,
                    &msg.header,
                    GNUNET_TIME_absolute_get_remaining (pal_ctx->timeout),
                    GNUNET_YES,
                    &peer_response_processor,
                    pal_ctx));
}
예제 #9
0
파일: fs_unindex.c 프로젝트: tg-x/gnunet
/**
 * Function called when we are done with removing UBlocks.
 * Disconnect from datastore and notify FS service about
 * the unindex event.
 *
 * @param uc our unindexing context
 */
static void
unindex_finish (struct GNUNET_FS_UnindexContext *uc)
{
  char *emsg;
  struct UnindexMessage req;

  /* generate final progress message */
  unindex_progress (uc, uc->file_size, NULL, 0, 0);
  GNUNET_FS_tree_encoder_finish (uc->tc, &emsg);
  uc->tc = NULL;
  GNUNET_DISK_file_close (uc->fh);
  uc->fh = NULL;
  GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO);
  uc->dsh = NULL;
  GNUNET_CONTAINER_multihashmap_destroy (uc->seen_dh);
  uc->seen_dh = NULL;
  uc->state = UNINDEX_STATE_FS_NOTIFY;
  GNUNET_FS_unindex_sync_ (uc);
  uc->client = GNUNET_CLIENT_connect ("fs", uc->h->cfg);
  if (uc->client == NULL)
  {
    uc->state = UNINDEX_STATE_ERROR;
    uc->emsg =
        GNUNET_strdup (_("Failed to connect to FS service for unindexing."));
    GNUNET_FS_unindex_sync_ (uc);
    signal_unindex_error (uc);
    return;
  }
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Sending UNINDEX message to FS service\n");
  req.header.size = htons (sizeof (struct UnindexMessage));
  req.header.type = htons (GNUNET_MESSAGE_TYPE_FS_UNINDEX);
  req.reserved = 0;
  req.file_id = uc->file_id;
  GNUNET_break (GNUNET_OK ==
                GNUNET_CLIENT_transmit_and_get_response (uc->client,
                                                         &req.header,
                                                         GNUNET_CONSTANTS_SERVICE_TIMEOUT,
                                                         GNUNET_YES,
                                                         &process_fs_response,
                                                         uc));
}