diff options
author | Julius Bünger <buenger@mytum.de> | 2016-05-14 19:41:37 +0000 |
---|---|---|
committer | Julius Bünger <buenger@mytum.de> | 2016-05-14 19:41:37 +0000 |
commit | 24d2c11a025e4a96d7fc0cb1ff4f4537e2003026 (patch) | |
tree | 23dbeead26eec9d3380f346a94e1a67084c4c6e1 /src/rps | |
parent | da72f158c616fe40c5b254e5db78ef5884a0f525 (diff) | |
download | gnunet-24d2c11a025e4a96d7fc0cb1ff4f4537e2003026.tar.gz gnunet-24d2c11a025e4a96d7fc0cb1ff4f4537e2003026.zip |
rps: use stored peers at startup
Diffstat (limited to 'src/rps')
-rw-r--r-- | src/rps/gnunet-service-rps.c | 28 | ||||
-rw-r--r-- | src/rps/gnunet-service-rps_peers.c | 64 | ||||
-rw-r--r-- | src/rps/gnunet-service-rps_peers.h | 26 |
3 files changed, 116 insertions, 2 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index c7cdccdfb..f56627a54 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c | |||
@@ -698,7 +698,6 @@ got_peer (const struct GNUNET_PeerIdentity *peer) | |||
698 | } | 698 | } |
699 | } | 699 | } |
700 | 700 | ||
701 | |||
702 | /** | 701 | /** |
703 | * @brief Checks if there is a sending channel and if it is needed | 702 | * @brief Checks if there is a sending channel and if it is needed |
704 | * | 703 | * |
@@ -2019,6 +2018,31 @@ init_peer_cb (void *cls, | |||
2019 | } | 2018 | } |
2020 | } | 2019 | } |
2021 | 2020 | ||
2021 | /** | ||
2022 | * @brief Iterator function over stored, valid peers. | ||
2023 | * | ||
2024 | * We initialise the sampler with those. | ||
2025 | * | ||
2026 | * @param cls the closure | ||
2027 | * @param peer the peer id | ||
2028 | * @return #GNUNET_YES if we should continue to | ||
2029 | * iterate, | ||
2030 | * #GNUNET_NO if not. | ||
2031 | */ | ||
2032 | static int | ||
2033 | valid_peers_iterator (void *cls, | ||
2034 | const struct GNUNET_PeerIdentity *peer) | ||
2035 | { | ||
2036 | if (NULL != peer) | ||
2037 | { | ||
2038 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2039 | "Got stored, valid peer %s\n", | ||
2040 | GNUNET_i2s (peer)); | ||
2041 | got_peer (peer); | ||
2042 | } | ||
2043 | return GNUNET_YES; | ||
2044 | } | ||
2045 | |||
2022 | 2046 | ||
2023 | /** | 2047 | /** |
2024 | * Iterator over peers from peerinfo. | 2048 | * Iterator over peers from peerinfo. |
@@ -2316,6 +2340,8 @@ run (void *cls, | |||
2316 | GNUNET_CADET_get_peers (cadet_handle, &init_peer_cb, NULL); | 2340 | GNUNET_CADET_get_peers (cadet_handle, &init_peer_cb, NULL); |
2317 | // TODO send push/pull to each of those peers? | 2341 | // TODO send push/pull to each of those peers? |
2318 | // TODO read stored valid peers from last run | 2342 | // TODO read stored valid peers from last run |
2343 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting stored valid peers\n"); | ||
2344 | Peers_get_valid_peers (valid_peers_iterator, NULL); | ||
2319 | 2345 | ||
2320 | peerinfo_notify_handle = GNUNET_PEERINFO_notify (cfg, | 2346 | peerinfo_notify_handle = GNUNET_PEERINFO_notify (cfg, |
2321 | GNUNET_NO, | 2347 | GNUNET_NO, |
diff --git a/src/rps/gnunet-service-rps_peers.c b/src/rps/gnunet-service-rps_peers.c index 93c9bef86..29b08adc8 100644 --- a/src/rps/gnunet-service-rps_peers.c +++ b/src/rps/gnunet-service-rps_peers.c | |||
@@ -204,6 +204,22 @@ struct PeerContext | |||
204 | }; | 204 | }; |
205 | 205 | ||
206 | /** | 206 | /** |
207 | * @brief Closure to #valid_peer_iterator | ||
208 | */ | ||
209 | struct PeersIteratorCls | ||
210 | { | ||
211 | /** | ||
212 | * Iterator function | ||
213 | */ | ||
214 | PeersIterator iterator; | ||
215 | |||
216 | /** | ||
217 | * Closure to iterator | ||
218 | */ | ||
219 | void *cls; | ||
220 | }; | ||
221 | |||
222 | /** | ||
207 | * @brief Hashmap of valid peers. | 223 | * @brief Hashmap of valid peers. |
208 | */ | 224 | */ |
209 | static struct GNUNET_CONTAINER_MultiPeerMap *valid_peers; | 225 | static struct GNUNET_CONTAINER_MultiPeerMap *valid_peers; |
@@ -919,7 +935,53 @@ Peers_terminate () | |||
919 | GNUNET_CONTAINER_multipeermap_destroy (valid_peers); | 935 | GNUNET_CONTAINER_multipeermap_destroy (valid_peers); |
920 | } | 936 | } |
921 | 937 | ||
922 | // TODO store valid peers | 938 | |
939 | /** | ||
940 | * Iterator over #valid_peers hash map entries. | ||
941 | * | ||
942 | * @param cls closure - unused | ||
943 | * @param peer current peer id | ||
944 | * @param value value in the hash map - unused | ||
945 | * @return #GNUNET_YES if we should continue to | ||
946 | * iterate, | ||
947 | * #GNUNET_NO if not. | ||
948 | */ | ||
949 | static int | ||
950 | valid_peer_iterator (void *cls, | ||
951 | const struct GNUNET_PeerIdentity *peer, | ||
952 | void *value) | ||
953 | { | ||
954 | struct PeersIteratorCls *it_cls = cls; | ||
955 | |||
956 | return it_cls->iterator (it_cls->cls, | ||
957 | peer); | ||
958 | } | ||
959 | |||
960 | |||
961 | /** | ||
962 | * @brief Get all currently known, valid peer ids. | ||
963 | * | ||
964 | * @param it function to call on each peer id | ||
965 | * @param it_cls extra argument to @a it | ||
966 | * @return the number of key value pairs processed, | ||
967 | * #GNUNET_SYSERR if it aborted iteration | ||
968 | */ | ||
969 | int | ||
970 | Peers_get_valid_peers (PeersIterator iterator, | ||
971 | void *it_cls) | ||
972 | { | ||
973 | struct PeersIteratorCls *cls; | ||
974 | int ret; | ||
975 | |||
976 | cls = GNUNET_new (struct PeersIteratorCls); | ||
977 | cls->iterator = iterator; | ||
978 | cls->cls = it_cls; | ||
979 | ret = GNUNET_CONTAINER_multipeermap_iterate (valid_peers, | ||
980 | valid_peer_iterator, | ||
981 | cls); | ||
982 | GNUNET_free (cls); | ||
983 | return ret; | ||
984 | } | ||
923 | 985 | ||
924 | /** | 986 | /** |
925 | * @brief Add peer to known peers. | 987 | * @brief Add peer to known peers. |
diff --git a/src/rps/gnunet-service-rps_peers.h b/src/rps/gnunet-service-rps_peers.h index 8a163f8cf..2a7bae6f4 100644 --- a/src/rps/gnunet-service-rps_peers.h +++ b/src/rps/gnunet-service-rps_peers.h | |||
@@ -100,6 +100,19 @@ enum Peers_ChannelRole | |||
100 | typedef void (* PeerOp) (void *cls, const struct GNUNET_PeerIdentity *peer); | 100 | typedef void (* PeerOp) (void *cls, const struct GNUNET_PeerIdentity *peer); |
101 | 101 | ||
102 | /** | 102 | /** |
103 | * @brief Iterator over valid peers. | ||
104 | * | ||
105 | * @param cls closure | ||
106 | * @param peer current public peer id | ||
107 | * @return #GNUNET_YES if we should continue to | ||
108 | * iterate, | ||
109 | * #GNUNET_NO if not. | ||
110 | */ | ||
111 | typedef int | ||
112 | (*PeersIterator) (void *cls, | ||
113 | const struct GNUNET_PeerIdentity *peer); | ||
114 | |||
115 | /** | ||
103 | * @brief Initialise storage of peers | 116 | * @brief Initialise storage of peers |
104 | * | 117 | * |
105 | * @param fn_valid_peers filename of the file used to store valid peer ids | 118 | * @param fn_valid_peers filename of the file used to store valid peer ids |
@@ -117,6 +130,19 @@ Peers_initialise (char* fn_valid_peers, | |||
117 | void | 130 | void |
118 | Peers_terminate (); | 131 | Peers_terminate (); |
119 | 132 | ||
133 | |||
134 | /** | ||
135 | * @brief Get all currently known, valid peer ids. | ||
136 | * | ||
137 | * @param it function to call on each peer id | ||
138 | * @param it_cls extra argument to @a it | ||
139 | * @return the number of key value pairs processed, | ||
140 | * #GNUNET_SYSERR if it aborted iteration | ||
141 | */ | ||
142 | int | ||
143 | Peers_get_valid_peers (PeersIterator iterator, | ||
144 | void *it_cls); | ||
145 | |||
120 | /** | 146 | /** |
121 | * @brief Add peer to known peers. | 147 | * @brief Add peer to known peers. |
122 | * | 148 | * |