aboutsummaryrefslogtreecommitdiff
path: root/src/topology
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-10-07 18:16:19 +0000
committerChristian Grothoff <christian@grothoff.org>2013-10-07 18:16:19 +0000
commit5f516f44aeb2777c7c11f6e79ad392559d898cc3 (patch)
treecece5b213a5c769bf6b72e4467a8ef6717fec2f9 /src/topology
parent91dfeebc1a2e840f88904aab7f43ce214c3eb03a (diff)
implementing FRIENDS file writing logic
Diffstat (limited to 'src/topology')
-rw-r--r--src/topology/friends.c56
-rw-r--r--src/topology/gnunet-daemon-topology.c2
2 files changed, 54 insertions, 4 deletions
diff --git a/src/topology/friends.c b/src/topology/friends.c
index c0915fa153..d12d711d37 100644
--- a/src/topology/friends.c
+++ b/src/topology/friends.c
@@ -117,6 +117,10 @@ GNUNET_FRIENDS_parse (const struct GNUNET_CONFIGURATION_Handle *cfg,
*/
struct GNUNET_FRIENDS_Writer
{
+ /**
+ * Handle to the file.
+ */
+ struct GNUNET_DISK_FileHandle *fh;
};
@@ -130,7 +134,30 @@ struct GNUNET_FRIENDS_Writer
struct GNUNET_FRIENDS_Writer *
GNUNET_FRIENDS_write_start (const struct GNUNET_CONFIGURATION_Handle *cfg)
{
- return NULL;
+ struct GNUNET_FRIENDS_Writer *w;
+ char *fn;
+
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_filename (cfg, "TOPOLOGY", "FRIENDS", &fn))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "topology", "FRIENDS");
+ return NULL;
+ }
+ if (GNUNET_OK == GNUNET_DISK_file_test (fn))
+ GNUNET_DISK_file_backup (fn);
+ w = GNUNET_new (struct GNUNET_FRIENDS_Writer);
+ w->fh = GNUNET_DISK_file_open (fn,
+ GNUNET_DISK_OPEN_CREATE |
+ GNUNET_DISK_OPEN_WRITE |
+ GNUNET_DISK_OPEN_FAILIFEXISTS,
+ GNUNET_DISK_PERM_USER_READ);
+ if (NULL == w->fh)
+ {
+ GNUNET_free (w);
+ return NULL;
+ }
+ return w;
}
@@ -143,7 +170,11 @@ GNUNET_FRIENDS_write_start (const struct GNUNET_CONFIGURATION_Handle *cfg)
int
GNUNET_FRIENDS_write_stop (struct GNUNET_FRIENDS_Writer *w)
{
- return GNUNET_SYSERR;
+ int ret;
+
+ ret = GNUNET_DISK_file_close (w->fh);
+ GNUNET_free (w);
+ return ret;
}
@@ -158,7 +189,26 @@ int
GNUNET_FRIENDS_write (struct GNUNET_FRIENDS_Writer *w,
const struct GNUNET_PeerIdentity *friend)
{
- return GNUNET_SYSERR;
+ char *buf;
+ char *ret;
+ size_t slen;
+
+ ret = GNUNET_CRYPTO_ecc_public_sign_key_to_string (&friend->public_key);
+ GNUNET_asprintf (&buf,
+ "%s\n",
+ ret);
+ GNUNET_free (ret);
+ slen = strlen (buf);
+ if (slen !=
+ GNUNET_DISK_file_write (w->fh,
+ buf,
+ slen))
+ {
+ GNUNET_free (buf);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_free (buf);
+ return GNUNET_OK;
}
diff --git a/src/topology/gnunet-daemon-topology.c b/src/topology/gnunet-daemon-topology.c
index 051dccf50c..7e21d882b9 100644
--- a/src/topology/gnunet-daemon-topology.c
+++ b/src/topology/gnunet-daemon-topology.c
@@ -1019,7 +1019,7 @@ handle_friend (void *cls,
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
_("Found myself `%s' in friend list (useless, ignored)\n"),
- GNUNET_i2s (&pid));
+ GNUNET_i2s (pid));
return;
}
(*entries_found)++;