aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-communicator-unix.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-11-22 22:46:43 +0100
committerChristian Grothoff <christian@grothoff.org>2018-11-22 22:46:43 +0100
commitfbc5f3876a2ed52f18e2a2810e3cdda497cc99ea (patch)
treed01a9a8f202dd53a6ff6901c190d4d7031da1baa /src/transport/gnunet-communicator-unix.c
parentc87f73a07df468eccedbe1fdfa82bdd5b633a0d5 (diff)
downloadgnunet-fbc5f3876a2ed52f18e2a2810e3cdda497cc99ea.tar.gz
gnunet-fbc5f3876a2ed52f18e2a2810e3cdda497cc99ea.zip
add design sketch for new ATS API
Diffstat (limited to 'src/transport/gnunet-communicator-unix.c')
-rw-r--r--src/transport/gnunet-communicator-unix.c44
1 files changed, 23 insertions, 21 deletions
diff --git a/src/transport/gnunet-communicator-unix.c b/src/transport/gnunet-communicator-unix.c
index a9a75f779..a97560ad4 100644
--- a/src/transport/gnunet-communicator-unix.c
+++ b/src/transport/gnunet-communicator-unix.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/ 17*/
@@ -31,8 +31,8 @@
31#include "gnunet_transport_communication_service.h" 31#include "gnunet_transport_communication_service.h"
32 32
33/** 33/**
34 * How many messages do we keep at most in the queue to the 34 * How many messages do we keep at most in the queue to the
35 * transport service before we start to drop (default, 35 * transport service before we start to drop (default,
36 * can be changed via the configuration file). 36 * can be changed via the configuration file).
37 * Should be _below_ the level of the communicator API, as 37 * Should be _below_ the level of the communicator API, as
38 * otherwise we may read messages just to have them dropped 38 * otherwise we may read messages just to have them dropped
@@ -113,17 +113,17 @@ struct Queue
113 * if this queue is in the #queue_head DLL. 113 * if this queue is in the #queue_head DLL.
114 */ 114 */
115 const struct GNUNET_MessageHeader *msg; 115 const struct GNUNET_MessageHeader *msg;
116 116
117 /** 117 /**
118 * Message queue we are providing for the #ch. 118 * Message queue we are providing for the #ch.
119 */ 119 */
120 struct GNUNET_MQ_Handle *mq; 120 struct GNUNET_MQ_Handle *mq;
121 121
122 /** 122 /**
123 * handle for this queue with the #ch. 123 * handle for this queue with the #ch.
124 */ 124 */
125 struct GNUNET_TRANSPORT_QueueHandle *qh; 125 struct GNUNET_TRANSPORT_QueueHandle *qh;
126 126
127 /** 127 /**
128 * Number of bytes we currently have in our write queue. 128 * Number of bytes we currently have in our write queue.
129 */ 129 */
@@ -211,14 +211,14 @@ queue_destroy (struct Queue *queue)
211 struct GNUNET_MQ_Handle *mq; 211 struct GNUNET_MQ_Handle *mq;
212 212
213 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 213 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
214 "Disconnecting queue for peer `%s'\n", 214 "Disconnecting queue for peer `%s'\n",
215 GNUNET_i2s (&queue->target)); 215 GNUNET_i2s (&queue->target));
216 if (0 != queue->bytes_in_queue) 216 if (0 != queue->bytes_in_queue)
217 { 217 {
218 GNUNET_CONTAINER_DLL_remove (queue_head, 218 GNUNET_CONTAINER_DLL_remove (queue_head,
219 queue_tail, 219 queue_tail,
220 queue); 220 queue);
221 queue->bytes_in_queue = 0; 221 queue->bytes_in_queue = 0;
222 } 222 }
223 if (NULL != (mq = queue->mq)) 223 if (NULL != (mq = queue->mq))
224 { 224 {
@@ -439,7 +439,7 @@ select_write_cb (void *cls)
439 queue->address_len); 439 queue->address_len);
440 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 440 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
441 "UNIX transmitted message to %s (%d/%u: %s)\n", 441 "UNIX transmitted message to %s (%d/%u: %s)\n",
442 GNUNET_i2s (&queue->target), 442 GNUNET_i2s (&queue->target),
443 (int) sent, 443 (int) sent,
444 (unsigned int) msg_size, 444 (unsigned int) msg_size,
445 (sent < 0) ? STRERROR (errno) : "ok"); 445 (sent < 0) ? STRERROR (errno) : "ok");
@@ -463,7 +463,7 @@ select_write_cb (void *cls)
463 /* We should retry later... */ 463 /* We should retry later... */
464 GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, 464 GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG,
465 "send"); 465 "send");
466 return; 466 return;
467 case EMSGSIZE: 467 case EMSGSIZE:
468 { 468 {
469 socklen_t size = 0; 469 socklen_t size = 0;
@@ -533,7 +533,7 @@ mq_send (struct GNUNET_MQ_Handle *mq,
533 533
534 GNUNET_assert (mq == queue->mq); 534 GNUNET_assert (mq == queue->mq);
535 GNUNET_assert (NULL == queue->msg); 535 GNUNET_assert (NULL == queue->msg);
536 queue->msg = msg; 536 queue->msg = msg;
537 GNUNET_CONTAINER_DLL_insert (queue_head, 537 GNUNET_CONTAINER_DLL_insert (queue_head,
538 queue_tail, 538 queue_tail,
539 queue); 539 queue);
@@ -664,7 +664,7 @@ setup_queue (const struct GNUNET_PeerIdentity *target,
664 queue); 664 queue);
665 { 665 {
666 char *foreign_addr; 666 char *foreign_addr;
667 667
668 if ('\0' == un->sun_path[0]) 668 if ('\0' == un->sun_path[0])
669 GNUNET_asprintf (&foreign_addr, 669 GNUNET_asprintf (&foreign_addr,
670 "%s-@%s", 670 "%s-@%s",
@@ -679,8 +679,9 @@ setup_queue (const struct GNUNET_PeerIdentity *target,
679 = GNUNET_TRANSPORT_communicator_mq_add (ch, 679 = GNUNET_TRANSPORT_communicator_mq_add (ch,
680 &queue->target, 680 &queue->target,
681 foreign_addr, 681 foreign_addr,
682 UNIX_MTU, 682 UNIX_MTU,
683 GNUNET_ATS_NET_LOOPBACK, 683 GNUNET_ATS_NET_LOOPBACK,
684 0 /* distance */,
684 cs, 685 cs,
685 queue->mq); 686 queue->mq);
686 GNUNET_free (foreign_addr); 687 GNUNET_free (foreign_addr);
@@ -798,12 +799,12 @@ select_read_cb (void *cls)
798 _("Maximum number of UNIX connections exceeded, dropping incoming message\n")); 799 _("Maximum number of UNIX connections exceeded, dropping incoming message\n"));
799 return; 800 return;
800 } 801 }
801 802
802 { 803 {
803 uint16_t offset = 0; 804 uint16_t offset = 0;
804 uint16_t tsize = msize - sizeof (struct UNIXMessage); 805 uint16_t tsize = msize - sizeof (struct UNIXMessage);
805 const char *msgbuf = (const char *) &msg[1]; 806 const char *msgbuf = (const char *) &msg[1];
806 807
807 while (offset + sizeof (struct GNUNET_MessageHeader) <= tsize) 808 while (offset + sizeof (struct GNUNET_MessageHeader) <= tsize)
808 { 809 {
809 const struct GNUNET_MessageHeader *currhdr; 810 const struct GNUNET_MessageHeader *currhdr;
@@ -870,7 +871,7 @@ mq_init (void *cls,
870 const char *path; 871 const char *path;
871 struct sockaddr_un *un; 872 struct sockaddr_un *un;
872 socklen_t un_len; 873 socklen_t un_len;
873 874
874 if (0 != strncmp (address, 875 if (0 != strncmp (address,
875 COMMUNICATOR_ADDRESS_PREFIX "-", 876 COMMUNICATOR_ADDRESS_PREFIX "-",
876 strlen (COMMUNICATOR_ADDRESS_PREFIX "-"))) 877 strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
@@ -902,7 +903,7 @@ mq_init (void *cls,
902 { 903 {
903 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 904 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
904 "Failed to setup queue to %s at `%s'\n", 905 "Failed to setup queue to %s at `%s'\n",
905 GNUNET_i2s (peer), 906 GNUNET_i2s (peer),
906 path); 907 path);
907 return GNUNET_NO; 908 return GNUNET_NO;
908 } 909 }
@@ -981,7 +982,7 @@ do_shutdown (void *cls)
981 982
982/** 983/**
983 * Setup communicator and launch network interactions. 984 * Setup communicator and launch network interactions.
984 * 985 *
985 * @param cls NULL (always) 986 * @param cls NULL (always)
986 * @param args remaining command-line arguments 987 * @param args remaining command-line arguments
987 * @param cfgfile name of the configuration file used (for saving, can be NULL!) 988 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
@@ -998,7 +999,7 @@ run (void *cls,
998 socklen_t un_len; 999 socklen_t un_len;
999 char *my_addr; 1000 char *my_addr;
1000 (void) cls; 1001 (void) cls;
1001 1002
1002 if (GNUNET_OK != 1003 if (GNUNET_OK !=
1003 GNUNET_CONFIGURATION_get_value_filename (cfg, 1004 GNUNET_CONFIGURATION_get_value_filename (cfg,
1004 COMMUNICATOR_CONFIG_SECTION, 1005 COMMUNICATOR_CONFIG_SECTION,
@@ -1016,7 +1017,7 @@ run (void *cls,
1016 "MAX_QUEUE_LENGTH", 1017 "MAX_QUEUE_LENGTH",
1017 &max_queue_length)) 1018 &max_queue_length))
1018 max_queue_length = DEFAULT_MAX_QUEUE_LENGTH; 1019 max_queue_length = DEFAULT_MAX_QUEUE_LENGTH;
1019 1020
1020 un = unix_address_to_sockaddr (unix_socket_path, 1021 un = unix_address_to_sockaddr (unix_socket_path,
1021 &un_len); 1022 &un_len);
1022 if (NULL == un) 1023 if (NULL == un)
@@ -1082,6 +1083,7 @@ run (void *cls,
1082 ch = GNUNET_TRANSPORT_communicator_connect (cfg, 1083 ch = GNUNET_TRANSPORT_communicator_connect (cfg,
1083 COMMUNICATOR_CONFIG_SECTION, 1084 COMMUNICATOR_CONFIG_SECTION,
1084 COMMUNICATOR_ADDRESS_PREFIX, 1085 COMMUNICATOR_ADDRESS_PREFIX,
1086 GNUNET_TRANSPORT_CC_RELIABLE,
1085 &mq_init, 1087 &mq_init,
1086 NULL); 1088 NULL);
1087 if (NULL == ch) 1089 if (NULL == ch)