Added I2PControl method for getting I2PControl info.
This commit is contained in:
@ -96,8 +96,8 @@ public class Main {
|
||||
WindowHandler.toggleFrames();
|
||||
|
||||
|
||||
reseedMonitor = new Timer();
|
||||
// Start running periodic task after 2 minutes, run periodically every 10th minute.
|
||||
reseedMonitor = new Timer();
|
||||
reseedMonitor.scheduleAtFixedRate(new ReseedMonitor(), 2*60*1000, 10*60*1000);
|
||||
|
||||
//testStuff(); // Delete Me
|
||||
|
@ -16,6 +16,7 @@ import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
@ -43,7 +44,6 @@ import org.apache.commons.logging.LogFactory;
|
||||
import java.awt.Component;
|
||||
|
||||
public class SettingsFrame extends RegisteredFrame{
|
||||
private static final Log _log = LogFactory.getLog(SettingsFrame.class);
|
||||
|
||||
private enum LOCAL_SAVE_STATUS {
|
||||
SAVE_OK,
|
||||
@ -59,20 +59,46 @@ public class SettingsFrame extends RegisteredFrame{
|
||||
NO_CHANGES { public String toString(){return Transl._("No changes found, settings not saved.");} }
|
||||
};
|
||||
|
||||
private interface Address { public String getAddress();}
|
||||
private enum ADDRESSES implements Address {
|
||||
LOCAL { public String getAddress(){ return "127.0.0.1";}
|
||||
public String toString(){ return Transl._("local host (127.0.0.1)"); }},
|
||||
|
||||
LAN_192_168 { public String getAddress(){ return "192.168.0.0";}
|
||||
public String toString(){ return Transl._("lan host (192.168.*.*)"); }},
|
||||
|
||||
LAN_10 { public String getAddress(){ return "10.0.0.0";}
|
||||
public String toString(){ return Transl._("lan host (10.*.*.*)"); }},
|
||||
|
||||
ANY { public String getAddress(){ return "0.0.0.0";}
|
||||
public String toString(){ return Transl._("any host (*.*.*.*)"); }}
|
||||
};
|
||||
|
||||
|
||||
private static final Log _log = LogFactory.getLog(SettingsFrame.class);
|
||||
private static final HashMap<String, ADDRESSES> reverseAddressMap;
|
||||
private static Boolean instanceShown = false;
|
||||
|
||||
// NetworkPanel
|
||||
// ConnectPanel
|
||||
private JTextField txtRouterIP;
|
||||
private JTextField txtRouterPort;
|
||||
private JPasswordField passwordField;
|
||||
// PasswordPanel
|
||||
// ChangePanel
|
||||
private JComboBox comboAddress;
|
||||
private int currentComboAddressOption = 0;
|
||||
private JTextField txtNewPort;
|
||||
private JPasswordField txtNewPassword;
|
||||
private JPasswordField txtRetypeNewPassword;
|
||||
// PortPanel
|
||||
private JTextField txtNewPort;
|
||||
|
||||
private ConfigurationManager _conf;
|
||||
|
||||
static {
|
||||
reverseAddressMap = new HashMap<String,ADDRESSES>();
|
||||
for (ADDRESSES n : ADDRESSES.values()){
|
||||
reverseAddressMap.put(n.toString(), n);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
@ -94,6 +120,7 @@ public class SettingsFrame extends RegisteredFrame{
|
||||
*/
|
||||
private SettingsFrame() {
|
||||
_conf = ConfigurationManager.getInstance();
|
||||
GUIHelper.setDefaultStyle();
|
||||
initialize();
|
||||
}
|
||||
|
||||
@ -121,43 +148,33 @@ public class SettingsFrame extends RegisteredFrame{
|
||||
GUIHelper.setDefaultStyle();
|
||||
|
||||
setTitle("itoopie Settings");
|
||||
setBounds(0, 0, 450, 260);
|
||||
setBounds(0, 0, 450, 310);
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
getContentPane().setLayout(null);
|
||||
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
|
||||
JPanel networkPanel = new JPanel();
|
||||
networkPanel.setLayout(null);
|
||||
networkPanel.setBounds(0, 0, 426, 89);
|
||||
getContentPane().add(networkPanel);
|
||||
setupNetworkPanel(networkPanel);
|
||||
JPanel connectPanel = new JPanel();
|
||||
connectPanel.setLayout(null);
|
||||
connectPanel.setBounds(0, 0, 426, 99);
|
||||
getContentPane().add(connectPanel);
|
||||
setupConnectPanel(connectPanel);
|
||||
|
||||
|
||||
JSeparator separator = new JSeparator(SwingConstants.HORIZONTAL);
|
||||
separator.setBounds((96)/2, 90, (getWidth()-96), 1);
|
||||
separator.setBounds((96)/2, 108, (getWidth()-96), 2);
|
||||
getContentPane().add(separator);
|
||||
|
||||
JPanel newPasswordPanel = new JPanel();
|
||||
newPasswordPanel.setLayout(null);
|
||||
newPasswordPanel.setBounds(0, 90, 426, 64);
|
||||
getContentPane().add(newPasswordPanel);
|
||||
setupNewPasswordPanel(newPasswordPanel);
|
||||
JPanel newChangePanel = new JPanel();
|
||||
newChangePanel.setLayout(null);
|
||||
newChangePanel.setBounds(0, 110, 426, 135);
|
||||
getContentPane().add(newChangePanel);
|
||||
setupChangePanel(newChangePanel);
|
||||
|
||||
|
||||
separator = new JSeparator(SwingConstants.HORIZONTAL);
|
||||
separator.setBounds((96)/2, 155, (getWidth()-96), 1);
|
||||
getContentPane().add(separator);
|
||||
|
||||
|
||||
JPanel newPortPanel = new JPanel();
|
||||
newPortPanel.setLayout(null);
|
||||
newPortPanel.setBounds(0, 155, 426, 35);
|
||||
getContentPane().add(newPortPanel);
|
||||
setupNewPortPanel(newPortPanel);
|
||||
|
||||
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
|
||||
buttonPanel.setBounds(0, 200, getWidth()-10, 35);
|
||||
buttonPanel.setBounds(0, getHeight()-60, getWidth()-10, 35);
|
||||
getContentPane().add(buttonPanel);
|
||||
|
||||
|
||||
@ -228,93 +245,106 @@ public class SettingsFrame extends RegisteredFrame{
|
||||
validate();
|
||||
}
|
||||
|
||||
private void setupNetworkPanel(JPanel networkPanel){
|
||||
JLabel lblI2PControl = new JLabel(Transl._("Network:"));
|
||||
lblI2PControl.setBounds(10, 10, 120, 15);
|
||||
private void setupConnectPanel(JPanel networkPanel){
|
||||
JLabel lblI2PControl = new JLabel(Transl._("Connect to I2PControl"));
|
||||
lblI2PControl.setBounds(10, 10, 228, 15);
|
||||
networkPanel.add(lblI2PControl);
|
||||
lblI2PControl.setHorizontalAlignment(SwingConstants.RIGHT);
|
||||
|
||||
|
||||
JLabel lblRouterIP = new JLabel(Transl._("IP address:"));
|
||||
lblRouterIP.setBounds(138, 10, 100, 15);
|
||||
lblRouterIP.setBounds(138, 30, 100, 15);
|
||||
networkPanel.add(lblRouterIP);
|
||||
lblRouterIP.setHorizontalAlignment(SwingConstants.LEFT);
|
||||
lblRouterIP.setHorizontalAlignment(SwingConstants.RIGHT);
|
||||
|
||||
txtRouterIP = new JTextField();
|
||||
txtRouterIP.setBounds(240, 10, 90, 19);
|
||||
txtRouterIP.setBounds(240, 30, 90, 19);
|
||||
networkPanel.add(txtRouterIP);
|
||||
|
||||
|
||||
JLabel lblRouterPort = new JLabel(Transl._("Port:"));
|
||||
lblRouterPort.setBounds(138, 35, 100, 15);
|
||||
lblRouterPort.setBounds(10, 55, 228, 15);
|
||||
networkPanel.add(lblRouterPort);
|
||||
lblRouterPort.setHorizontalAlignment(SwingConstants.LEFT);
|
||||
lblRouterPort.setHorizontalAlignment(SwingConstants.RIGHT);
|
||||
|
||||
txtRouterPort = new JTextField();
|
||||
txtRouterPort.setBounds(240, 35, 45, 19);
|
||||
txtRouterPort.setBounds(240, 55, 45, 19);
|
||||
networkPanel.add(txtRouterPort);
|
||||
|
||||
|
||||
JLabel lblRouterPassword = new JLabel(Transl._("Password:"));
|
||||
lblRouterPassword.setBounds(138, 60, 100, 15);
|
||||
lblRouterPassword.setBounds(10, 80, 228, 15);
|
||||
networkPanel.add(lblRouterPassword);
|
||||
lblRouterPassword.setHorizontalAlignment(SwingConstants.LEFT);
|
||||
lblRouterPassword.setHorizontalAlignment(SwingConstants.RIGHT);
|
||||
|
||||
passwordField = new JPasswordField();
|
||||
passwordField.setBounds(240, 60, 90, 19);
|
||||
passwordField.setBounds(240, 80, 90, 19);
|
||||
networkPanel.add(passwordField);
|
||||
}
|
||||
|
||||
|
||||
private void setupNewPasswordPanel(JPanel pwdPanel){
|
||||
private void setupChangePanel(JPanel changePanel){
|
||||
JLabel lblChange = new JLabel(Transl._("Change I2PControl"));
|
||||
lblChange.setBounds(10, 10, 228, 15);
|
||||
changePanel.add(lblChange);
|
||||
lblChange.setHorizontalAlignment(SwingConstants.RIGHT);
|
||||
|
||||
|
||||
JLabel lblAddress = new JLabel(Transl._("Change address:"));
|
||||
lblAddress.setBounds(10, 30, 228, 15);
|
||||
changePanel.add(lblAddress);
|
||||
lblAddress.setHorizontalAlignment(SwingConstants.RIGHT);
|
||||
|
||||
comboAddress = new JComboBox();
|
||||
setupAddressComboBox(comboAddress);
|
||||
comboAddress.setBounds(240, 30, 170, 19);
|
||||
changePanel.add(comboAddress);
|
||||
|
||||
JLabel lblPort = new JLabel(Transl._("Change port:"));
|
||||
lblPort.setBounds(10, 60, 228, 15);
|
||||
changePanel.add(lblPort);
|
||||
lblPort.setHorizontalAlignment(SwingConstants.RIGHT);
|
||||
|
||||
txtNewPort = new JTextField();
|
||||
txtNewPort.setBounds(240, 60, 45, 19);
|
||||
changePanel.add(txtNewPort);
|
||||
|
||||
|
||||
JLabel lblNewPassword = new JLabel(Transl._("New password:"));
|
||||
lblNewPassword.setBounds(10, 10, 120, 15);
|
||||
pwdPanel.add(lblNewPassword);
|
||||
lblNewPassword.setBounds(10, 90, 228, 15);
|
||||
changePanel.add(lblNewPassword);
|
||||
lblNewPassword.setHorizontalAlignment(SwingConstants.RIGHT);
|
||||
|
||||
|
||||
JLabel lblNewPassword2 = new JLabel(Transl._("Password:"));
|
||||
lblNewPassword2.setBounds(138, 10, 100, 15);
|
||||
pwdPanel.add(lblNewPassword2);
|
||||
lblNewPassword2.setHorizontalAlignment(SwingConstants.LEFT);
|
||||
|
||||
txtNewPassword = new JPasswordField();
|
||||
txtNewPassword.setBounds(240, 10, 90, 19);
|
||||
pwdPanel.add(txtNewPassword);
|
||||
txtNewPassword.setBounds(240, 90, 90, 19);
|
||||
changePanel.add(txtNewPassword);
|
||||
|
||||
|
||||
JLabel lblRetypeNewPassword = new JLabel(Transl._("Repeat:"));
|
||||
lblRetypeNewPassword.setBounds(138, 35, 100, 15);
|
||||
pwdPanel.add(lblRetypeNewPassword);
|
||||
lblRetypeNewPassword.setHorizontalAlignment(SwingConstants.LEFT);
|
||||
JLabel lblRetypeNewPassword = new JLabel(Transl._("Repeat password:"));
|
||||
lblRetypeNewPassword.setBounds(10, 115, 228, 15);
|
||||
changePanel.add(lblRetypeNewPassword);
|
||||
lblRetypeNewPassword.setHorizontalAlignment(SwingConstants.RIGHT);
|
||||
|
||||
txtRetypeNewPassword = new JPasswordField();
|
||||
txtRetypeNewPassword.setBounds(240, 35, 90, 19);
|
||||
pwdPanel.add(txtRetypeNewPassword);
|
||||
txtRetypeNewPassword.setBounds(240, 115, 90, 19);
|
||||
changePanel.add(txtRetypeNewPassword);
|
||||
}
|
||||
|
||||
private void setupNewPortPanel(JPanel portPanel){
|
||||
JLabel lblPort = new JLabel(Transl._("New port:"));
|
||||
lblPort.setBounds(10, 10, 120, 15);
|
||||
portPanel.add(lblPort);
|
||||
lblPort.setHorizontalAlignment(SwingConstants.RIGHT);
|
||||
|
||||
|
||||
JLabel lblPort2 = new JLabel(Transl._("Port:"));
|
||||
lblPort2.setBounds(138, 10, 100, 15);
|
||||
portPanel.add(lblPort2);
|
||||
lblPort2.setHorizontalAlignment(SwingConstants.LEFT);
|
||||
|
||||
txtNewPort = new JTextField();
|
||||
txtNewPort.setBounds(240, 10, 45, 19);
|
||||
portPanel.add(txtNewPort);
|
||||
private void setupAddressComboBox(JComboBox comboBox) {
|
||||
for (ADDRESSES addr : ADDRESSES.values()){
|
||||
comboBox.addItem(addr.toString());
|
||||
}
|
||||
comboBox.setSelectedIndex(0);
|
||||
}
|
||||
|
||||
|
||||
private void populateSettings(){
|
||||
txtRouterIP.setText(_conf.getConf("server.hostname", "127.0.0.1"));
|
||||
txtRouterPort.setText(_conf.getConf("server.port", 7650)+"");
|
||||
passwordField.setText(_conf.getConf("server.password", "itoopie"));
|
||||
|
||||
GetI
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-access")
|
||||
@ -328,7 +358,7 @@ public class SettingsFrame extends RegisteredFrame{
|
||||
String portText = txtRouterPort.getText();
|
||||
String pwText = new String(passwordField.getPassword());
|
||||
|
||||
// // Exit SAVE_STATUS.NO_CHANGES if no changes are found. Possibly just a annoying check.
|
||||
// // Exit SAVE_STATUS.NO_CHANGES if no changes are found. Possibly just an annoying check.
|
||||
// if (ipText.equals(oldIP) && portText.equals(oldPort+"") && pwText.equals(oldPW))
|
||||
// return LOCAL_SAVE_STATUS.NO_CHANGES;
|
||||
|
||||
|
65
src/net/i2p/itoopie/i2pcontrol/methods/GetI2PControl.java
Normal file
65
src/net/i2p/itoopie/i2pcontrol/methods/GetI2PControl.java
Normal file
@ -0,0 +1,65 @@
|
||||
package net.i2p.itoopie.i2pcontrol.methods;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import net.i2p.itoopie.i2pcontrol.InvalidParametersException;
|
||||
import net.i2p.itoopie.i2pcontrol.InvalidPasswordException;
|
||||
import net.i2p.itoopie.i2pcontrol.JSONRPC2Interface;
|
||||
import net.i2p.itoopie.i2pcontrol.UnrecoverableFailedRequestException;
|
||||
import net.i2p.itoopie.i2pcontrol.methods.I2PControl.I2P_CONTROL;
|
||||
|
||||
import com.thetransactioncompany.jsonrpc2.JSONRPC2Request;
|
||||
import com.thetransactioncompany.jsonrpc2.JSONRPC2Response;
|
||||
import com.thetransactioncompany.jsonrpc2.client.JSONRPC2SessionException;
|
||||
|
||||
public class GetI2PControl {
|
||||
private final static Log _log = LogFactory.getLog(GetI2PControl.class);
|
||||
|
||||
|
||||
public static EnumMap<I2P_CONTROL, Object> execute(I2P_CONTROL ... settings)
|
||||
throws InvalidPasswordException, JSONRPC2SessionException, InvalidParametersException{
|
||||
|
||||
JSONRPC2Request req = new JSONRPC2Request("I2PControl", JSONRPC2Interface.incrNonce());
|
||||
|
||||
Map outParams = new HashMap();
|
||||
|
||||
for (I2P_CONTROL s : settings){
|
||||
if(s.isReadable()){
|
||||
outParams.put(s.toString(), null);
|
||||
}
|
||||
}
|
||||
req.setParams(outParams);
|
||||
|
||||
JSONRPC2Response resp = null;
|
||||
try {
|
||||
resp = JSONRPC2Interface.sendReq(req);
|
||||
HashMap map = (HashMap) resp.getResult();
|
||||
if (map != null){
|
||||
Set<Entry> inputSet = map.entrySet();
|
||||
EnumMap<I2P_CONTROL, Object> output = new EnumMap<I2P_CONTROL, Object>(I2P_CONTROL.class);
|
||||
// Present the result as an <Enum,Object> map.
|
||||
for (Entry e: inputSet){
|
||||
String key = (String) e.getKey();
|
||||
I2P_CONTROL I2PC = I2PControl.getEnum(key);
|
||||
// If the enum exists. They should exists, but safety first.
|
||||
if (I2PC != null){
|
||||
output.put(I2PC, e.getValue());
|
||||
}
|
||||
}
|
||||
return output;
|
||||
} else {
|
||||
return new EnumMap<I2P_CONTROL, Object>(I2P_CONTROL.class);
|
||||
}
|
||||
} catch (UnrecoverableFailedRequestException e) {
|
||||
_log.error("getI2PControl failed.", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -46,10 +46,10 @@ public class ReseedMonitor extends TimerTask{
|
||||
Boolean isReseeding = (Boolean) em.get(ROUTER_INFO.IS_RESEEDING);
|
||||
if (knownPeers != null && isReseeding != null){
|
||||
if (knownPeers < MIN_KNOWN_PEERS){
|
||||
_log.info("Few peers detected, initiating reseed..");
|
||||
HashMap<ROUTER_MANAGER, String> hm = new HashMap<ROUTER_MANAGER, String>();
|
||||
hm.put(ROUTER_MANAGER.RESEED, null);
|
||||
SetRouterManager.execute(hm);
|
||||
_log.info("Reseed initiated..");
|
||||
}
|
||||
}
|
||||
} catch (InvalidPasswordException e) {
|
||||
|
Reference in New Issue
Block a user