aboutsummaryrefslogtreecommitdiff
path: root/src/util/connection.c
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-07-02 10:42:03 +0000
committerNathan S. Evans <evans@in.tum.de>2010-07-02 10:42:03 +0000
commitcf8b4a15709cb391397f9220729af97cf691a0f1 (patch)
tree64765330559f25c17130170010a872060cabc521 /src/util/connection.c
parent9c5ddb1541ff43030e99457e8ba090ab917399cc (diff)
downloadgnunet-cf8b4a15709cb391397f9220729af97cf691a0f1.tar.gz
gnunet-cf8b4a15709cb391397f9220729af97cf691a0f1.zip
reduce buffer size for all connections, and for mst processing
Diffstat (limited to 'src/util/connection.c')
-rw-r--r--src/util/connection.c53
1 files changed, 39 insertions, 14 deletions
diff --git a/src/util/connection.c b/src/util/connection.c
index 6c53bdef7..34c9fa62b 100644
--- a/src/util/connection.c
+++ b/src/util/connection.c
@@ -214,7 +214,12 @@ struct GNUNET_CONNECTION_Handle
214 char *write_buffer; 214 char *write_buffer;
215 215
216 /** 216 /**
217 * Size of our write buffer. 217 * Max size of our write buffer.
218 */
219 size_t max_write_buffer_size;
220
221 /**
222 * Current size of our write buffer.
218 */ 223 */
219 size_t write_buffer_size; 224 size_t write_buffer_size;
220 225
@@ -226,7 +231,7 @@ struct GNUNET_CONNECTION_Handle
226 231
227 /** 232 /**
228 * Current read-offset in write buffer (how many 233 * Current read-offset in write buffer (how many
229 * bytes have already been send). 234 * bytes have already been sent).
230 */ 235 */
231 size_t write_buffer_pos; 236 size_t write_buffer_pos;
232 237
@@ -325,10 +330,11 @@ GNUNET_CONNECTION_create_from_existing (struct GNUNET_SCHEDULER_Handle
325 *osSocket, size_t maxbuf) 330 *osSocket, size_t maxbuf)
326{ 331{
327 struct GNUNET_CONNECTION_Handle *ret; 332 struct GNUNET_CONNECTION_Handle *ret;
328 ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle) + maxbuf); 333 ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle));
329 ret->write_buffer = (char *) &ret[1];
330 GNUNET_assert (maxbuf < GNUNET_SERVER_MAX_MESSAGE_SIZE); 334 GNUNET_assert (maxbuf < GNUNET_SERVER_MAX_MESSAGE_SIZE);
331 ret->write_buffer_size = maxbuf; 335 ret->write_buffer_size = GNUNET_SERVER_MIN_BUFFER_SIZE;
336 ret->max_write_buffer_size = maxbuf;
337 ret->write_buffer = GNUNET_malloc(ret->write_buffer_size);
332 ret->sock = osSocket; 338 ret->sock = osSocket;
333 ret->sched = sched; 339 ret->sched = sched;
334 return ret; 340 return ret;
@@ -416,10 +422,12 @@ GNUNET_CONNECTION_create_from_accept (struct GNUNET_SCHEDULER_Handle
416 GNUNET_free (uaddr); 422 GNUNET_free (uaddr);
417 return NULL; 423 return NULL;
418 } 424 }
419 ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle) + maxbuf); 425 ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle));
420 ret->write_buffer = (char *) &ret[1]; 426
421 GNUNET_assert (maxbuf < GNUNET_SERVER_MAX_MESSAGE_SIZE); 427 GNUNET_assert (maxbuf < GNUNET_SERVER_MAX_MESSAGE_SIZE);
422 ret->write_buffer_size = maxbuf; 428 ret->write_buffer_size = GNUNET_SERVER_MIN_BUFFER_SIZE;
429 ret->max_write_buffer_size = maxbuf;
430 ret->write_buffer = GNUNET_malloc(ret->write_buffer_size);
423 ret->addr = uaddr; 431 ret->addr = uaddr;
424 ret->addrlen = addrlen; 432 ret->addrlen = addrlen;
425 ret->sock = sock; 433 ret->sock = sock;
@@ -588,6 +596,7 @@ transmit_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
588static void 596static void
589connect_fail_continuation (struct GNUNET_CONNECTION_Handle *h) 597connect_fail_continuation (struct GNUNET_CONNECTION_Handle *h)
590{ 598{
599#if DEBUG_CONNECTION
591 GNUNET_log ((0 != strncmp (h->hostname, 600 GNUNET_log ((0 != strncmp (h->hostname,
592 "localhost:", 601 "localhost:",
593 10)) 602 10))
@@ -595,6 +604,7 @@ connect_fail_continuation (struct GNUNET_CONNECTION_Handle *h)
595 : GNUNET_ERROR_TYPE_WARNING, 604 : GNUNET_ERROR_TYPE_WARNING,
596 _("Failed to establish TCP connection to `%s:%u', no further addresses to try.\n"), 605 _("Failed to establish TCP connection to `%s:%u', no further addresses to try.\n"),
597 h->hostname, h->port); 606 h->hostname, h->port);
607#endif
598 /* connect failed / timed out */ 608 /* connect failed / timed out */
599 GNUNET_break (h->ap_head == NULL); 609 GNUNET_break (h->ap_head == NULL);
600 GNUNET_break (h->ap_tail == NULL); 610 GNUNET_break (h->ap_tail == NULL);
@@ -819,9 +829,11 @@ try_connect_using_address (void *cls,
819 GNUNET_free (ap); 829 GNUNET_free (ap);
820 return; /* not supported by OS */ 830 return; /* not supported by OS */
821 } 831 }
832#if DEBUG_CONNECTION
822 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 833 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
823 _("Trying to connect to `%s' (%p)\n"), 834 _("Trying to connect to `%s' (%p)\n"),
824 GNUNET_a2s (ap->addr, ap->addrlen), h); 835 GNUNET_a2s (ap->addr, ap->addrlen), h);
836#endif
825 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (ap->sock, 837 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (ap->sock,
826 ap->addr, 838 ap->addr,
827 ap->addrlen)) && 839 ap->addrlen)) &&
@@ -872,12 +884,14 @@ GNUNET_CONNECTION_create_from_connect (struct GNUNET_SCHEDULER_Handle *sched,
872 struct GNUNET_CONNECTION_Handle *ret; 884 struct GNUNET_CONNECTION_Handle *ret;
873 885
874 GNUNET_assert (0 < strlen (hostname)); /* sanity check */ 886 GNUNET_assert (0 < strlen (hostname)); /* sanity check */
875 ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle) + maxbuf); 887 ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle));
876 ret->cfg = cfg; 888 ret->cfg = cfg;
877 ret->sched = sched; 889 ret->sched = sched;
878 ret->write_buffer = (char *) &ret[1]; 890
879 GNUNET_assert (maxbuf < GNUNET_SERVER_MAX_MESSAGE_SIZE); 891 GNUNET_assert (maxbuf < GNUNET_SERVER_MAX_MESSAGE_SIZE);
880 ret->write_buffer_size = maxbuf; 892 ret->write_buffer_size = GNUNET_SERVER_MIN_BUFFER_SIZE;
893 ret->max_write_buffer_size = maxbuf;
894 ret->write_buffer = GNUNET_malloc(ret->write_buffer_size);
881 ret->port = port; 895 ret->port = port;
882 ret->hostname = GNUNET_strdup (hostname); 896 ret->hostname = GNUNET_strdup (hostname);
883 ret->dns_active = GNUNET_RESOLVER_ip_get (sched, 897 ret->dns_active = GNUNET_RESOLVER_ip_get (sched,
@@ -929,12 +943,13 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (struct GNUNET_SCHEDULER_Handl
929 un->sun_path[0] = '\0'; 943 un->sun_path[0] = '\0';
930 slen = sizeof (struct sockaddr_un); 944 slen = sizeof (struct sockaddr_un);
931#endif 945#endif
932 ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle) + maxbuf); 946 ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle));
933 ret->cfg = cfg; 947 ret->cfg = cfg;
934 ret->sched = sched; 948 ret->sched = sched;
935 ret->write_buffer = (char *) &ret[1];
936 GNUNET_assert (maxbuf < GNUNET_SERVER_MAX_MESSAGE_SIZE); 949 GNUNET_assert (maxbuf < GNUNET_SERVER_MAX_MESSAGE_SIZE);
937 ret->write_buffer_size = maxbuf; 950 ret->write_buffer_size = GNUNET_SERVER_MIN_BUFFER_SIZE;
951 ret->max_write_buffer_size = maxbuf;
952 ret->write_buffer = GNUNET_malloc(ret->write_buffer_size);
938 ret->port = 0; 953 ret->port = 0;
939 ret->hostname = NULL; 954 ret->hostname = NULL;
940 ret->addr = (struct sockaddr*) un; 955 ret->addr = (struct sockaddr*) un;
@@ -1596,9 +1611,19 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle
1596 GNUNET_CONNECTION_TransmitReadyNotify 1611 GNUNET_CONNECTION_TransmitReadyNotify
1597 notify, void *notify_cls) 1612 notify, void *notify_cls)
1598{ 1613{
1614 size_t temp_size;
1599 if (sock->nth.notify_ready != NULL) 1615 if (sock->nth.notify_ready != NULL)
1600 return NULL; 1616 return NULL;
1601 GNUNET_assert (notify != NULL); 1617 GNUNET_assert (notify != NULL);
1618 if ((sock->write_buffer_size < size) && (size < sock->max_write_buffer_size))
1619 {
1620 temp_size = sock->write_buffer_size + size;
1621 if (temp_size > sock->max_write_buffer_size)
1622 temp_size = sock->max_write_buffer_size;
1623
1624 sock->write_buffer = GNUNET_realloc(sock->write_buffer, temp_size);
1625 sock->write_buffer_size = temp_size;
1626 }
1602 GNUNET_assert (sock->write_buffer_size >= size); 1627 GNUNET_assert (sock->write_buffer_size >= size);
1603 GNUNET_assert (sock->write_buffer_off <= sock->write_buffer_size); 1628 GNUNET_assert (sock->write_buffer_off <= sock->write_buffer_size);
1604 GNUNET_assert (sock->write_buffer_pos <= sock->write_buffer_size); 1629 GNUNET_assert (sock->write_buffer_pos <= sock->write_buffer_size);