Added support for new features in the RouterInfo API method.
Added support for API versioning.
This commit is contained in:
@ -7,6 +7,7 @@ import java.util.Random;
|
|||||||
|
|
||||||
import javax.net.ssl.HttpsURLConnection;
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
|
|
||||||
|
import net.i2p.itoopie.ItoopieVersion;
|
||||||
import net.i2p.itoopie.configuration.ConfigurationManager;
|
import net.i2p.itoopie.configuration.ConfigurationManager;
|
||||||
import net.i2p.itoopie.i2pcontrol.methods.Authenticate;
|
import net.i2p.itoopie.i2pcontrol.methods.Authenticate;
|
||||||
import net.i2p.itoopie.security.CertificateHelper;
|
import net.i2p.itoopie.security.CertificateHelper;
|
||||||
@ -77,11 +78,14 @@ public class JSONRPC2Interface {
|
|||||||
}
|
}
|
||||||
HashMap outParams = (HashMap) req.getParams();
|
HashMap outParams = (HashMap) req.getParams();
|
||||||
outParams.put("Token", token); // Add authentication token
|
outParams.put("Token", token); // Add authentication token
|
||||||
|
outParams.put("API", ItoopieVersion.I2PCONTROL_API_VERSION);
|
||||||
req.setParams(outParams);
|
req.setParams(outParams);
|
||||||
|
|
||||||
JSONRPC2Response resp = null;
|
JSONRPC2Response resp = null;
|
||||||
try {
|
try {
|
||||||
resp = session.send(req);
|
resp = session.send(req);
|
||||||
|
System.out.println("Request: " + req.toString());
|
||||||
|
System.out.println("Response: " + resp.toString());
|
||||||
JSONRPC2Error err = resp.getError();
|
JSONRPC2Error err = resp.getError();
|
||||||
if (err != null) {
|
if (err != null) {
|
||||||
switch (err.getCode()) {
|
switch (err.getCode()) {
|
||||||
@ -128,11 +132,20 @@ public class JSONRPC2Interface {
|
|||||||
token = Authenticate.execute();
|
token = Authenticate.execute();
|
||||||
throw new FailedRequestException();
|
throw new FailedRequestException();
|
||||||
// break;
|
// break;
|
||||||
|
case -32005:
|
||||||
|
// I2PControl API version not provided
|
||||||
|
throw new InvalidI2PControlAPI(err.getMessage());
|
||||||
|
case -32006:
|
||||||
|
// I2PControl API version not supported
|
||||||
|
throw new InvalidI2PControlAPI(err.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return resp;
|
return resp;
|
||||||
} catch (FailedRequestException e) {
|
} catch (FailedRequestException e) {
|
||||||
return sendReq(req, ++tryNbr);
|
return sendReq(req, ++tryNbr);
|
||||||
|
} catch (InvalidI2PControlAPI e) {
|
||||||
|
_log.error(e);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,21 +16,42 @@ public class RouterInfo{
|
|||||||
* @author hottuna
|
* @author hottuna
|
||||||
*/
|
*/
|
||||||
public enum ROUTER_INFO implements Remote{
|
public enum ROUTER_INFO implements Remote{
|
||||||
VERSION { public boolean isReadable(){ return true;}
|
VERSION { public boolean isReadable(){ return true;}
|
||||||
public boolean isWritable(){ return false;}
|
public boolean isWritable(){ return false;}
|
||||||
public String toString() { return "i2p.router.version"; }},
|
public String toString() { return "i2p.router.version"; }},
|
||||||
|
|
||||||
UPTIME { public boolean isReadable(){ return true;}
|
UPTIME { public boolean isReadable(){ return true;}
|
||||||
public boolean isWritable(){ return false;}
|
public boolean isWritable(){ return false;}
|
||||||
public String toString() { return "i2p.router.uptime"; }},
|
public String toString() { return "i2p.router.uptime"; }},
|
||||||
|
|
||||||
STATUS { public boolean isReadable(){ return true;}
|
STATUS { public boolean isReadable(){ return true;}
|
||||||
public boolean isWritable(){ return false;}
|
public boolean isWritable(){ return false;}
|
||||||
public String toString() { return "i2p.router.status"; }},
|
public String toString() { return "i2p.router.status"; }},
|
||||||
|
|
||||||
NETWORK_STATUS { public boolean isReadable(){ return true;}
|
NETWORK_STATUS { public boolean isReadable(){ return true;}
|
||||||
public boolean isWritable(){ return false;}
|
public boolean isWritable(){ return false;}
|
||||||
public String toString() { return "i2p.router.net.status"; }}
|
public String toString() { return "i2p.router.net.status"; }},
|
||||||
|
|
||||||
|
BW_INBOUND_1S { public boolean isReadable(){ return true;}
|
||||||
|
public boolean isWritable(){ return false;}
|
||||||
|
public String toString() { return "i2p.router.net.bw.inbound.1s"; }},
|
||||||
|
|
||||||
|
BW_INBOUND_15S { public boolean isReadable(){ return true;}
|
||||||
|
public boolean isWritable(){ return false;}
|
||||||
|
public String toString() { return "i2p.router.net.bw.inbound.15s"; }},
|
||||||
|
|
||||||
|
BW_OUTBOUND_1S { public boolean isReadable(){ return true;}
|
||||||
|
public boolean isWritable(){ return false;}
|
||||||
|
public String toString() { return "i2p.router.net.bw.outbound.1s"; }},
|
||||||
|
|
||||||
|
BW_OUTBOUND_15S { public boolean isReadable(){ return true;}
|
||||||
|
public boolean isWritable(){ return false;}
|
||||||
|
public String toString() { return "i2p.router.net.bw.outbound.15s"; }},
|
||||||
|
|
||||||
|
TUNNELS_PARTICIPATING { public boolean isReadable(){ return true;}
|
||||||
|
public boolean isWritable(){ return false;}
|
||||||
|
public String toString() { return "i2p.router.net.tunnels.participating"; }}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
Reference in New Issue
Block a user