Don't block when adding a new contact / searching for its public key
This commit is contained in:
parent
31eca20cca
commit
e1dcbbf19c
@ -30,6 +30,8 @@ import java.io.IOException;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The internal context should normally only be used for port implementations. If you need it in your client
|
* The internal context should normally only be used for port implementations. If you need it in your client
|
||||||
@ -45,6 +47,8 @@ public class InternalContext {
|
|||||||
public final static long NETWORK_NONCE_TRIALS_PER_BYTE = 1000;
|
public final static long NETWORK_NONCE_TRIALS_PER_BYTE = 1000;
|
||||||
public final static long NETWORK_EXTRA_BYTES = 1000;
|
public final static long NETWORK_EXTRA_BYTES = 1000;
|
||||||
|
|
||||||
|
private final Executor threadPool = Executors.newCachedThreadPool();
|
||||||
|
|
||||||
private final Cryptography cryptography;
|
private final Cryptography cryptography;
|
||||||
private final Inventory inventory;
|
private final Inventory inventory;
|
||||||
private final NodeRegistry nodeRegistry;
|
private final NodeRegistry nodeRegistry;
|
||||||
@ -226,6 +230,9 @@ public class InternalContext {
|
|||||||
* for freshly received pubkeys will not be called. Instead the pubkey is added to the contact and stored on DB.
|
* for freshly received pubkeys will not be called. Instead the pubkey is added to the contact and stored on DB.
|
||||||
*/
|
*/
|
||||||
public void requestPubkey(final BitmessageAddress contact) {
|
public void requestPubkey(final BitmessageAddress contact) {
|
||||||
|
threadPool.execute(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
BitmessageAddress stored = addressRepository.getAddress(contact.getAddress());
|
BitmessageAddress stored = addressRepository.getAddress(contact.getAddress());
|
||||||
|
|
||||||
tryToFindMatchingPubkey(contact);
|
tryToFindMatchingPubkey(contact);
|
||||||
@ -252,6 +259,8 @@ public class InternalContext {
|
|||||||
.build();
|
.build();
|
||||||
proofOfWorkService.doProofOfWork(request);
|
proofOfWorkService.doProofOfWork(request);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void tryToFindMatchingPubkey(BitmessageAddress address) {
|
private void tryToFindMatchingPubkey(BitmessageAddress address) {
|
||||||
BitmessageAddress stored = addressRepository.getAddress(address.getAddress());
|
BitmessageAddress stored = addressRepository.getAddress(address.getAddress());
|
||||||
|
Loading…
Reference in New Issue
Block a user