mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-08-01 03:06:14 -04:00
Remove NetworkPreferencesModel
This commit is contained in:
parent
526727134f
commit
a81db94f25
3 changed files with 58 additions and 158 deletions
|
@ -1,136 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.gui.main.preferences.network;
|
|
||||||
|
|
||||||
import io.bitsquare.BitsquareException;
|
|
||||||
import io.bitsquare.gui.UIModel;
|
|
||||||
import io.bitsquare.msg.tomp2p.BootstrappedPeerFactory;
|
|
||||||
import io.bitsquare.msg.tomp2p.TomP2PNode;
|
|
||||||
import io.bitsquare.network.BootstrapState;
|
|
||||||
import io.bitsquare.network.Node;
|
|
||||||
|
|
||||||
import org.bitcoinj.core.NetworkParameters;
|
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
|
||||||
import com.google.inject.name.Named;
|
|
||||||
|
|
||||||
import net.tomp2p.peers.PeerSocketAddress;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
class NetworkPreferencesModel extends UIModel {
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(NetworkPreferencesModel.class);
|
|
||||||
|
|
||||||
final String bitcoinNetworkType;
|
|
||||||
final String p2pNetworkConnection;
|
|
||||||
final String p2pNetworkAddress;
|
|
||||||
final String bootstrapAddress;
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Constructor
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
NetworkPreferencesModel(NetworkParameters networkParameters,
|
|
||||||
BootstrappedPeerFactory bootstrappedPeerFactory,
|
|
||||||
TomP2PNode tomP2PNode,
|
|
||||||
@Named(BootstrappedPeerFactory.BOOTSTRAP_NODE_KEY) Node bootstrapNode) {
|
|
||||||
|
|
||||||
switch (networkParameters.getId()) {
|
|
||||||
case NetworkParameters.ID_REGTEST:
|
|
||||||
bitcoinNetworkType = "Regtest";
|
|
||||||
break;
|
|
||||||
case NetworkParameters.ID_TESTNET:
|
|
||||||
bitcoinNetworkType = "Testnet";
|
|
||||||
break;
|
|
||||||
case NetworkParameters.ID_MAINNET:
|
|
||||||
bitcoinNetworkType = "Mainnet";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
bitcoinNetworkType = "Undefined";
|
|
||||||
throw new BitsquareException("Invalid networkParameters " + networkParameters.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
PeerSocketAddress socketAddress = tomP2PNode.getPeerDHT().peerAddress().peerSocketAddress();
|
|
||||||
p2pNetworkAddress = "IP: " + socketAddress.inetAddress().getHostAddress()
|
|
||||||
+ ", TCP port: " + socketAddress.tcpPort()
|
|
||||||
+ ", UDP port: " + socketAddress.udpPort();
|
|
||||||
|
|
||||||
bootstrapAddress = "ID: " + bootstrapNode.getName()
|
|
||||||
+ ", IP: " + bootstrapNode.getIp()
|
|
||||||
+ ", Port: " + bootstrapNode.getPortAsString();
|
|
||||||
|
|
||||||
BootstrapState state = bootstrappedPeerFactory.bootstrapState.get();
|
|
||||||
if (state == BootstrapState.DIRECT_SUCCESS)
|
|
||||||
p2pNetworkConnection = "Direct connection";
|
|
||||||
else if (state == BootstrapState.NAT_SUCCESS)
|
|
||||||
p2pNetworkConnection = "Connected with automatic port forwarding";
|
|
||||||
else if (state == BootstrapState.RELAY_SUCCESS)
|
|
||||||
p2pNetworkConnection = "Relayed by other peers";
|
|
||||||
else
|
|
||||||
throw new BitsquareException("Invalid BootstrapState " + state);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Lifecycle
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
@SuppressWarnings("EmptyMethod")
|
|
||||||
@Override
|
|
||||||
public void initialize() {
|
|
||||||
super.initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("EmptyMethod")
|
|
||||||
@Override
|
|
||||||
public void activate() {
|
|
||||||
super.activate();
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("EmptyMethod")
|
|
||||||
@Override
|
|
||||||
public void deactivate() {
|
|
||||||
super.deactivate();
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("EmptyMethod")
|
|
||||||
@Override
|
|
||||||
public void terminate() {
|
|
||||||
super.terminate();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Methods
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Getters
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Private
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -17,24 +17,75 @@
|
||||||
|
|
||||||
package io.bitsquare.gui.main.preferences.network;
|
package io.bitsquare.gui.main.preferences.network;
|
||||||
|
|
||||||
|
import io.bitsquare.BitsquareException;
|
||||||
import io.bitsquare.gui.PresentationModel;
|
import io.bitsquare.gui.PresentationModel;
|
||||||
|
import io.bitsquare.msg.tomp2p.BootstrappedPeerFactory;
|
||||||
|
import io.bitsquare.msg.tomp2p.TomP2PNode;
|
||||||
|
import io.bitsquare.network.BootstrapState;
|
||||||
|
import io.bitsquare.network.Node;
|
||||||
|
|
||||||
|
import org.bitcoinj.core.NetworkParameters;
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
import com.google.inject.name.Named;
|
||||||
|
|
||||||
|
import net.tomp2p.peers.PeerSocketAddress;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class NetworkPreferencesPM extends PresentationModel<NetworkPreferencesModel> {
|
public class NetworkPreferencesPM extends PresentationModel {
|
||||||
private static final Logger log = LoggerFactory.getLogger(NetworkPreferencesPM.class);
|
private static final Logger log = LoggerFactory.getLogger(NetworkPreferencesPM.class);
|
||||||
|
|
||||||
|
final String bitcoinNetworkType;
|
||||||
|
final String p2pNetworkConnection;
|
||||||
|
final String p2pNetworkAddress;
|
||||||
|
final String bootstrapAddress;
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
NetworkPreferencesPM(NetworkPreferencesModel model) {
|
NetworkPreferencesPM(NetworkParameters networkParameters,
|
||||||
super(model);
|
BootstrappedPeerFactory bootstrappedPeerFactory,
|
||||||
|
TomP2PNode tomP2PNode,
|
||||||
|
@Named(BootstrappedPeerFactory.BOOTSTRAP_NODE_KEY) Node bootstrapNode) {
|
||||||
|
|
||||||
|
switch (networkParameters.getId()) {
|
||||||
|
case NetworkParameters.ID_REGTEST:
|
||||||
|
bitcoinNetworkType = "Regtest";
|
||||||
|
break;
|
||||||
|
case NetworkParameters.ID_TESTNET:
|
||||||
|
bitcoinNetworkType = "Testnet";
|
||||||
|
break;
|
||||||
|
case NetworkParameters.ID_MAINNET:
|
||||||
|
bitcoinNetworkType = "Mainnet";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
bitcoinNetworkType = "Undefined";
|
||||||
|
throw new BitsquareException("Invalid networkParameters " + networkParameters.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
PeerSocketAddress socketAddress = tomP2PNode.getPeerDHT().peerAddress().peerSocketAddress();
|
||||||
|
p2pNetworkAddress = "IP: " + socketAddress.inetAddress().getHostAddress()
|
||||||
|
+ ", TCP port: " + socketAddress.tcpPort()
|
||||||
|
+ ", UDP port: " + socketAddress.udpPort();
|
||||||
|
|
||||||
|
bootstrapAddress = "ID: " + bootstrapNode.getName()
|
||||||
|
+ ", IP: " + bootstrapNode.getIp()
|
||||||
|
+ ", Port: " + bootstrapNode.getPortAsString();
|
||||||
|
|
||||||
|
BootstrapState state = bootstrappedPeerFactory.bootstrapState.get();
|
||||||
|
if (state == BootstrapState.DIRECT_SUCCESS)
|
||||||
|
p2pNetworkConnection = "Direct connection";
|
||||||
|
else if (state == BootstrapState.NAT_SUCCESS)
|
||||||
|
p2pNetworkConnection = "Connected with automatic port forwarding";
|
||||||
|
else if (state == BootstrapState.RELAY_SUCCESS)
|
||||||
|
p2pNetworkConnection = "Relayed by other peers";
|
||||||
|
else
|
||||||
|
throw new BitsquareException("Invalid BootstrapState " + state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -76,21 +127,6 @@ public class NetworkPreferencesPM extends PresentationModel<NetworkPreferencesMo
|
||||||
// Getters
|
// Getters
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
String bitcoinNetworkType() {
|
|
||||||
return model.bitcoinNetworkType;
|
|
||||||
}
|
|
||||||
|
|
||||||
String p2pNetworkConnection() {
|
|
||||||
return model.p2pNetworkConnection;
|
|
||||||
}
|
|
||||||
|
|
||||||
String p2pNetworkAddress() {
|
|
||||||
return model.p2pNetworkAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
String bootstrapAddress() {
|
|
||||||
return model.bootstrapAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Private
|
// Private
|
||||||
|
|
|
@ -65,10 +65,10 @@ public class NetworkPreferencesViewCB extends CachedViewCB<NetworkPreferencesPM>
|
||||||
public void activate() {
|
public void activate() {
|
||||||
super.activate();
|
super.activate();
|
||||||
|
|
||||||
bitcoinNetworkType.setText(presentationModel.bitcoinNetworkType());
|
bitcoinNetworkType.setText(presentationModel.bitcoinNetworkType);
|
||||||
p2pNetworkConnection.setText(presentationModel.p2pNetworkConnection());
|
p2pNetworkConnection.setText(presentationModel.p2pNetworkConnection);
|
||||||
p2pNetworkAddress.setText(presentationModel.p2pNetworkAddress());
|
p2pNetworkAddress.setText(presentationModel.p2pNetworkAddress);
|
||||||
bootstrapAddress.setText(presentationModel.bootstrapAddress());
|
bootstrapAddress.setText(presentationModel.bootstrapAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("EmptyMethod")
|
@SuppressWarnings("EmptyMethod")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue