aboutsummaryrefslogtreecommitdiff
path: root/src/cadet/cadet_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cadet/cadet_api.c')
-rw-r--r--src/cadet/cadet_api.c97
1 files changed, 30 insertions, 67 deletions
diff --git a/src/cadet/cadet_api.c b/src/cadet/cadet_api.c
index 68bd4c290..45cb66c1d 100644
--- a/src/cadet/cadet_api.c
+++ b/src/cadet/cadet_api.c
@@ -73,72 +73,6 @@ struct GNUNET_CADET_Handle
73 struct GNUNET_TIME_Relative reconnect_time; 73 struct GNUNET_TIME_Relative reconnect_time;
74}; 74};
75 75
76
77/**
78 * Opaque handle to a channel.
79 */
80struct GNUNET_CADET_Channel
81{
82 /**
83 * Other end of the channel.
84 */
85 struct GNUNET_PeerIdentity peer;
86
87 /**
88 * Handle to the cadet this channel belongs to
89 */
90 struct GNUNET_CADET_Handle *cadet;
91
92 /**
93 * Channel's port, if incoming.
94 */
95 struct GNUNET_CADET_Port *incoming_port;
96
97 /**
98 * Any data the caller wants to put in here, used for the
99 * various callbacks (@e disconnects, @e window_changes, handlers).
100 */
101 void *ctx;
102
103 /**
104 * Message Queue for the channel (which we are implementing).
105 */
106 struct GNUNET_MQ_Handle *mq;
107
108 /**
109 * Task to allow mq to send more traffic.
110 */
111 struct GNUNET_SCHEDULER_Task *mq_cont;
112
113 /**
114 * Pending envelope with a message to be transmitted to the
115 * service as soon as we are allowed to. Should only be
116 * non-NULL if @e allow_send is 0.
117 */
118 struct GNUNET_MQ_Envelope *pending_env;
119
120 /**
121 * Window change handler.
122 */
123 GNUNET_CADET_WindowSizeEventHandler window_changes;
124
125 /**
126 * Disconnect handler.
127 */
128 GNUNET_CADET_DisconnectEventHandler disconnects;
129
130 /**
131 * Local ID of the channel, #GNUNET_CADET_LOCAL_CHANNEL_ID_CLI bit is set if outbound.
132 */
133 struct GNUNET_CADET_ClientChannelNumber ccn;
134
135 /**
136 * How many messages are we allowed to send to the service right now?
137 */
138 unsigned int allow_send;
139};
140
141
142/** 76/**
143 * Opaque handle to a port. 77 * Opaque handle to a port.
144 */ 78 */
@@ -995,6 +929,32 @@ GNUNET_CADET_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
995 929
996 930
997/** 931/**
932 * Function to return link to AGPL source upon request.
933 *
934 * @param cls closure with the identification of the client
935 * @param msg AGPL request
936 */
937static void
938return_agpl (void *cls, const struct GNUNET_MessageHeader *msg)
939{
940 struct GNUNET_SERVICE_Client *client = cls;
941 struct GNUNET_MQ_Handle *mq;
942 struct GNUNET_MQ_Envelope *env;
943 struct GNUNET_MessageHeader *res;
944 size_t slen;
945 const struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get ();
946
947 (void) msg;
948 slen = strlen (pd->agpl_url) + 1;
949 env = GNUNET_MQ_msg_extra (res, GNUNET_MESSAGE_TYPE_RESPONSE_AGPL, slen);
950 memcpy (&res[1], GNUNET_AGPL_URL, slen);
951 mq = GNUNET_SERVICE_client_get_mq (client);
952 GNUNET_MQ_send (mq, env);
953 GNUNET_SERVICE_client_continue (client);
954}
955
956
957/**
998 * Open a port to receive incomming MQ-based channels. 958 * Open a port to receive incomming MQ-based channels.
999 * 959 *
1000 * @param h CADET handle. 960 * @param h CADET handle.
@@ -1016,6 +976,7 @@ GNUNET_CADET_open_port (struct GNUNET_CADET_Handle *h,
1016 const struct GNUNET_MQ_MessageHandler *handlers) 976 const struct GNUNET_MQ_MessageHandler *handlers)
1017{ 977{
1018 struct GNUNET_CADET_Port *p; 978 struct GNUNET_CADET_Port *p;
979 const struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get ();
1019 980
1020 GNUNET_assert (NULL != connects); 981 GNUNET_assert (NULL != connects);
1021 GNUNET_assert (NULL != disconnects); 982 GNUNET_assert (NULL != disconnects);
@@ -1039,7 +1000,9 @@ GNUNET_CADET_open_port (struct GNUNET_CADET_Handle *h,
1039 p->cls = connects_cls; 1000 p->cls = connects_cls;
1040 p->window_changes = window_changes; 1001 p->window_changes = window_changes;
1041 p->disconnects = disconnects; 1002 p->disconnects = disconnects;
1042 p->handlers = GNUNET_MQ_copy_handlers (handlers); 1003 p->handlers = (NULL == pd->agpl_url)
1004 ? GNUNET_MQ_copy_handlers (handlers)
1005 : GNUNET_MQ_copy_handlers2 (handlers, &return_agpl, NULL);
1043 1006
1044 GNUNET_assert (GNUNET_OK == open_port_cb (h, &p->id, p)); 1007 GNUNET_assert (GNUNET_OK == open_port_cb (h, &p->id, p));
1045 return p; 1008 return p;