Get a random peer, but try our preferred peer first, if any. This * biasses us to the peer that told us of unexpected gossip. */
| 175 | /* Get a random peer, but try our preferred peer first, if any. This |
| 176 | * biasses us to the peer that told us of unexpected gossip. */ |
| 177 | static struct peer *random_seeker(struct seeker *seeker, |
| 178 | bool (*check_peer)(const struct peer *peer)) |
| 179 | { |
| 180 | struct peer *peer = seeker->preferred_peer; |
| 181 | struct peer *first; |
| 182 | struct peer_node_id_map_iter it; |
| 183 | |
| 184 | /* 80% chance of immediately choosing a peer who reported the missing |
| 185 | * stuff: they presumably can tell us more about it. We don't |
| 186 | * *always* choose it because it could be simply spamming us with |
| 187 | * invalid announcements to get chosen, and we don't handle that case |
| 188 | * well yet. */ |
| 189 | if (peer && check_peer(peer) && pseudorand(5) != 0) { |
| 190 | seeker->random_peer = NULL; |
| 191 | return peer; |
| 192 | } |
| 193 | |
| 194 | /* Rotate through, so we don't favor a single peer. */ |
| 195 | peer = first = first_random_peer(seeker->daemon, &it); |
| 196 | while (peer) { |
| 197 | if (check_peer(peer)) |
| 198 | break; |
| 199 | peer = next_random_peer(seeker->daemon, first, &it); |
| 200 | } |
| 201 | return peer; |
| 202 | } |
| 203 | |
| 204 | static bool peer_made_progress(struct seeker *seeker, const struct peer *peer) |
| 205 | { |
no test coverage detected