コード例 #1
0
ファイル: flooding.c プロジェクト: cschramm/gnunet-search
/**
 * @brief This function is the GNUnet iteration handler called while iterating the connected peers.
 *
 * \latexonly \\ \\ \endlatexonly
 * \em Detailed \em description \n
 * This function is the GNUnet iteration handler called while iterating the connected peers. It is used to flood data to all known peers.
 *
 * @param cls the GNUnet closure; it contains a reference to a data structure (see above) containing a parameters needed to send data to the current peer.
 * @param peer the peer of the current iteration
 * @param atsi a reference to the GNUnet ATS information (not used)
 * @param atsi_count the length of the ATS information (not used)
 */
static void gnunet_search_flooding_peer_iterate_handler(void *cls, const struct GNUNET_PeerIdentity *peer,
		const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) {
	if(!peer) {
//		printf("Iterating done...\n");
		struct gnunet_search_flooding_data_flood_parameters *parameters =
				(struct gnunet_search_flooding_data_flood_parameters*) cls;
		GNUNET_free(parameters->data);
		if(parameters->sender)
			GNUNET_free(parameters->sender);
		GNUNET_free(parameters);
		return;
	}
	struct gnunet_search_flooding_data_flood_parameters *parameters =
			(struct gnunet_search_flooding_data_flood_parameters*) cls;

	if(parameters->sender && !GNUNET_CRYPTO_hash_cmp(&parameters->sender->hashPubKey, &peer->hashPubKey)) {
//		printf("Skipping sender...\n");
		return;
	}

	struct GNUNET_CRYPTO_HashAsciiEncoded result;
	GNUNET_CRYPTO_hash_to_enc(&peer->hashPubKey, &result);
//	printf("Flooding message to peer %.*s...\n", 104, (char*) &result);

	gnunet_search_flooding_to_peer_message_send(peer, parameters->data, parameters->size);
}
コード例 #2
0
/**
 * Print the collected address information to the console and free 'pc'.
 *
 * @param pc printing context
 */
static void
dump_pc (struct PrintContext *pc)
{
  struct GNUNET_CRYPTO_HashAsciiEncoded enc;
  unsigned int i;

  GNUNET_CRYPTO_hash_to_enc (&pc->peer.hashPubKey, &enc);
  printf (_("Peer `%s'\n"), 
	  (const char *) &enc);
  for (i = 0; i < pc->num_addresses; i++)
  {
    if (NULL != pc->address_list[i].result)
    {
      printf ("\t%s\n", pc->address_list[i].result);
      GNUNET_free (pc->address_list[i].result);
    }
  }
  printf ("\n");
  GNUNET_free_non_null (pc->address_list);
  GNUNET_CONTAINER_DLL_remove (pc_head,
			       pc_tail,
			       pc);
  GNUNET_free (pc);
  if ( (NULL == pc_head) &&
       (NULL == pic) )
    tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);  
}
コード例 #3
0
/**
 * Main state machine that goes over all options and
 * runs the next requested function.
 *
 * @param cls unused
 * @param tc scheduler context
 */
static void
state_machine (void *cls,
	       const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  tt = GNUNET_SCHEDULER_NO_TASK;

  if (NULL != put_uri)
  {
    GPI_plugins_load (cfg);
    if (GNUNET_SYSERR == parse_hello_uri (put_uri))
      fprintf (stderr,
	       _("Invalid URI `%s'\n"),
	       put_uri);    
    GNUNET_free (put_uri);
    put_uri = NULL;
    return;
  }
  if (GNUNET_YES == get_info)
  {
    get_info = GNUNET_NO;
    GPI_plugins_load (cfg);
    pic = GNUNET_PEERINFO_iterate (peerinfo, NULL,
				   TIMEOUT,
				   &print_peer_info, NULL);
    return;
  }
  if (GNUNET_YES == get_self)
  {
    struct GNUNET_CRYPTO_HashAsciiEncoded enc;

    get_self = GNUNET_NO;
    GNUNET_CRYPTO_hash_to_enc (&my_peer_identity.hashPubKey, &enc);
    if (be_quiet)
      printf ("%s\n", (char *) &enc);
    else
      printf (_("I am peer `%s'.\n"), (const char *) &enc);
  }
  if (GNUNET_YES == get_uri)
  {
    struct GetUriContext *guc;
    char *pkey;

    guc = GNUNET_malloc (sizeof (struct GetUriContext));
    pkey = GNUNET_CRYPTO_rsa_public_key_to_string (&my_public_key);
    GNUNET_asprintf (&guc->uri,
		     "%s%s",
		     HELLO_URI_PREFIX,
		     pkey);
    GNUNET_free (pkey);
    GPI_plugins_load (cfg);
    pic = GNUNET_PEERINFO_iterate (peerinfo, &my_peer_identity,
				   TIMEOUT,
				   &print_my_uri, guc);
    get_uri = GNUNET_NO;
    return;
  }
  GNUNET_SCHEDULER_shutdown ();
}
コード例 #4
0
/**
 * Get the filename under which we would store the GNUNET_HELLO_Message
 * for the given host and protocol.
 *
 * @param id peer for which we need the filename for the HELLO
 * @return filename of the form DIRECTORY/HOSTID
 */
static char *
get_host_filename (const struct GNUNET_PeerIdentity *id)
{
  struct GNUNET_CRYPTO_HashAsciiEncoded fil;
  char *fn;

  GNUNET_CRYPTO_hash_to_enc (&id->hashPubKey, &fil);
  GNUNET_asprintf (&fn, "%s%s%s", networkIdDirectory, DIR_SEPARATOR_STR, &fil);
  return fn;
}
コード例 #5
0
/**
 * Callback for retrieving a list of connected peers.
 *
 * @param cls closure (unused)
 * @param peer peer identity this notification is about
 * @param atsi performance data for the connection
 * @param atsi_count number of records in 'atsi'
 */
static void
connected_peer_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
                         const struct GNUNET_ATS_Information *atsi,
                         unsigned int atsi_count)
{
  struct GNUNET_CRYPTO_HashAsciiEncoded enc;

  if (NULL == peer)
    return;
  GNUNET_CRYPTO_hash_to_enc (&peer->hashPubKey, &enc);
  printf (_("Peer `%s'\n"), (const char *) &enc);
}
コード例 #6
0
ファイル: gnunet-rsa.c プロジェクト: amatus/gnunet-debian
/**
 * Main function that will be run by the scheduler.
 *
 * @param cls closure
 * @param args remaining command-line arguments
 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
 * @param cfg configuration
 */
static void
run (void *cls, char *const *args, const char *cfgfile,
     const struct GNUNET_CONFIGURATION_Handle *cfg)
{
  struct GNUNET_CRYPTO_RsaPrivateKey *pk;
  struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub;
  struct GNUNET_PeerIdentity pid;

  if (NULL == args[0])
  {
    fprintf (stderr, _("No hostkey file specified on command line\n"));
    return;
  }
  if (0 != weak_random)    
    GNUNET_CRYPTO_random_disable_entropy_gathering ();  
  if (make_keys > 0)
  {
    create_keys (args[0]);
    return;
  }
  pk = GNUNET_CRYPTO_rsa_key_create_from_file (args[0]);
  if (NULL == pk)
    return;
  if (print_public_key)
  {
    char *s;

    GNUNET_CRYPTO_rsa_key_get_public (pk, &pub);
    s = GNUNET_CRYPTO_rsa_public_key_to_string (&pub);
    fprintf (stdout, "%s\n", s);
    GNUNET_free (s);
  }
  if (print_peer_identity)
  {
    struct GNUNET_CRYPTO_HashAsciiEncoded enc;

    GNUNET_CRYPTO_rsa_key_get_public (pk, &pub);
    GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey);
    GNUNET_CRYPTO_hash_to_enc (&pid.hashPubKey, &enc);
    fprintf (stdout, "%s\n", enc.encoding);
  }
  if (print_short_identity)
  {
    struct GNUNET_CRYPTO_ShortHashAsciiEncoded enc;
    struct GNUNET_CRYPTO_ShortHashCode sh;

    GNUNET_CRYPTO_rsa_key_get_public (pk, &pub);
    GNUNET_CRYPTO_short_hash (&pub, sizeof (pub), &sh);
    GNUNET_CRYPTO_short_hash_to_enc (&sh, &enc);
    fprintf (stdout, "%s\n", enc.short_encoding);
  }
  GNUNET_CRYPTO_rsa_key_free (pk);
}
コード例 #7
0
ファイル: pseudonym.c プロジェクト: amatus/gnunet-debian
/**
 * Get the filename (or directory name) for the given
 * pseudonym identifier and directory prefix.
 * @param cfg configuration to use
 * @param prefix path components to append to the private directory name
 * @param psid hash code of pseudonym, can be NULL
 * @return filename of the pseudonym (if psid != NULL) or directory with the data (if psid == NULL)
 */
static char *
get_data_filename (const struct GNUNET_CONFIGURATION_Handle *cfg,
                   const char *prefix, const struct GNUNET_HashCode * psid)
{
  struct GNUNET_CRYPTO_HashAsciiEncoded enc;

  if (psid != NULL)
    GNUNET_CRYPTO_hash_to_enc (psid, &enc);
  return GNUNET_DISK_get_home_filename (cfg, GNUNET_CLIENT_SERVICE_NAME, prefix,
                                        (psid ==
                                         NULL) ? NULL : (const char *) &enc,
                                        NULL);
}
コード例 #8
0
/**
 * Print information about the peer.
 * Currently prints the GNUNET_PeerIdentity and the transport address.
 *
 * @param cls the 'struct PrintContext'
 * @param peer identity of the peer 
 * @param hello addresses of the peer
 * @param err_msg error message
 */
static void
print_peer_info (void *cls, const struct GNUNET_PeerIdentity *peer,
                 const struct GNUNET_HELLO_Message *hello, const char *err_msg)
{
  struct GNUNET_CRYPTO_HashAsciiEncoded enc;
  struct PrintContext *pc;

  if (NULL == peer)
  {
    pic = NULL; /* end of iteration */
    if (NULL != err_msg)
    {
      FPRINTF (stderr, 
	       _("Error in communication with PEERINFO service: %s\n"),
	       err_msg);
    }
    if (NULL == pc_head)
      tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
    return;
  }
  if ((GNUNET_YES == be_quiet) || (NULL == hello))
  {
    GNUNET_CRYPTO_hash_to_enc (&peer->hashPubKey, &enc);
    printf ("%s\n", (const char *) &enc);
    return;
  }
  pc = GNUNET_malloc (sizeof (struct PrintContext));
  GNUNET_CONTAINER_DLL_insert (pc_head,
			       pc_tail, 
			       pc);
  pc->peer = *peer;
  GNUNET_HELLO_iterate_addresses (hello, 
				  GNUNET_NO, 
				  &count_address, 
				  pc);
  if (0 == pc->off)
  {
    dump_pc (pc);
    return;
  }
  pc->address_list_size = pc->off;
  pc->address_list = GNUNET_malloc (sizeof (struct AddressRecord) * pc->off);
  GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, 
				  &print_address, pc);
}
コード例 #9
0
ファイル: test_crypto_hash.c プロジェクト: muggenhor/GNUnet
static int
test (int number)
{
  struct GNUNET_HashCode h1;
  struct GNUNET_HashCode h2;
  struct GNUNET_CRYPTO_HashAsciiEncoded enc;

  memset (&h1, number, sizeof (struct GNUNET_HashCode));
  GNUNET_CRYPTO_hash_to_enc (&h1, &enc);
  if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((char *) &enc, &h2))
  {
    printf ("enc2hash failed!\n");
    return 1;
  }
  if (0 != memcmp (&h1, &h2, sizeof (struct GNUNET_HashCode)))
    return 1;
  return 0;
}
コード例 #10
0
ファイル: plugin_namecache_flat.c プロジェクト: tg-x/gnunet
/**
 * Store values in hashmap in file and free data
 *
 * @param plugin the plugin context
 */
static int
store_and_free_entries (void *cls,
                        const struct GNUNET_HashCode *key,
                        void *value)
{
  struct GNUNET_DISK_FileHandle *fh = cls;
  struct FlatFileEntry *entry = value;

  char *line;
  char *block_b64;
  struct GNUNET_CRYPTO_HashAsciiEncoded query;
  size_t block_size;

  block_size = ntohl (entry->block->purpose.size) +
    sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) +
    sizeof (struct GNUNET_CRYPTO_EcdsaSignature);

  GNUNET_STRINGS_base64_encode ((char*)entry->block,
                                block_size,
                                &block_b64);
  GNUNET_CRYPTO_hash_to_enc (&entry->query,
                             &query);
  GNUNET_asprintf (&line,
                   "%s,%s\n",
                   (char*)&query,
                   block_b64);

  GNUNET_free (block_b64);

  GNUNET_DISK_file_write (fh,
                          line,
                          strlen (line));

  GNUNET_free (entry->block);
  GNUNET_free (entry);
  return GNUNET_YES;
}
コード例 #11
0
/**
 * Convert the 'value' of a record to a string.
 *
 * @param type type of the record
 * @param data value in binary encoding
 * @param data_size number of bytes in data
 * @return NULL on error, otherwise human-readable representation of the value
 */
char *
GNUNET_NAMESTORE_value_to_string (uint32_t type,
				  const void *data,
				  size_t data_size)
{
  uint16_t mx_pref;
  const struct soa_data *soa;
  const struct vpn_data *vpn;
  const struct srv_data *srv;
  const struct tlsa_data *tlsa;
  struct GNUNET_CRYPTO_ShortHashAsciiEncoded enc;
  struct GNUNET_CRYPTO_HashAsciiEncoded s_peer;
  const char *cdata;
  char* vpn_str;
  char* srv_str;
  char* tlsa_str;
  char* result;
  const char* soa_rname;
  const char* soa_mname;
  char tmp[INET6_ADDRSTRLEN];

  switch (type)
  {
  case 0:
    return NULL;
  case GNUNET_DNSPARSER_TYPE_A:
    if (data_size != sizeof (struct in_addr))
      return NULL;
    if (NULL == inet_ntop (AF_INET, data, tmp, sizeof (tmp)))
      return NULL;
    return GNUNET_strdup (tmp);
  case GNUNET_DNSPARSER_TYPE_NS:
    return GNUNET_strndup (data, data_size);
  case GNUNET_DNSPARSER_TYPE_CNAME:
    return GNUNET_strndup (data, data_size);
  case GNUNET_DNSPARSER_TYPE_SOA:
    if (data_size <= sizeof (struct soa_data))
      return NULL;
    soa = data;
    soa_rname = (const char*) &soa[1];
    soa_mname = memchr (soa_rname, 0, data_size - sizeof (struct soa_data) - 1);
    if (NULL == soa_mname)
      return NULL;
    soa_mname++;
    if (NULL == memchr (soa_mname, 0, 
			data_size - (sizeof (struct soa_data) + strlen (soa_rname) + 1)))
      return NULL;
    GNUNET_asprintf (&result, 
		     "rname=%s mname=%s %lu,%lu,%lu,%lu,%lu",
		     soa_rname, soa_mname,
		     ntohl (soa->serial), 
		     ntohl (soa->refresh),
		     ntohl (soa->retry), 
		     ntohl (soa->expire),
		     ntohl (soa->minimum));
    return result;
  case GNUNET_DNSPARSER_TYPE_PTR:
    return GNUNET_strndup (data, data_size);
  case GNUNET_DNSPARSER_TYPE_MX:
    mx_pref = ntohs(*((uint16_t*)data));
    if (GNUNET_asprintf(&result, "%hu,%s", mx_pref, data+sizeof(uint16_t))
        != 0)
      return result;
    else
    {
      GNUNET_free (result);
      return NULL;
    }
  case GNUNET_DNSPARSER_TYPE_TXT:
    return GNUNET_strndup (data, data_size);
  case GNUNET_DNSPARSER_TYPE_AAAA:
    if (data_size != sizeof (struct in6_addr))
      return NULL;
    if (NULL == inet_ntop (AF_INET6, data, tmp, sizeof (tmp)))
      return NULL;
    return GNUNET_strdup (tmp);
  case GNUNET_NAMESTORE_TYPE_PKEY:
    if (data_size != sizeof (struct GNUNET_CRYPTO_ShortHashCode))
      return NULL;
    GNUNET_CRYPTO_short_hash_to_enc (data,
				     &enc);
    return GNUNET_strdup ((const char*) enc.short_encoding);
  case GNUNET_NAMESTORE_TYPE_PSEU:
    return GNUNET_strndup (data, data_size);
  case GNUNET_NAMESTORE_TYPE_LEHO:
    return GNUNET_strndup (data, data_size);
  case GNUNET_NAMESTORE_TYPE_VPN:
    cdata = data;
    if ( (data_size <= sizeof (struct vpn_data)) ||
	 ('\0' != cdata[data_size - 1]) )
      return NULL; /* malformed */
    vpn = data;
    GNUNET_CRYPTO_hash_to_enc (&vpn->peer, &s_peer);
    if (0 == GNUNET_asprintf (&vpn_str, "%u %s %s",
			      (unsigned int) ntohs (vpn->proto),
			      (const char*) &s_peer,
			      (const char*) &vpn[1]))
    {
      GNUNET_free (vpn_str);
      return NULL;
    }
    return vpn_str;
  case GNUNET_DNSPARSER_TYPE_SRV:
    cdata = data;
    if ( (data_size <= sizeof (struct srv_data)) ||
	 ('\0' != cdata[data_size - 1]) )
      return NULL; /* malformed */
    srv = data;

    if (0 == GNUNET_asprintf (&srv_str, 
			      "%d %d %d %s",
			      ntohs (srv->prio),
			      ntohs (srv->weight),
			      ntohs (srv->port),
			      (const char *)&srv[1]))
    {
      GNUNET_free (srv_str);
      return NULL;
    }
    return srv_str;
  case GNUNET_DNSPARSER_TYPE_TLSA:
    cdata = data;
    if ( (data_size <= sizeof (struct tlsa_data)) ||
	 ('\0' != cdata[data_size - 1]) )
      return NULL; /* malformed */
    tlsa = data;
    if (0 == GNUNET_asprintf (&tlsa_str, 
			      "%c %c %c %s",
			      tlsa->usage,
			      tlsa->selector,
			      tlsa->matching_type,
			      (const char *) &tlsa[1]))
    {
      GNUNET_free (tlsa_str);
      return NULL;
    }
    return tlsa_str;
  default:
    GNUNET_break (0);
  }
  GNUNET_break (0); // not implemented
  return NULL;
}