Add null check

This commit is contained in:
Manfred Karrer 2015-04-05 16:59:28 +02:00
parent 22338a8d4d
commit f4f1f9f451
4 changed files with 13 additions and 5 deletions

View file

@ -22,7 +22,7 @@ import java.util.List;
public interface BootstrapNodes { public interface BootstrapNodes {
Node DIGITAL_OCEAN_1 = Node.at("digitalocean1.bitsquare.io", "188.226.179.109"); Node DIGITAL_OCEAN_1 = Node.at("digitalocean1.bitsquare.io", "188.226.179.109", 7366);
/** /**
* Alias to the default bootstrap node. * Alias to the default bootstrap node.
@ -33,7 +33,7 @@ public interface BootstrapNodes {
* A locally-running BootstrapNode instance. * A locally-running BootstrapNode instance.
* Typically used only for testing. Not included in results from {@link #all()}. * Typically used only for testing. Not included in results from {@link #all()}.
*/ */
Node LOCALHOST = Node.at("localhost", "127.0.0.1"); Node LOCALHOST = Node.at("localhost", "127.0.0.1", 7366);
/** /**
* All known public bootstrap nodes. * All known public bootstrap nodes.

View file

@ -85,6 +85,7 @@ public final class Node {
try { try {
ServerSocket server = new ServerSocket(0); ServerSocket server = new ServerSocket(0);
port = server.getLocalPort(); port = server.getLocalPort();
log.debug("Random system port used for client: {}", port);
server.close(); server.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();

View file

@ -34,6 +34,7 @@ import javax.inject.Inject;
import net.tomp2p.dht.FutureGet; import net.tomp2p.dht.FutureGet;
import net.tomp2p.dht.FuturePut; import net.tomp2p.dht.FuturePut;
import net.tomp2p.dht.FutureRemove;
import net.tomp2p.futures.BaseFuture; import net.tomp2p.futures.BaseFuture;
import net.tomp2p.futures.BaseFutureAdapter; import net.tomp2p.futures.BaseFutureAdapter;
import net.tomp2p.futures.BaseFutureListener; import net.tomp2p.futures.BaseFutureListener;
@ -174,8 +175,11 @@ public class TomP2PAddressService extends TomP2PDHTService implements AddressSer
private void removeAddress() { private void removeAddress() {
try { try {
boolean success = removeDataFromMyProtectedDomain(locationKey).awaitUninterruptibly(1000); FutureRemove futureRemove = removeDataFromMyProtectedDomain(locationKey);
log.debug("removeDataFromMyProtectedDomain success=" + success); if (futureRemove != null) {
boolean success = futureRemove.awaitUninterruptibly(1000);
log.debug("removeDataFromMyProtectedDomain success=" + success);
}
} catch (Throwable t) { } catch (Throwable t) {
t.printStackTrace(); t.printStackTrace();
log.error(t.getMessage()); log.error(t.getMessage());

View file

@ -130,7 +130,10 @@ public class TomP2PDHTService extends TomP2PService implements DHTService {
*/ */
public FutureRemove removeDataFromMyProtectedDomain(Number160 locationKey) { public FutureRemove removeDataFromMyProtectedDomain(Number160 locationKey) {
log.trace("removeDataOfProtectedDomain"); log.trace("removeDataOfProtectedDomain");
return peerDHT.remove(locationKey).domainKey(pubKeyHashForMyDomain).keyPair(keyPair).start(); if (peerDHT != null)
return peerDHT.remove(locationKey).domainKey(pubKeyHashForMyDomain).keyPair(keyPair).start();
else
return null;
} }
/** /**