diff options
Diffstat (limited to 'src/cadet/cadet_api_list_peers.c')
-rw-r--r-- | src/cadet/cadet_api_list_peers.c | 76 |
1 files changed, 32 insertions, 44 deletions
diff --git a/src/cadet/cadet_api_list_peers.c b/src/cadet/cadet_api_list_peers.c index cc6948a36..4dc6d02f5 100644 --- a/src/cadet/cadet_api_list_peers.c +++ b/src/cadet/cadet_api_list_peers.c | |||
@@ -71,59 +71,43 @@ struct GNUNET_CADET_PeersLister | |||
71 | 71 | ||
72 | 72 | ||
73 | /** | 73 | /** |
74 | * Check that message received from CADET service is well-formed. | 74 | * Process a local reply about info on all tunnels, pass info to the user. |
75 | * | 75 | * |
76 | * @param cls the `struct GNUNET_CADET_PeersLister` | 76 | * @param cls a `struct GNUNET_CADET_PeersLister` |
77 | * @param message the message we got | 77 | * @param info Message itself. |
78 | * @return #GNUNET_OK if the message is well-formed, | ||
79 | * #GNUNET_SYSERR otherwise | ||
80 | */ | 78 | */ |
81 | static int | 79 | static void |
82 | check_get_peers (void *cls, | 80 | handle_get_peers (void *cls, |
83 | const struct GNUNET_MessageHeader *message) | 81 | const struct GNUNET_CADET_LocalInfoPeers *info) |
84 | { | 82 | { |
85 | size_t esize; | 83 | struct GNUNET_CADET_PeersLister *pl = cls; |
86 | 84 | struct GNUNET_CADET_PeerListEntry ple; | |
87 | (void) cls; | 85 | |
88 | esize = ntohs (message->size); | 86 | ple.peer = info->destination; |
89 | if (sizeof (struct GNUNET_CADET_LocalInfoPeer) == esize) | 87 | ple.have_tunnel = (int) ntohs (info->tunnel); |
90 | return GNUNET_OK; | 88 | ple.n_paths = (unsigned int) ntohs (info->paths); |
91 | if (sizeof (struct GNUNET_MessageHeader) == esize) | 89 | ple.best_path_length = (unsigned int) ntohl (info->best_path_length); |
92 | return GNUNET_OK; | 90 | pl->peers_cb (pl->peers_cb_cls, |
93 | return GNUNET_SYSERR; | 91 | &ple); |
94 | } | 92 | } |
95 | 93 | ||
96 | 94 | ||
97 | // FIXME: use two different message types instead of this mess! | ||
98 | /** | 95 | /** |
99 | * Process a local reply about info on all tunnels, pass info to the user. | 96 | * Process a end of list reply about info on all peers. |
100 | * | 97 | * |
101 | * @param cls a `struct GNUNET_CADET_PeersLister` | 98 | * @param cls a `struct GNUNET_CADET_PeersLister` |
102 | * @param msg Message itself. | 99 | * @param msg Message itself. |
103 | */ | 100 | */ |
104 | static void | 101 | static void |
105 | handle_get_peers (void *cls, | 102 | handle_get_peers_end (void *cls, |
106 | const struct GNUNET_MessageHeader *msg) | 103 | const struct GNUNET_MessageHeader *msg) |
107 | { | 104 | { |
108 | struct GNUNET_CADET_PeersLister *pl = cls; | 105 | struct GNUNET_CADET_PeersLister *pl = cls; |
109 | const struct GNUNET_CADET_LocalInfoPeer *info = | 106 | (void) msg; |
110 | (const struct GNUNET_CADET_LocalInfoPeer *) msg; | 107 | |
111 | 108 | pl->peers_cb (pl->peers_cb_cls, | |
112 | if (sizeof (struct GNUNET_CADET_LocalInfoPeer) == ntohs (msg->size)) | 109 | NULL); |
113 | pl->peers_cb (pl->peers_cb_cls, | 110 | GNUNET_CADET_list_peers_cancel (pl); |
114 | &info->destination, | ||
115 | (int) ntohs (info->tunnel), | ||
116 | (unsigned int) ntohs (info->paths), | ||
117 | 0); | ||
118 | else | ||
119 | { | ||
120 | pl->peers_cb (pl->peers_cb_cls, | ||
121 | NULL, | ||
122 | 0, | ||
123 | 0, | ||
124 | 0); | ||
125 | GNUNET_CADET_list_peers_cancel (pl); | ||
126 | } | ||
127 | } | 111 | } |
128 | 112 | ||
129 | 113 | ||
@@ -168,10 +152,14 @@ reconnect (void *cls) | |||
168 | { | 152 | { |
169 | struct GNUNET_CADET_PeersLister *pl = cls; | 153 | struct GNUNET_CADET_PeersLister *pl = cls; |
170 | struct GNUNET_MQ_MessageHandler handlers[] = { | 154 | struct GNUNET_MQ_MessageHandler handlers[] = { |
171 | GNUNET_MQ_hd_var_size (get_peers, | 155 | GNUNET_MQ_hd_fixed_size (get_peers, |
172 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS, | 156 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS, |
173 | struct GNUNET_MessageHeader, | 157 | struct GNUNET_CADET_LocalInfoPeers, |
174 | pl), | 158 | pl), |
159 | GNUNET_MQ_hd_fixed_size (get_peers_end, | ||
160 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS_END, | ||
161 | struct GNUNET_MessageHeader, | ||
162 | pl), | ||
175 | GNUNET_MQ_handler_end () | 163 | GNUNET_MQ_handler_end () |
176 | }; | 164 | }; |
177 | struct GNUNET_MessageHeader *msg; | 165 | struct GNUNET_MessageHeader *msg; |
@@ -186,7 +174,7 @@ reconnect (void *cls) | |||
186 | if (NULL == pl->mq) | 174 | if (NULL == pl->mq) |
187 | return; | 175 | return; |
188 | env = GNUNET_MQ_msg (msg, | 176 | env = GNUNET_MQ_msg (msg, |
189 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS); | 177 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PEERS); |
190 | GNUNET_MQ_send (pl->mq, | 178 | GNUNET_MQ_send (pl->mq, |
191 | env); | 179 | env); |
192 | } | 180 | } |