Skip to content

Commit

Permalink
fix(DistributedQuery): use ContainsKey for visited peers
Browse files Browse the repository at this point in the history
  • Loading branch information
richardschneider committed Sep 2, 2019
1 parent 9d849b0 commit c704e7c
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Routing/DistributedQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ async Task AskAsync(int taskId)
// Get the nearest peer that has not been visited.
var peer = Dht.RoutingTable
.NearestPeers(QueryKey)
.Where(p => !visited.Keys.Contains(p))
.Where(p => !visited.ContainsKey(p))
.FirstOrDefault();
if (peer == null)
{
Expand Down Expand Up @@ -230,7 +230,7 @@ void ProcessProviders(DhtPeerMessage[] providers)
{
// Only unique answers
var answer = p as T;
if (!answers.Keys.Contains(answer))
if (!answers.ContainsKey(answer))
{
AddAnswer(answer);
}
Expand Down Expand Up @@ -274,10 +274,12 @@ public void AddAnswer(T answer)
if (runningQuery != null && runningQuery.IsCancellationRequested)
return;

answers.TryAdd(answer, answer);
if (answers.Values.Count >= AnswersNeeded && runningQuery != null && !runningQuery.IsCancellationRequested)
if (answers.TryAdd(answer, answer))
{
runningQuery.Cancel(false);
if (answers.Count >= AnswersNeeded && runningQuery != null && !runningQuery.IsCancellationRequested)
{
runningQuery.Cancel(false);
}
}

AnswerObtained?.Invoke(this, answer);
Expand Down

0 comments on commit c704e7c

Please sign in to comment.