mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-05-24 17:31:25 -04:00
Throw exception if address storage fails
This commit is contained in:
parent
ef7c2305fc
commit
c3f87609a8
3 changed files with 62 additions and 21 deletions
|
@ -23,6 +23,7 @@ import io.bitsquare.msg.listeners.BootstrapListener;
|
||||||
import io.bitsquare.network.BootstrapState;
|
import io.bitsquare.network.BootstrapState;
|
||||||
import io.bitsquare.network.ClientNode;
|
import io.bitsquare.network.ClientNode;
|
||||||
import io.bitsquare.network.ConnectionType;
|
import io.bitsquare.network.ConnectionType;
|
||||||
|
import io.bitsquare.network.NetworkException;
|
||||||
import io.bitsquare.network.Node;
|
import io.bitsquare.network.Node;
|
||||||
import io.bitsquare.network.tomp2p.TomP2PPeer;
|
import io.bitsquare.network.tomp2p.TomP2PPeer;
|
||||||
|
|
||||||
|
@ -126,7 +127,11 @@ public class TomP2PNode implements ClientNode {
|
||||||
public void onSuccess(@Nullable PeerDHT peerDHT) {
|
public void onSuccess(@Nullable PeerDHT peerDHT) {
|
||||||
if (peerDHT != null) {
|
if (peerDHT != null) {
|
||||||
TomP2PNode.this.peerDHT = peerDHT;
|
TomP2PNode.this.peerDHT = peerDHT;
|
||||||
setup();
|
try {
|
||||||
|
setup();
|
||||||
|
} catch (NetworkException e) {
|
||||||
|
Platform.runLater(() -> bootstrapListener.onFailed(e));
|
||||||
|
}
|
||||||
Platform.runLater(bootstrapListener::onCompleted);
|
Platform.runLater(bootstrapListener::onCompleted);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -144,10 +149,10 @@ public class TomP2PNode implements ClientNode {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setup() {
|
private void setup() throws NetworkException {
|
||||||
setupTimerForIPCheck();
|
setupTimerForIPCheck();
|
||||||
setupReplyHandler();
|
setupReplyHandler();
|
||||||
storeAddressAfterBootstrap();
|
storeAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shutDown() {
|
public void shutDown() {
|
||||||
|
@ -322,27 +327,20 @@ public class TomP2PNode implements ClientNode {
|
||||||
timer.scheduleAtFixedRate(new TimerTask() {
|
timer.scheduleAtFixedRate(new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (storedPeerAddress != null) {
|
if (storedPeerAddress != null && peerDHT != null
|
||||||
if (peerDHT != null && !storedPeerAddress.equals(peerDHT.peerAddress())) {
|
&& !storedPeerAddress.equals(peerDHT.peerAddress()))
|
||||||
try {
|
try {
|
||||||
storeAddress();
|
storeAddress();
|
||||||
} catch (IOException e) {
|
} catch (NetworkException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
log.error(e.toString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else {
|
|
||||||
log.error("storedPeerAddress is null. That should not happen. " +
|
|
||||||
"Seems there is a problem with DHT storage.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, checkIfIPChangedPeriod, checkIfIPChangedPeriod);
|
}, checkIfIPChangedPeriod, checkIfIPChangedPeriod);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void storeAddressAfterBootstrap() {
|
private void storeAddress() throws NetworkException {
|
||||||
try {
|
try {
|
||||||
FuturePut futurePut = storeAddress();
|
FuturePut futurePut = saveAddress();
|
||||||
futurePut.addListener(new BaseFutureListener<BaseFuture>() {
|
futurePut.addListener(new BaseFutureListener<BaseFuture>() {
|
||||||
@Override
|
@Override
|
||||||
public void operationComplete(BaseFuture future) throws Exception {
|
public void operationComplete(BaseFuture future) throws Exception {
|
||||||
|
@ -352,21 +350,25 @@ public class TomP2PNode implements ClientNode {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
log.error("storedPeerAddress not successful");
|
log.error("storedPeerAddress not successful");
|
||||||
|
throw new NetworkException("Storing address was not successful. Reason: "
|
||||||
|
+ future.failedReason());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exceptionCaught(Throwable t) throws Exception {
|
public void exceptionCaught(Throwable t) throws Exception {
|
||||||
log.error("Error at storedPeerAddress " + t.toString());
|
log.error("Exception at storedPeerAddress " + t.toString());
|
||||||
|
throw new NetworkException("Exception at storeAddress.", t);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
log.error("Error at storePeerAddress " + e.toString());
|
log.error("Exception at storePeerAddress " + e.toString());
|
||||||
|
throw new NetworkException("Exception at storeAddress.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private FuturePut storeAddress() throws IOException {
|
private FuturePut saveAddress() throws IOException {
|
||||||
Number160 locationKey = Utils.makeSHAHash(keyPair.getPublic().getEncoded());
|
Number160 locationKey = Utils.makeSHAHash(keyPair.getPublic().getEncoded());
|
||||||
Data data = new Data(new TomP2PPeer(peerDHT.peerAddress()));
|
Data data = new Data(new TomP2PPeer(peerDHT.peerAddress()));
|
||||||
log.debug("storePeerAddress " + peerDHT.peerAddress().toString());
|
log.debug("storePeerAddress " + peerDHT.peerAddress().toString());
|
||||||
|
|
38
src/main/java/io/bitsquare/network/NetworkException.java
Normal file
38
src/main/java/io/bitsquare/network/NetworkException.java
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Bitsquare.
|
||||||
|
*
|
||||||
|
* Bitsquare is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Bitsquare is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||||
|
* License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.bitsquare.network;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@SuppressWarnings("serializable")
|
||||||
|
public class NetworkException extends IOException {
|
||||||
|
|
||||||
|
public NetworkException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NetworkException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NetworkException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
<logger name="io.bitsquare.gui.CachedViewCB" level="WARN"/>
|
<logger name="io.bitsquare.gui.CachedViewCB" level="WARN"/>
|
||||||
<logger name="io.bitsquare.gui.util.Profiler" level="WARN"/>
|
<logger name="io.bitsquare.gui.util.Profiler" level="WARN"/>
|
||||||
<logger name="io.bitsquare.persistence.Persistence" level="WARN"/>
|
<logger name="io.bitsquare.persistence.Persistence" level="WARN"/>
|
||||||
|
<logger name="io.bitsquare.locale.BSResources" level="OFF"/>
|
||||||
|
|
||||||
|
|
||||||
<logger name="org.bitcoinj.core.BitcoinSerializer" level="WARN"/>
|
<logger name="org.bitcoinj.core.BitcoinSerializer" level="WARN"/>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue