diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2010-04-09 12:52:54 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2010-04-09 12:52:54 +0000 |
commit | c57ed076db3529c114dad3251a838e06b64f048a (patch) | |
tree | 243147b9a9a2f212b81ea54ab35f9a486fb5a78e /src | |
parent | d44413921e1537b91026db84d765bb23f07fad9b (diff) | |
download | gnunet-c57ed076db3529c114dad3251a838e06b64f048a.tar.gz gnunet-c57ed076db3529c114dad3251a838e06b64f048a.zip |
added code to build the advertisement message
Diffstat (limited to 'src')
-rw-r--r-- | src/hostlist/hostlist-server.c | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/src/hostlist/hostlist-server.c b/src/hostlist/hostlist-server.c index 65d5939c6..4ffcc27f4 100644 --- a/src/hostlist/hostlist-server.c +++ b/src/hostlist/hostlist-server.c | |||
@@ -110,9 +110,10 @@ update_response (void *cls, | |||
110 | * Function that assembles our hostlist adv message. | 110 | * Function that assembles our hostlist adv message. |
111 | */ | 111 | */ |
112 | static int | 112 | static int |
113 | create_hostlist_adv_message (void) | 113 | create_hostlist_adv_message (struct GNUNET_HOSTLIST_ADV_Message *adv_msg) |
114 | { | 114 | { |
115 | int length = 0; | 115 | int length = 0; |
116 | int size = 0; | ||
116 | unsigned long long port; | 117 | unsigned long long port; |
117 | 118 | ||
118 | char *uri; | 119 | char *uri; |
@@ -134,8 +135,8 @@ create_hostlist_adv_message (void) | |||
134 | 135 | ||
135 | sprintf(port_s, "%llu", port); | 136 | sprintf(port_s, "%llu", port); |
136 | length = strlen(hostname)+strlen(protocol)+strlen(port_s)+2; | 137 | length = strlen(hostname)+strlen(protocol)+strlen(port_s)+2; |
137 | 138 | size = (length+1) * sizeof (char); | |
138 | uri = GNUNET_malloc(length * sizeof(char)); | 139 | uri = GNUNET_malloc(size); |
139 | uri = strcpy(uri, protocol); | 140 | uri = strcpy(uri, protocol); |
140 | uri = strcat(uri, hostname); | 141 | uri = strcat(uri, hostname); |
141 | uri = strcat(uri, ":"); | 142 | uri = strcat(uri, ":"); |
@@ -144,6 +145,29 @@ create_hostlist_adv_message (void) | |||
144 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Address to obtain hostlist: %s\n", uri); | 145 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Address to obtain hostlist: %s\n", uri); |
145 | 146 | ||
146 | 147 | ||
148 | adv_msg = GNUNET_malloc ( sizeof(struct GNUNET_HOSTLIST_ADV_Message) + size); | ||
149 | if ( NULL == adv_msg) | ||
150 | { | ||
151 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | ||
152 | "Could not allocate memory for the message"); | ||
153 | return GNUNET_NO; | ||
154 | } | ||
155 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
156 | "size ADV_Message: %u\n",sizeof(struct GNUNET_HOSTLIST_ADV_Message)); | ||
157 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
158 | "size uri: %u\n", (length + 1) * sizeof (char)); | ||
159 | |||
160 | |||
161 | if ( ( size + sizeof( struct GNUNET_HOSTLIST_ADV_Message )) > GNUNET_SERVER_MAX_MESSAGE_SIZE) | ||
162 | { | ||
163 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | ||
164 | "Advertisement message is bigger than GNUNET allows"); | ||
165 | return GNUNET_NO; | ||
166 | } | ||
167 | |||
168 | adv_msg->header.type = htons (GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT); | ||
169 | adv_msg->header.size = htons (sizeof (struct GNUNET_HOSTLIST_ADV_Message) + size); | ||
170 | memcpy(&adv_msg[1],uri,size); | ||
147 | 171 | ||
148 | return GNUNET_OK; | 172 | return GNUNET_OK; |
149 | } | 173 | } |
@@ -409,8 +433,8 @@ connect_handler (void *cls, | |||
409 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 433 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
410 | "A new peer connected to the server, preparing to send hostlist advertisement\n"); | 434 | "A new peer connected to the server, preparing to send hostlist advertisement\n"); |
411 | /* create a new advertisement message */ | 435 | /* create a new advertisement message */ |
412 | struct GNUNET_HOSTLIST_ADV_Message *adv_msg = | 436 | struct GNUNET_HOSTLIST_ADV_Message *adv_msg; |
413 | create_hostlist_adv_message(); | 437 | create_hostlist_adv_message(adv_msg); |
414 | 438 | ||
415 | } | 439 | } |
416 | 440 | ||