static char *
generate_config (char *cfg_file, unsigned long long quota_in,
                 unsigned long long quota_out)
{
  char *networks[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkTypeString;
  char *in_name;
  char *out_name;
  char *fname = NULL;
  struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create ();
  int c;

  GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (cfg, cfg_file));
  GNUNET_asprintf (&fname, "q_in_%llu_q_out_%llu_%s", quota_in, quota_out,
                   cfg_file);

  GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG", fname);

  for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
  {
      GNUNET_asprintf (&in_name, "%s_QUOTA_IN", networks[c]);
      GNUNET_asprintf (&out_name, "%s_QUOTA_OUT", networks[c]);
      GNUNET_CONFIGURATION_set_value_number (cfg, "ats", in_name, quota_in);
      GNUNET_CONFIGURATION_set_value_number (cfg, "ats", out_name, quota_out);
      GNUNET_free (in_name);
      GNUNET_free (out_name);
  }
  GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_write (cfg, fname));
  GNUNET_CONFIGURATION_destroy (cfg);
  return fname;
}
Example #2
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);
}
static char *
generate_config (char *cfg_file, unsigned long long quota_in,
                 unsigned long long quota_out)
{
  char *fname = NULL;
  struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create ();

  GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (cfg, cfg_file));
  GNUNET_asprintf (&fname, "q_in_%llu_q_out_%llu_%s", quota_in, quota_out,
                   cfg_file);
  GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG", fname);
  GNUNET_CONFIGURATION_set_value_number (cfg, "ats", "WAN_QUOTA_IN", quota_in);
  GNUNET_CONFIGURATION_set_value_number (cfg, "ats", "WAN_QUOTA_OUT",
                                         quota_out);
  GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_write (cfg, fname));
  GNUNET_CONFIGURATION_destroy (cfg);
  return fname;
}
Example #4
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 #5
0
int
main (int argc, char *argv[])
{
  int ok;

  GNUNET_log_setup ("test_client",
                    "WARNING",
                    NULL);
  cfg = GNUNET_CONFIGURATION_create ();
  GNUNET_CONFIGURATION_set_value_number (cfg, MYNAME, "PORT", PORT);
  GNUNET_CONFIGURATION_set_value_string (cfg, MYNAME, "HOSTNAME", "localhost");
  GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
                                         "localhost");
  ok = 1;
  GNUNET_SCHEDULER_run (&task, &ok);
  GNUNET_CONFIGURATION_destroy (cfg);
  return ok;
}
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, TIMEOUT, GNUNET_NO);
    GNUNET_assert (server != NULL);
    GNUNET_SERVER_add_handlers (server, handlers);
    GNUNET_SERVER_disconnect_notify (server, &notify_disconnect, NULL);
    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");
    cc = GNUNET_CLIENT_connect ("test-server", cfg);
    GNUNET_assert (cc != NULL);
    GNUNET_assert (NULL !=
                   GNUNET_CLIENT_notify_transmit_ready (cc,
                           sizeof (struct
                                   GNUNET_MessageHeader),
                           TIMEOUT, GNUNET_YES,
                           &transmit_initial_message,
                           NULL));
}
/**
 * Function called with th test result to see if the resolver is
 * running.
 *
 * @param cls closure with our configuration
 * @param result #GNUNET_YES if the resolver is running
 */
static void
resolver_test_task (void *cls,
		    int result)
{
  struct GNUNET_CONFIGURATION_Handle *cfg = cls;

  if (GNUNET_YES != result)
   {
     FPRINTF (stderr,
	      _("Trying to connect to remote host, but service `%s' is not running\n"), "resolver");
     return;
   }
  /* connect to a remote host */
  if (0 == remote_port)
  {
    if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, "statistics", "PORT", &remote_port))
    {
      FPRINTF (stderr, _("A port is required to connect to host `%s'\n"), remote_host);
      return;
    }
  }
  else if (65535 <= remote_port)
  {
    FPRINTF (stderr,
	     _("A port has to be between 1 and 65535 to connect to host `%s'\n"), remote_host);
    return;
  }

  /* Manipulate configuration */
  GNUNET_CONFIGURATION_set_value_string (cfg,
					 "statistics", "UNIXPATH", "");
  GNUNET_CONFIGURATION_set_value_string (cfg,
					 "statistics", "HOSTNAME", remote_host);
  GNUNET_CONFIGURATION_set_value_number (cfg,
					 "statistics", "PORT", remote_port);
  GNUNET_SCHEDULER_add_now (&main_task, cfg);
}
/**
 * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER messages
 *
 * @param cls identification of the client
 * @param msg the actual message
 */
void
handle_peer_create (void *cls,
                    const struct GNUNET_TESTBED_PeerCreateMessage *msg)
{
  struct GNUNET_SERVICE_Client *client = cls;
  struct GNUNET_MQ_Envelope *env;
  struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *reply;
  struct GNUNET_CONFIGURATION_Handle *cfg;
  struct ForwardedOperationContext *fo_ctxt;
  struct Route *route;
  struct Peer *peer;
  char *emsg;
  uint32_t host_id;
  uint32_t peer_id;

  host_id = ntohl (msg->host_id);
  peer_id = ntohl (msg->peer_id);
  if (VALID_PEER_ID (peer_id))
  {
    (void) GNUNET_asprintf (&emsg,
                            "Peer with ID %u already exists",
                            peer_id);
    GST_send_operation_fail_msg (client,
                                 GNUNET_ntohll (msg->operation_id),
                                 emsg);
    GNUNET_free (emsg);
    GNUNET_SERVICE_client_continue (client);
    return;
  }
  if (UINT32_MAX == peer_id)
  {
    GST_send_operation_fail_msg (client,
                                 GNUNET_ntohll (msg->operation_id),
                                 "Cannot create peer with given ID");
    GNUNET_SERVICE_client_continue (client);
    return;
  }
  if (host_id == GST_context->host_id)
  {
    /* We are responsible for this peer */
    cfg = GNUNET_TESTBED_extract_config_ (&msg->header);
    if (NULL == cfg)
    {
      GNUNET_break (0);
      GNUNET_SERVICE_client_drop (client);
      return;
    }
    GNUNET_CONFIGURATION_set_value_number (cfg,
                                           "TESTBED",
                                           "PEERID",
                                           (unsigned long long) peer_id);

    GNUNET_CONFIGURATION_set_value_number (cfg,
                                           "PATHS",
                                           "PEERID",
                                           (unsigned long long) peer_id);
    peer = GNUNET_new (struct Peer);
    peer->is_remote = GNUNET_NO;
    peer->details.local.cfg = cfg;
    peer->id = peer_id;
    LOG_DEBUG ("Creating peer with id: %u\n",
               (unsigned int) peer->id);
    peer->details.local.peer =
        GNUNET_TESTING_peer_configure (GST_context->system,
                                       peer->details.local.cfg, peer->id,
                                       NULL /* Peer id */ ,
                                       &emsg);
    if (NULL == peer->details.local.peer)
    {
      LOG (GNUNET_ERROR_TYPE_WARNING,
           "Configuring peer failed: %s\n",
           emsg);
      GNUNET_free (emsg);
      GNUNET_free (peer);
      GNUNET_break (0);
      GNUNET_SERVICE_client_drop (client);
      return;
    }
    peer->details.local.is_running = GNUNET_NO;
    peer_list_add (peer);
    env = GNUNET_MQ_msg (reply,
                         GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS);
    reply->peer_id = msg->peer_id;
    reply->operation_id = msg->operation_id;
    GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
                    env);
    GNUNET_SERVICE_client_continue (client);
    return;
  }
Example #9
0
int
main (int argc, char *argv[])
{
  int ok;
  int status;
  const char *socksport = "1081";

  GNUNET_log_setup ("test_client",
                    "WARNING",
                    NULL);

  pid_t pid = fork();
  GNUNET_assert (pid >= 0);
  if (pid == 0) 
  {
    execlp ("ssh",
            "ssh","-D",socksport,
            "-o","BatchMode yes",
            "-o","UserKnownHostsFile /tmp/gnunet_test_socks_ssh_garbage",
            "-o","StrictHostKeyChecking no",
            "127.0.0.1","-N",(char*)NULL);
    perror ("execlp (\"ssh\",\"ssh\",...,\"-D\",\"1081\",\"127.0.0.1\",\"-N\") ");
    printf (""
"Please ensure you have ssh installed and have sshd installed and running :\n"
"\tsudo apt-get install openssh-client openssh-server\n"
"If you run Tor as a network proxy then Tor might prevent ssh from connecting\n"
"to localhost.  Please either run  make check  from an unproxied user, or else\n"
"add these lines to the beginning of your ~/.ssh/config file :"
"\tHost 127.0.0.1 localhost\n"
"\t  CheckHostIP no\n"
"\t  Protocol 2\n"
"\t  ProxyCommand nc 127.0.0.1 22\n");
    kill (getppid(), SIGALRM);
    return 1;
  }
  if (0 != sleep (1))
  {
    /* sleep interrupted, likely SIGALRM, failure to
       launch child, terminate */
    printf (""
"Please ensure you have ssh installed and have sshd installed and running :\n"
"\tsudo apt-get install openssh-client openssh-server\n"
"If you run Tor as a network proxy then Tor might prevent ssh from connecting\n"
"to localhost.  Please either run  make check  from an unproxied user, or else\n"
"add these lines to the beginning of your ~/.ssh/config file :"
"\tHost 127.0.0.1 localhost\n"
"\t  CheckHostIP no\n"
"\t  Protocol 2\n"
"\t  ProxyCommand nc 127.0.0.1 22\n");
    return 77;
  }
  /* check if child exec()ed but died */
  if (0 != waitpid (pid, &status, WNOHANG))
  {
    printf (""
"If you run Tor as a network proxy then Tor might prevent ssh from connecting\n"
"to localhost.  Please either run  make check  from an unproxied user, or else\n"
"add these lines to the beginning of your ~/.ssh/config file :"
"\tHost 127.0.0.1 localhost\n"
"\t  CheckHostIP no\n"
"\t  Protocol 2\n"
"\t  ProxyCommand nc 127.0.0.1 22\n");
    return 77;
  }

  cfg = GNUNET_CONFIGURATION_create ();
  GNUNET_CONFIGURATION_set_value_string (cfg, MYNAME, "SOCKSHOST", "127.0.0.1");
  GNUNET_CONFIGURATION_set_value_string (cfg, MYNAME, "SOCKSPORT", socksport);
  GNUNET_CONFIGURATION_set_value_number (cfg, MYNAME, "PORT", PORT);
  GNUNET_CONFIGURATION_set_value_string (cfg, MYNAME, "HOSTNAME", "127.0.0.1");
  ok = 1;
  GNUNET_SCHEDULER_run (&task, &ok);
  GNUNET_CONFIGURATION_destroy (cfg);

  GNUNET_break (0 == kill (pid, SIGTERM));
  GNUNET_break (pid == waitpid (pid, &status, 0));
  return ok;
}
Example #10
0
/**
 * Run the next phase of the auto test.
 */
static void
next_phase (struct GNUNET_NAT_AutoHandle *ah)
{
  struct GNUNET_CONFIGURATION_Handle *diff;

  ah->phase++;
  switch (ah->phase)
  {
  case AUTO_INIT:
    GNUNET_assert (0);
    break;
  case AUTO_EXTERNAL_IP:
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Will run AUTO_EXTERNAL_IP\n");
    test_external_ip (ah);
    break;
  case AUTO_STUN:
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Will run AUTO_STUN\n");
    test_stun (ah);
    break;
  case AUTO_LOCAL_IP:
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Will run AUTO_LOCAL_IP\n");
    test_local_ip (ah);
    break;
  case AUTO_NAT_PUNCHED:
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Will run AUTO_NAT_PUNCHED\n");
    test_nat_punched (ah);
    break;
  case AUTO_UPNPC:
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Will run AUTO_UPNPC\n");
    test_upnpc (ah);
    break;
  case AUTO_ICMP_SERVER:
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Will run AUTO_ICMP_SERVER\n");
    test_icmp_server (ah);
    break;
  case AUTO_ICMP_CLIENT:
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Will run AUTO_ICMP_CLIENT\n");
    test_icmp_client (ah);
    break;
  case AUTO_DONE:
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Done with tests\n");
    if (!ah->internal_ip_is_public)
    {
      GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "BEHIND_NAT", "YES");

      if (ah->connected_back)
      {
        GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "PUNCHED_NAT", "YES");
      }
      else
      {
        GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "PUNCHED_NAT", "NO");
      }

      if (ah->stun_ip)
      {
        GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "EXTERNAL_ADDRESS",
                                               ah->stun_ip);
        if (ah->connected_back)
        {
          ah->type = GNUNET_NAT_TYPE_STUN_PUNCHED_NAT;
          GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "USE_STUN", "YES");
        }
        else
        {
          ah->type = GNUNET_NAT_TYPE_UNREACHABLE_NAT;
          GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "USE_STUN", "NO");
        }

      }
      if (ah->stun_port)
      {
        GNUNET_CONFIGURATION_set_value_number (ah->cfg, "transport-udp",
                                               "ADVERTISED_PORT",
                                               ah->stun_port);
      }

    }
    else
    {
      //The internal IP is the same as public, but we didn't got a incoming connection
      if (ah->connected_back)
      {
        ah->type = GNUNET_NAT_TYPE_NO_NAT;
        GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "BEHIND_NAT", "NO");
      }
      else
      {
        GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "BEHIND_NAT", "YES");
        ah->type = GNUNET_NAT_TYPE_UNREACHABLE_NAT;
        if (ah->stun_ip)
        {
          GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "EXTERNAL_ADDRESS",
                                                 ah->stun_ip);
        }
        if (ah->stun_port)
        {
          GNUNET_CONFIGURATION_set_value_number (ah->cfg, "transport-udp",
                                                 "ADVERTISED_PORT",
                                                 ah->stun_port);

        }
      }
    }

    diff = GNUNET_CONFIGURATION_get_diff (ah->initial_cfg,
                                          ah->cfg);


    ah->fin_cb (ah->fin_cb_cls,
                diff,
                ah->ret,
                ah->type);
    GNUNET_CONFIGURATION_destroy (diff);
    GNUNET_NAT_autoconfig_cancel (ah);
    return;

  }



}
Example #11
0
static int
testConfig ()
{
  char *c;
  unsigned long long l;

  if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "test", "b", &c))
    return 1;
  if (0 != strcmp ("b", c))
  {
    FPRINTF (stderr, "Got `%s'\n", c);
    GNUNET_free (c);
    return 2;
  }
  GNUNET_free (c);
  if (GNUNET_OK !=
      GNUNET_CONFIGURATION_get_value_number (cfg, "test", "five", &l))
  {
    GNUNET_break (0);
    return 3;
  }
  if (5 != l)
  {
    GNUNET_break (0);
    return 4;
  }
  GNUNET_CONFIGURATION_set_value_string (cfg, "more", "c", "YES");
  if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_yesno (cfg, "more", "c"))
  {
    GNUNET_break (0);
    return 5;
  }
  GNUNET_CONFIGURATION_set_value_number (cfg, "NUMBERS", "TEN", 10);
  if (GNUNET_OK !=
      GNUNET_CONFIGURATION_get_value_string (cfg, "NUMBERS", "TEN", &c))
  {
    GNUNET_break (0);
    return 6;
  }
  if (0 != strcmp (c, "10"))
  {
    GNUNET_free (c);
    GNUNET_break (0);
    return 7;
  }
  GNUNET_free (c);

  if (GNUNET_OK !=
      GNUNET_CONFIGURATION_get_value_filename (cfg, "last", "test", &c))
  {
    GNUNET_break (0);
    return 8;
  }
#ifndef MINGW
  if (0 != strcmp (c, "/hello/world"))
#else
#define HI "\\hello\\world"
  if (strstr (c, HI) != c + strlen (c) - strlen (HI))
#endif
  {
    GNUNET_break (0);
    GNUNET_free (c);
    return 9;
  }
  GNUNET_free (c);

  if (GNUNET_OK !=
      GNUNET_CONFIGURATION_get_value_size (cfg, "last", "size", &l))
  {
    GNUNET_break (0);
    return 10;
  }
  if (l != 512 * 1024)
  {
    GNUNET_break (0);
    return 11;
  }
  return 0;
}