diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-01-27 04:05:12 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-01-27 04:05:12 +0100 |
commit | d3f013aba71486c121800d279cd1d3af4425c412 (patch) | |
tree | c86bfc9d800e04bda51e68b3041db1d954f43737 /src/cadet/cadet_api_get_channel.c | |
parent | 20c42b92b71cb31bc5ed9cc4e4ff32efbd95aae4 (diff) | |
download | gnunet-d3f013aba71486c121800d279cd1d3af4425c412.tar.gz gnunet-d3f013aba71486c121800d279cd1d3af4425c412.zip |
more work towards fixing #5385
Diffstat (limited to 'src/cadet/cadet_api_get_channel.c')
-rw-r--r-- | src/cadet/cadet_api_get_channel.c | 90 |
1 files changed, 74 insertions, 16 deletions
diff --git a/src/cadet/cadet_api_get_channel.c b/src/cadet/cadet_api_get_channel.c index 1249777c2..81f0691f1 100644 --- a/src/cadet/cadet_api_get_channel.c +++ b/src/cadet/cadet_api_get_channel.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2011, 2017 GNUnet e.V. | 3 | Copyright (C) 2011, 2017, 2019 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
@@ -72,15 +72,67 @@ struct GNUNET_CADET_ChannelMonitor | |||
72 | */ | 72 | */ |
73 | struct GNUNET_PeerIdentity peer; | 73 | struct GNUNET_PeerIdentity peer; |
74 | 74 | ||
75 | /** | ||
76 | * Channel we want information about. | ||
77 | */ | ||
78 | uint32_t /* UGH */ channel_number; | ||
79 | |||
80 | }; | 75 | }; |
81 | 76 | ||
82 | 77 | ||
83 | /** | 78 | /** |
79 | * Check that message received from CADET service is well-formed. | ||
80 | * | ||
81 | * @param cls unused | ||
82 | * @param message the message we got | ||
83 | * @return #GNUNET_OK if the message is well-formed, | ||
84 | * #GNUNET_SYSERR otherwise | ||
85 | */ | ||
86 | static int | ||
87 | check_channel_info (void *cls, | ||
88 | const struct GNUNET_CADET_ChannelInfoMessage *message) | ||
89 | { | ||
90 | (void) cls; | ||
91 | |||
92 | return GNUNET_OK; | ||
93 | } | ||
94 | |||
95 | |||
96 | /** | ||
97 | * Process a local peer info reply, pass info to the user. | ||
98 | * | ||
99 | * @param cls Closure | ||
100 | * @param message Message itself. | ||
101 | */ | ||
102 | static void | ||
103 | handle_channel_info (void *cls, | ||
104 | const struct GNUNET_CADET_ChannelInfoMessage *message) | ||
105 | { | ||
106 | struct GNUNET_CADET_ChannelMonitor *cm = cls; | ||
107 | struct GNUNET_CADET_ChannelInternals ci; | ||
108 | |||
109 | ci.root = message->root; | ||
110 | ci.dest = message->dest; | ||
111 | cm->channel_cb (cm->channel_cb_cls, | ||
112 | &ci); | ||
113 | GNUNET_CADET_get_channel_cancel (cm); | ||
114 | } | ||
115 | |||
116 | |||
117 | /** | ||
118 | * Process a local peer info reply, pass info to the user. | ||
119 | * | ||
120 | * @param cls Closure | ||
121 | * @param message Message itself. | ||
122 | */ | ||
123 | static void | ||
124 | handle_channel_info_end (void *cls, | ||
125 | const struct GNUNET_MessageHeader *message) | ||
126 | { | ||
127 | struct GNUNET_CADET_ChannelMonitor *cm = cls; | ||
128 | |||
129 | cm->channel_cb (cm->channel_cb_cls, | ||
130 | NULL); | ||
131 | GNUNET_CADET_get_channel_cancel (cm); | ||
132 | } | ||
133 | |||
134 | |||
135 | /** | ||
84 | * Reconnect to the service and try again. | 136 | * Reconnect to the service and try again. |
85 | * | 137 | * |
86 | * @param cls a `struct GNUNET_CADET_ChannelMonitor` operation | 138 | * @param cls a `struct GNUNET_CADET_ChannelMonitor` operation |
@@ -120,11 +172,18 @@ static void | |||
120 | reconnect (void *cls) | 172 | reconnect (void *cls) |
121 | { | 173 | { |
122 | struct GNUNET_CADET_ChannelMonitor *cm = cls; | 174 | struct GNUNET_CADET_ChannelMonitor *cm = cls; |
123 | struct GNUNET_MQ_MessageHandler *handlers[] = { | 175 | struct GNUNET_MQ_MessageHandler handlers[] = { |
124 | FIXME, | 176 | GNUNET_MQ_hd_fixed_size (channel_info_end, |
177 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL_END, | ||
178 | struct GNUNET_MessageHeader, | ||
179 | cm), | ||
180 | GNUNET_MQ_hd_var_size (channel_info, | ||
181 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL, | ||
182 | struct GNUNET_CADET_ChannelInfoMessage, | ||
183 | cm), | ||
125 | GNUNET_MQ_handler_end () | 184 | GNUNET_MQ_handler_end () |
126 | }; | 185 | }; |
127 | struct GNUNET_MessageHeader *msg; | 186 | struct GNUNET_CADET_RequestChannelInfoMessage *msg; |
128 | struct GNUNET_MQ_Envelope *env; | 187 | struct GNUNET_MQ_Envelope *env; |
129 | 188 | ||
130 | cm->reconnect_task = NULL; | 189 | cm->reconnect_task = NULL; |
@@ -136,7 +195,8 @@ reconnect (void *cls) | |||
136 | if (NULL == cm->mq) | 195 | if (NULL == cm->mq) |
137 | return; | 196 | return; |
138 | env = GNUNET_MQ_msg (msg, | 197 | env = GNUNET_MQ_msg (msg, |
139 | type); | 198 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_CHANNEL); |
199 | msg->target = cm->peer; | ||
140 | GNUNET_MQ_send (cm->mq, | 200 | GNUNET_MQ_send (cm->mq, |
141 | env); | 201 | env); |
142 | } | 202 | } |
@@ -147,7 +207,6 @@ reconnect (void *cls) | |||
147 | * | 207 | * |
148 | * @param cfg configuration to use | 208 | * @param cfg configuration to use |
149 | * @param peer ID of the other end of the channel. | 209 | * @param peer ID of the other end of the channel. |
150 | * @param channel_number Channel number. | ||
151 | * @param callback Function to call with the requested data. | 210 | * @param callback Function to call with the requested data. |
152 | * @param callback_cls Closure for @c callback. | 211 | * @param callback_cls Closure for @c callback. |
153 | * @return NULL on error | 212 | * @return NULL on error |
@@ -155,7 +214,6 @@ reconnect (void *cls) | |||
155 | struct GNUNET_CADET_ChannelMonitor * | 214 | struct GNUNET_CADET_ChannelMonitor * |
156 | GNUNET_CADET_get_channel (const struct GNUNET_CONFIGURATION_Handle *cfg, | 215 | GNUNET_CADET_get_channel (const struct GNUNET_CONFIGURATION_Handle *cfg, |
157 | struct GNUNET_PeerIdentity *peer, | 216 | struct GNUNET_PeerIdentity *peer, |
158 | uint32_t /* UGH */ channel_number, | ||
159 | GNUNET_CADET_ChannelCB callback, | 217 | GNUNET_CADET_ChannelCB callback, |
160 | void *callback_cls) | 218 | void *callback_cls) |
161 | { | 219 | { |
@@ -167,10 +225,10 @@ GNUNET_CADET_get_channel (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
167 | return NULL; | 225 | return NULL; |
168 | } | 226 | } |
169 | cm = GNUNET_new (struct GNUNET_CADET_ChannelMonitor); | 227 | cm = GNUNET_new (struct GNUNET_CADET_ChannelMonitor); |
170 | cm->peer_cb = callback; | 228 | cm->channel_cb = callback; |
171 | cm->peer_cb_cls = callback_cls; | 229 | cm->channel_cb_cls = callback_cls; |
172 | cm->cfg = cfg; | 230 | cm->cfg = cfg; |
173 | cm->id = *id; | 231 | cm->peer = *peer; |
174 | reconnect (cm); | 232 | reconnect (cm); |
175 | if (NULL == cm->mq) | 233 | if (NULL == cm->mq) |
176 | { | 234 | { |
@@ -190,7 +248,7 @@ GNUNET_CADET_get_channel (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
190 | void * | 248 | void * |
191 | GNUNET_CADET_get_channel_cancel (struct GNUNET_CADET_ChannelMonitor *cm) | 249 | GNUNET_CADET_get_channel_cancel (struct GNUNET_CADET_ChannelMonitor *cm) |
192 | { | 250 | { |
193 | void *ret = cm->peer_cb_cls; | 251 | void *ret = cm->channel_cb_cls; |
194 | 252 | ||
195 | if (NULL != cm->mq) | 253 | if (NULL != cm->mq) |
196 | GNUNET_MQ_destroy (cm->mq); | 254 | GNUNET_MQ_destroy (cm->mq); |