- _("Option `%s' in section `%s' not specified!\n"),
- "FRIENDS",
- "TOPOLOGY");
- return;
- }
- if (GNUNET_OK != GNUNET_DISK_file_test (fn))
- GNUNET_DISK_fn_write (fn, NULL, 0,
- GNUNET_DISK_PERM_USER_READ
- | GNUNET_DISK_PERM_USER_WRITE);
- if (0 != STAT (fn, &frstat))
- {
- if ((friends_only) || (minimum_friend_count > 0))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not read friends list `%s'\n"), fn);
- GNUNET_free (fn);
- return;
- }
- if (frstat.st_size == 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Friends file `%s' is empty.\n"),
- fn);
- GNUNET_free (fn);
- return;
- }
- data = GNUNET_malloc_large (frstat.st_size);
- if (data == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to read friends list from `%s': out of memory\n"), fn);
- GNUNET_free (fn);
- return;
- }
- if (frstat.st_size !=
- GNUNET_DISK_fn_read (fn, data, frstat.st_size))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to read friends list from `%s'\n"), fn);
- GNUNET_free (fn);
- GNUNET_free (data);
- return;
- }
- entries_found = 0;
- pos = 0;
- while ((pos < frstat.st_size) && isspace ( (unsigned char) data[pos]))
- pos++;
- while ((frstat.st_size >= sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) &&
- (pos <= frstat.st_size - sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)))
- {
- memcpy (&enc, &data[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
- if (!isspace ( (unsigned char) enc.encoding[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1]))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Syntax error in topology specification at offset %llu, skipping bytes.\n"),
- (unsigned long long) pos);
- pos++;
- while ((pos < frstat.st_size) && (!isspace ( (unsigned char) data[pos])))
- pos++;
- continue;
- }
- enc.encoding[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
- if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((char *) &enc, &pid.hashPubKey))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Syntax error in topology specification at offset %llu, skipping bytes `%s'.\n"),
- (unsigned long long) pos,
- &enc);
- }
- else
- {
- if (0 != memcmp (&pid,
- &my_identity,
- sizeof (struct GNUNET_PeerIdentity)))
- {
- entries_found++;
- fl = make_peer (&pid,
- NULL,
- GNUNET_YES);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Found friend `%s' in configuration\n"),
- GNUNET_i2s (&fl->pid));
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Found myself `%s' in friend list (useless, ignored)\n"),
- GNUNET_i2s (&pid));
- }
- }
- pos = pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded);
- while ((pos < frstat.st_size) && isspace ( (unsigned char) data[pos]))
- pos++;
- }
- GNUNET_free (data);
- GNUNET_free (fn);