Handle the results from a resolve attempt. If it succeeded, notify the listener. Otherwise if we have fallback peers to try, start another query and send the result to them. By default these are the peers we know support the subnet, but weren't connected to when the we first attempted the resolution.
(&mut self, mut query: Query, result: ResolveResult)
| 512 | /// we know support the subnet, but weren't connected to when the we |
| 513 | /// first attempted the resolution. |
| 514 | fn resolve_query(&mut self, mut query: Query, result: ResolveResult) { |
| 515 | match result { |
| 516 | Ok(_) => { |
| 517 | stats::CONTENT_RESOLVE_SUCCESS.inc(); |
| 518 | send_resolve_result(query.response_channel, result) |
| 519 | } |
| 520 | Err(_) if query.fallback_peer_ids.is_empty() => { |
| 521 | stats::CONTENT_RESOLVE_FAILURE.inc(); |
| 522 | send_resolve_result(query.response_channel, result) |
| 523 | } |
| 524 | Err(e) => { |
| 525 | stats::CONTENT_RESOLVE_FALLBACK.inc(); |
| 526 | debug!( |
| 527 | "resolving {} from {} failed with {}, but there are {} fallback peers to try", |
| 528 | query.cid, |
| 529 | query.subnet_id, |
| 530 | e, |
| 531 | query.fallback_peer_ids.len() |
| 532 | ); |
| 533 | |
| 534 | // Try to resolve from the next batch of peers. |
| 535 | let peers = std::mem::take(&mut query.fallback_peer_ids); |
| 536 | let (peers, fallback) = self.split_peers_for_query(peers); |
| 537 | let query_id = self.content_mut().resolve(query.cid, peers); |
| 538 | |
| 539 | // Leave the rest for later. |
| 540 | query.fallback_peer_ids = fallback; |
| 541 | |
| 542 | self.queries.insert(query_id, query); |
| 543 | } |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | /// Split peers into a group we query now and a group we fall back on if the current batch fails. |
| 548 | fn split_peers_for_query(&self, mut peers: Vec<PeerId>) -> (Vec<PeerId>, Vec<PeerId>) { |
no test coverage detected