diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-01-27 00:36:47 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-01-27 00:36:47 +0100 |
commit | 65b339b7ce68fcbaec9df6f66e8ed45e60b39ce1 (patch) | |
tree | fff17cdb219935617877a5504bb8435712b80a61 /src/cadet/cadet_api_get_channel.c | |
parent | 8f884f001a70fee622fff0c0ac8c38a0634df789 (diff) | |
download | gnunet-65b339b7ce68fcbaec9df6f66e8ed45e60b39ce1.tar.gz gnunet-65b339b7ce68fcbaec9df6f66e8ed45e60b39ce1.zip |
more work on #5385
Diffstat (limited to 'src/cadet/cadet_api_get_channel.c')
-rw-r--r-- | src/cadet/cadet_api_get_channel.c | 98 |
1 files changed, 95 insertions, 3 deletions
diff --git a/src/cadet/cadet_api_get_channel.c b/src/cadet/cadet_api_get_channel.c index cd90f5b78..d41337522 100644 --- a/src/cadet/cadet_api_get_channel.c +++ b/src/cadet/cadet_api_get_channel.c | |||
@@ -31,9 +31,8 @@ | |||
31 | #include "cadet_protocol.h" | 31 | #include "cadet_protocol.h" |
32 | 32 | ||
33 | 33 | ||
34 | |||
35 | /** | 34 | /** |
36 | * Ugly legacy hack. | 35 | * Operation handle. |
37 | */ | 36 | */ |
38 | struct GNUNET_CADET_ChannelMonitor | 37 | struct GNUNET_CADET_ChannelMonitor |
39 | { | 38 | { |
@@ -48,23 +47,81 @@ struct GNUNET_CADET_ChannelMonitor | |||
48 | */ | 47 | */ |
49 | void *channel_cb_cls; | 48 | void *channel_cb_cls; |
50 | 49 | ||
50 | /** | ||
51 | * Configuration we use. | ||
52 | */ | ||
51 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 53 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
52 | 54 | ||
55 | /** | ||
56 | * Message queue to talk to CADET service. | ||
57 | */ | ||
53 | struct GNUNET_MQ_Handle *mq; | 58 | struct GNUNET_MQ_Handle *mq; |
54 | 59 | ||
60 | /** | ||
61 | * Task to reconnect. | ||
62 | */ | ||
63 | struct GNUNET_SCHEDULER_Task *reconnect_task; | ||
64 | |||
65 | /** | ||
66 | * Backoff for reconnect attempts. | ||
67 | */ | ||
68 | struct GNUNET_TIME_Relative backoff; | ||
69 | |||
70 | /** | ||
71 | * Peer we want information about. | ||
72 | */ | ||
55 | struct GNUNET_PeerIdentity peer; | 73 | struct GNUNET_PeerIdentity peer; |
56 | 74 | ||
75 | /** | ||
76 | * Channel we want information about. | ||
77 | */ | ||
57 | uint32_t /* UGH */ channel_number; | 78 | uint32_t /* UGH */ channel_number; |
58 | 79 | ||
59 | }; | 80 | }; |
60 | 81 | ||
61 | 82 | ||
83 | /** | ||
84 | * Reconnect to the service and try again. | ||
85 | * | ||
86 | * @param cls a `struct GNUNET_CADET_ChannelMonitor` operation | ||
87 | */ | ||
88 | static void | ||
89 | reconnect (void *cls); | ||
90 | |||
91 | |||
92 | /** | ||
93 | * Function called on connection trouble. Reconnects. | ||
94 | * | ||
95 | * @param cls a `struct GNUNET_CADET_ChannelMonitor`` | ||
96 | * @param error error code from MQ | ||
97 | */ | ||
98 | static void | ||
99 | error_handler (void *cls, | ||
100 | enum GNUNET_MQ_Error error) | ||
101 | { | ||
102 | struct GNUNET_CADET_ChannelMonitor *cm = cls; | ||
103 | |||
104 | GNUNET_MQ_destroy (cm->mq); | ||
105 | cm->mq = NULL; | ||
106 | cm->backoff = GNUNET_TIME_randomized_backoff (cm->backoff, | ||
107 | GNUNET_TIME_UNIT_MINUTES); | ||
108 | cm->reconnect_task = GNUNET_SCHEDULER_add_delayed (cm->backoff, | ||
109 | &reconnect, | ||
110 | cm); | ||
111 | } | ||
112 | |||
62 | 113 | ||
114 | /** | ||
115 | * Reconnect to the service and try again. | ||
116 | * | ||
117 | * @param cls a `struct GNUNET_CADET_ChannelMonitor` operation | ||
118 | */ | ||
63 | static void | 119 | static void |
64 | reconnect (void *cls) | 120 | reconnect (void *cls) |
65 | { | 121 | { |
66 | struct GNUNET_CADET_ChannelMonitor *cm = cls; | 122 | struct GNUNET_CADET_ChannelMonitor *cm = cls; |
67 | struct GNUNET_MQ_MessageHandler *handlers[] = { | 123 | struct GNUNET_MQ_MessageHandler *handlers[] = { |
124 | FIXME | ||
68 | } | 125 | } |
69 | struct GNUNET_MessageHeader *msg; | 126 | struct GNUNET_MessageHeader *msg; |
70 | struct GNUNET_MQ_Envelope *env; | 127 | struct GNUNET_MQ_Envelope *env; |
@@ -100,10 +157,45 @@ GNUNET_CADET_get_channel (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
100 | GNUNET_CADET_ChannelCB callback, | 157 | GNUNET_CADET_ChannelCB callback, |
101 | void *callback_cls) | 158 | void *callback_cls) |
102 | { | 159 | { |
160 | struct GNUNET_CADET_ChannelMonitor *cm; | ||
161 | |||
162 | if (NULL == callback) | ||
163 | { | ||
164 | GNUNET_break (0); | ||
165 | return NULL; | ||
166 | } | ||
167 | cm = GNUNET_new (struct GNUNET_CADET_ChannelMonitor); | ||
168 | cm->peer_cb = callback; | ||
169 | cm->peer_cb_cls = callback_cls; | ||
170 | cm->cfg = cfg; | ||
171 | cm->id = *id; | ||
172 | reconnect (cm); | ||
173 | if (NULL == cm->mq) | ||
174 | { | ||
175 | GNUNET_free (cm); | ||
176 | return NULL; | ||
177 | } | ||
178 | return cm; | ||
103 | } | 179 | } |
104 | 180 | ||
105 | 181 | ||
182 | /** | ||
183 | * Cancel a channel monitor request. The callback will not be called (anymore). | ||
184 | * | ||
185 | * @param h Cadet handle. | ||
186 | * @return Closure that was given to #GNUNET_CADET_get_channel(). | ||
187 | */ | ||
106 | void * | 188 | void * |
107 | GNUNET_CADET_get_channel_cancel (struct GNUNET_CADET_ChannelMonitor *cm) | 189 | GNUNET_CADET_get_channel_cancel (struct GNUNET_CADET_ChannelMonitor *cm) |
108 | { | 190 | { |
191 | void *ret = cm->peer_cb_cls; | ||
192 | |||
193 | if (NULL != cm->mq) | ||
194 | GNUNET_MQ_destroy (cm->mq); | ||
195 | if (NULL != cm->reconnect_task) | ||
196 | GNUNET_SCHEDULER_cancel (cm->reconnect_task); | ||
197 | GNUNET_free (cm); | ||
198 | return ret; | ||
109 | } | 199 | } |
200 | |||
201 | /* end of cadet_api_get_channel.c */ | ||