diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-10-07 18:16:19 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-10-07 18:16:19 +0000 |
commit | 5f516f44aeb2777c7c11f6e79ad392559d898cc3 (patch) | |
tree | cece5b213a5c769bf6b72e4467a8ef6717fec2f9 /src/topology | |
parent | 91dfeebc1a2e840f88904aab7f43ce214c3eb03a (diff) | |
download | gnunet-5f516f44aeb2777c7c11f6e79ad392559d898cc3.tar.gz gnunet-5f516f44aeb2777c7c11f6e79ad392559d898cc3.zip |
implementing FRIENDS file writing logic
Diffstat (limited to 'src/topology')
-rw-r--r-- | src/topology/friends.c | 56 | ||||
-rw-r--r-- | src/topology/gnunet-daemon-topology.c | 2 |
2 files changed, 54 insertions, 4 deletions
diff --git a/src/topology/friends.c b/src/topology/friends.c index c0915fa15..d12d711d3 100644 --- a/src/topology/friends.c +++ b/src/topology/friends.c | |||
@@ -117,6 +117,10 @@ GNUNET_FRIENDS_parse (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
117 | */ | 117 | */ |
118 | struct GNUNET_FRIENDS_Writer | 118 | struct GNUNET_FRIENDS_Writer |
119 | { | 119 | { |
120 | /** | ||
121 | * Handle to the file. | ||
122 | */ | ||
123 | struct GNUNET_DISK_FileHandle *fh; | ||
120 | }; | 124 | }; |
121 | 125 | ||
122 | 126 | ||
@@ -130,7 +134,30 @@ struct GNUNET_FRIENDS_Writer | |||
130 | struct GNUNET_FRIENDS_Writer * | 134 | struct GNUNET_FRIENDS_Writer * |
131 | GNUNET_FRIENDS_write_start (const struct GNUNET_CONFIGURATION_Handle *cfg) | 135 | GNUNET_FRIENDS_write_start (const struct GNUNET_CONFIGURATION_Handle *cfg) |
132 | { | 136 | { |
133 | return NULL; | 137 | struct GNUNET_FRIENDS_Writer *w; |
138 | char *fn; | ||
139 | |||
140 | if (GNUNET_OK != | ||
141 | GNUNET_CONFIGURATION_get_value_filename (cfg, "TOPOLOGY", "FRIENDS", &fn)) | ||
142 | { | ||
143 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | ||
144 | "topology", "FRIENDS"); | ||
145 | return NULL; | ||
146 | } | ||
147 | if (GNUNET_OK == GNUNET_DISK_file_test (fn)) | ||
148 | GNUNET_DISK_file_backup (fn); | ||
149 | w = GNUNET_new (struct GNUNET_FRIENDS_Writer); | ||
150 | w->fh = GNUNET_DISK_file_open (fn, | ||
151 | GNUNET_DISK_OPEN_CREATE | | ||
152 | GNUNET_DISK_OPEN_WRITE | | ||
153 | GNUNET_DISK_OPEN_FAILIFEXISTS, | ||
154 | GNUNET_DISK_PERM_USER_READ); | ||
155 | if (NULL == w->fh) | ||
156 | { | ||
157 | GNUNET_free (w); | ||
158 | return NULL; | ||
159 | } | ||
160 | return w; | ||
134 | } | 161 | } |
135 | 162 | ||
136 | 163 | ||
@@ -143,7 +170,11 @@ GNUNET_FRIENDS_write_start (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
143 | int | 170 | int |
144 | GNUNET_FRIENDS_write_stop (struct GNUNET_FRIENDS_Writer *w) | 171 | GNUNET_FRIENDS_write_stop (struct GNUNET_FRIENDS_Writer *w) |
145 | { | 172 | { |
146 | return GNUNET_SYSERR; | 173 | int ret; |
174 | |||
175 | ret = GNUNET_DISK_file_close (w->fh); | ||
176 | GNUNET_free (w); | ||
177 | return ret; | ||
147 | } | 178 | } |
148 | 179 | ||
149 | 180 | ||
@@ -158,7 +189,26 @@ int | |||
158 | GNUNET_FRIENDS_write (struct GNUNET_FRIENDS_Writer *w, | 189 | GNUNET_FRIENDS_write (struct GNUNET_FRIENDS_Writer *w, |
159 | const struct GNUNET_PeerIdentity *friend) | 190 | const struct GNUNET_PeerIdentity *friend) |
160 | { | 191 | { |
161 | return GNUNET_SYSERR; | 192 | char *buf; |
193 | char *ret; | ||
194 | size_t slen; | ||
195 | |||
196 | ret = GNUNET_CRYPTO_ecc_public_sign_key_to_string (&friend->public_key); | ||
197 | GNUNET_asprintf (&buf, | ||
198 | "%s\n", | ||
199 | ret); | ||
200 | GNUNET_free (ret); | ||
201 | slen = strlen (buf); | ||
202 | if (slen != | ||
203 | GNUNET_DISK_file_write (w->fh, | ||
204 | buf, | ||
205 | slen)) | ||
206 | { | ||
207 | GNUNET_free (buf); | ||
208 | return GNUNET_SYSERR; | ||
209 | } | ||
210 | GNUNET_free (buf); | ||
211 | return GNUNET_OK; | ||
162 | } | 212 | } |
163 | 213 | ||
164 | 214 | ||
diff --git a/src/topology/gnunet-daemon-topology.c b/src/topology/gnunet-daemon-topology.c index 051dccf50..7e21d882b 100644 --- a/src/topology/gnunet-daemon-topology.c +++ b/src/topology/gnunet-daemon-topology.c | |||
@@ -1019,7 +1019,7 @@ handle_friend (void *cls, | |||
1019 | { | 1019 | { |
1020 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1020 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1021 | _("Found myself `%s' in friend list (useless, ignored)\n"), | 1021 | _("Found myself `%s' in friend list (useless, ignored)\n"), |
1022 | GNUNET_i2s (&pid)); | 1022 | GNUNET_i2s (pid)); |
1023 | return; | 1023 | return; |
1024 | } | 1024 | } |
1025 | (*entries_found)++; | 1025 | (*entries_found)++; |