summaryrefslogtreecommitdiff
path: root/src/hello/gnunet-hello.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/hello/gnunet-hello.c')
-rw-r--r--src/hello/gnunet-hello.c124
1 files changed, 56 insertions, 68 deletions
diff --git a/src/hello/gnunet-hello.c b/src/hello/gnunet-hello.c
index 0b176ac79..612b5110a 100644
--- a/src/hello/gnunet-hello.c
+++ b/src/hello/gnunet-hello.c
@@ -67,13 +67,13 @@ add_to_buf (void *cls,
67 size_t ret; 67 size_t ret;
68 68
69 ret = GNUNET_HELLO_add_address (address, 69 ret = GNUNET_HELLO_add_address (address,
70 GNUNET_TIME_UNIT_FOREVER_ABS, 70 GNUNET_TIME_UNIT_FOREVER_ABS,
71 ac->buf, 71 ac->buf,
72 ac->max); 72 ac->max);
73 ac->buf += ret; 73 ac->buf += ret;
74 ac->max -= ret; 74 ac->max -= ret;
75 ac->ret += ret; 75 ac->ret += ret;
76 address_count ++; 76 address_count++;
77 return GNUNET_OK; 77 return GNUNET_OK;
78} 78}
79 79
@@ -87,9 +87,7 @@ add_to_buf (void *cls,
87 * @return number of bytes added, 0 to terminate 87 * @return number of bytes added, 0 to terminate
88 */ 88 */
89static ssize_t 89static ssize_t
90add_from_hello (void *cls, 90add_from_hello (void *cls, size_t max, void *buf)
91 size_t max,
92 void *buf)
93{ 91{
94 struct GNUNET_HELLO_Message **orig = cls; 92 struct GNUNET_HELLO_Message **orig = cls;
95 struct AddContext ac; 93 struct AddContext ac;
@@ -99,10 +97,9 @@ add_from_hello (void *cls,
99 ac.buf = buf; 97 ac.buf = buf;
100 ac.max = max; 98 ac.max = max;
101 ac.ret = 0; 99 ac.ret = 0;
102 GNUNET_assert (NULL == 100 GNUNET_assert (
103 GNUNET_HELLO_iterate_addresses (*orig, 101 NULL ==
104 GNUNET_NO, &add_to_buf, 102 GNUNET_HELLO_iterate_addresses (*orig, GNUNET_NO, &add_to_buf, &ac));
105 &ac));
106 *orig = NULL; 103 *orig = NULL;
107 return ac.ret; 104 return ac.ret;
108} 105}
@@ -121,67 +118,58 @@ main (int argc, char *argv[])
121 GNUNET_log_setup ("gnunet-hello", "INFO", NULL); 118 GNUNET_log_setup ("gnunet-hello", "INFO", NULL);
122 if (argc != 2) 119 if (argc != 2)
123 { 120 {
124 FPRINTF (stderr, 121 fprintf (stderr, "%s", _ ("Call with name of HELLO file to modify.\n"));
125 "%s",
126 _("Call with name of HELLO file to modify.\n"));
127 return 1; 122 return 1;
128 } 123 }
129 if (GNUNET_OK != GNUNET_DISK_file_size (argv[1], &fsize, GNUNET_YES, GNUNET_YES)) 124 if (GNUNET_OK !=
125 GNUNET_DISK_file_size (argv[1], &fsize, GNUNET_YES, GNUNET_YES))
130 { 126 {
131 FPRINTF (stderr, 127 fprintf (stderr,
132 _("Error accessing file `%s': %s\n"), 128 _ ("Error accessing file `%s': %s\n"),
133 argv[1], 129 argv[1],
134 STRERROR (errno)); 130 strerror (errno));
135 return 1; 131 return 1;
136 } 132 }
137 if (fsize > 65536) 133 if (fsize > 65536)
138 { 134 {
139 FPRINTF (stderr, 135 fprintf (stderr, _ ("File `%s' is too big to be a HELLO\n"), argv[1]);
140 _("File `%s' is too big to be a HELLO\n"),
141 argv[1]);
142 return 1; 136 return 1;
143 } 137 }
144 if (fsize < sizeof (struct GNUNET_MessageHeader)) 138 if (fsize < sizeof (struct GNUNET_MessageHeader))
145 { 139 {
146 FPRINTF (stderr, 140 fprintf (stderr, _ ("File `%s' is too small to be a HELLO\n"), argv[1]);
147 _("File `%s' is too small to be a HELLO\n"),
148 argv[1]);
149 return 1; 141 return 1;
150 } 142 }
151 fh = GNUNET_DISK_file_open (argv[1], 143 fh = GNUNET_DISK_file_open (argv[1],
152 GNUNET_DISK_OPEN_READ, 144 GNUNET_DISK_OPEN_READ,
153 GNUNET_DISK_PERM_USER_READ); 145 GNUNET_DISK_PERM_USER_READ);
154 if (NULL == fh) 146 if (NULL == fh)
155 { 147 {
156 FPRINTF (stderr, 148 fprintf (stderr,
157 _("Error opening file `%s': %s\n"), 149 _ ("Error opening file `%s': %s\n"),
158 argv[1], 150 argv[1],
159 STRERROR (errno)); 151 strerror (errno));
160 return 1; 152 return 1;
161 } 153 }
162 { 154 {
163 char buf[fsize] GNUNET_ALIGN; 155 char buf[fsize] GNUNET_ALIGN;
164 156
165 GNUNET_assert (fsize == 157 GNUNET_assert (fsize == GNUNET_DISK_file_read (fh, buf, fsize));
166 GNUNET_DISK_file_read (fh, buf, fsize));
167 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); 158 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh));
168 orig = (struct GNUNET_HELLO_Message *) buf; 159 orig = (struct GNUNET_HELLO_Message *) buf;
169 if ( (fsize < GNUNET_HELLO_size (orig)) || 160 if ((fsize < GNUNET_HELLO_size (orig)) ||
170 (GNUNET_OK != GNUNET_HELLO_get_id (orig, 161 (GNUNET_OK != GNUNET_HELLO_get_id (orig, &pid)))
171 &pid)) )
172 { 162 {
173 FPRINTF (stderr, 163 fprintf (stderr,
174 _("Did not find well-formed HELLO in file `%s'\n"), 164 _ ("Did not find well-formed HELLO in file `%s'\n"),
175 argv[1]); 165 argv[1]);
176 return 1; 166 return 1;
177 } 167 }
178 { 168 {
179 char *pids; 169 char *pids;
180 170
181 pids = GNUNET_CRYPTO_eddsa_public_key_to_string (&pid.public_key); 171 pids = GNUNET_CRYPTO_eddsa_public_key_to_string (&pid.public_key);
182 fprintf (stdout, 172 fprintf (stdout, "Processing HELLO for peer `%s'\n", pids);
183 "Processing HELLO for peer `%s'\n",
184 pids);
185 GNUNET_free (pids); 173 GNUNET_free (pids);
186 } 174 }
187 result = GNUNET_HELLO_create (&pid.public_key, 175 result = GNUNET_HELLO_create (&pid.public_key,
@@ -189,34 +177,34 @@ main (int argc, char *argv[])
189 &orig, 177 &orig,
190 GNUNET_HELLO_is_friend_only (orig)); 178 GNUNET_HELLO_is_friend_only (orig));
191 GNUNET_assert (NULL != result); 179 GNUNET_assert (NULL != result);
192 fh = GNUNET_DISK_file_open (argv[1], 180 fh =
193 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE, 181 GNUNET_DISK_file_open (argv[1],
194 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); 182 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE,
195 if (NULL == fh) 183 GNUNET_DISK_PERM_USER_READ |
196 { 184 GNUNET_DISK_PERM_USER_WRITE);
197 FPRINTF (stderr, 185 if (NULL == fh)
198 _("Error opening file `%s': %s\n"), 186 {
199 argv[1], 187 fprintf (stderr,
200 STRERROR (errno)); 188 _ ("Error opening file `%s': %s\n"),
201 GNUNET_free (result); 189 argv[1],
202 return 1; 190 strerror (errno));
203 } 191 GNUNET_free (result);
204 fsize = GNUNET_HELLO_size (result); 192 return 1;
205 if (fsize != GNUNET_DISK_file_write (fh, 193 }
206 result, 194 fsize = GNUNET_HELLO_size (result);
207 fsize)) 195 if (fsize != GNUNET_DISK_file_write (fh, result, fsize))
208 { 196 {
209 FPRINTF (stderr, 197 fprintf (stderr,
210 _("Error writing HELLO to file `%s': %s\n"), 198 _ ("Error writing HELLO to file `%s': %s\n"),
211 argv[1], 199 argv[1],
212 STRERROR (errno)); 200 strerror (errno));
213 (void) GNUNET_DISK_file_close (fh); 201 (void) GNUNET_DISK_file_close (fh);
214 return 1; 202 return 1;
215 } 203 }
216 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); 204 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh));
217 } 205 }
218 FPRINTF (stderr, 206 fprintf (stderr,
219 _("Modified %u addresses, wrote %u bytes\n"), 207 _ ("Modified %u addresses, wrote %u bytes\n"),
220 address_count, 208 address_count,
221 (unsigned int) fsize); 209 (unsigned int) fsize);
222 return 0; 210 return 0;