Skip to content

Commit

Permalink
* Fixed bug where if there are too many peers an exception is thrown
Browse files Browse the repository at this point in the history
 on get dht data
* Fixed bug that causes excessive error output on closed connection
  • Loading branch information
fireduck64 committed Jan 31, 2020
1 parent 78d239e commit a6aea54
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/DHTServer.java
Expand Up @@ -11,6 +11,8 @@
import snowblossom.lib.AddressUtil;
import snowblossom.lib.HexUtil;
import snowblossom.lib.ValidationException;
import java.util.LinkedList;
import java.util.Collections;

/**
* GRPC DHT server. Some methods can also be called directly. Whatever.
Expand Down Expand Up @@ -108,12 +110,12 @@ public void storeDHTData(StoreDHTRequest req, StreamObserver<DHTDataSet> o)
{
DHTDataSet ds = storeDHTData(req);
o.onNext(ds);
o.onCompleted();
}
catch(Throwable t)
{
o.onError(t);
}
o.onCompleted();
}


Expand Down Expand Up @@ -172,12 +174,12 @@ public void getDHTData(GetDHTRequest req, StreamObserver<DHTDataSet> o)
{
DHTDataSet ds = getDHTData(req);
o.onNext(ds);
o.onCompleted();
}
catch(Throwable t)
{
o.onError(t);
}
o.onCompleted();
}


Expand Down Expand Up @@ -216,14 +218,22 @@ public void getDHTDataAsync(GetDHTRequest req, StreamObserver<DHTDataSet> so)

}

// TODO - make return random results rather than first n
public DHTDataSet getDHTLocal(ByteString target, int desired)
{
DHTDataSet.Builder set = DHTDataSet.newBuilder();
if (desired > 0)
{
Map<ByteString, SignedMessage> m = node.getDB().getDHTDataMap().getByPrefix(target, desired);
set.addAllDhtData(m.values());
Map<ByteString, SignedMessage> m = node.getDB().getDHTDataMap().getByPrefix(target, 100000);
LinkedList<SignedMessage> lst = new LinkedList<>();
lst.addAll(m.values());
Collections.shuffle(lst);

while(lst.size() > desired)
{
lst.pop();
}

set.addAllDhtData(lst);
}

return set.build();
Expand Down

0 comments on commit a6aea54

Please sign in to comment.