use of com.biglybt.core.messenger.PlatformMessengerException in project BiglyBT by BiglySoftware.
the class PlatformSubscriptionsMessenger method getSubscriptionBySID.
public static subscriptionDetails getSubscriptionBySID(byte[] sid, boolean is_anon) throws PlatformMessengerException {
checkEnabled(OP_GET_SUBS_BY_SID);
Map parameters = new HashMap();
List sid_list = new JSONArray();
sid_list.add(Base32.encode(sid));
parameters.put("subscription_ids", sid_list);
Map reply = dispatcher.syncInvoke(OP_GET_SUBS_BY_SID, parameters, is_anon);
for (int i = 0; i < sid_list.size(); i++) {
Map map = (Map) reply.get((String) sid_list.get(i));
if (map != null) {
subscriptionDetails details = new subscriptionDetails(map);
return (details);
}
}
throw (new PlatformMessengerException("Unknown sid '" + ByteFormatter.encodeString(sid) + "'"));
}
use of com.biglybt.core.messenger.PlatformMessengerException in project BiglyBT by BiglySoftware.
the class PlatformMessengerConfig method syncInvoke.
protected Map syncInvoke(String operationID, Map parameters, boolean forceProxy) throws PlatformMessengerException {
PlatformMessage message = new PlatformMessage("AZMSG", listener_id, operationID, parameters, 0);
if (!send_azid) {
message.setSendAZID(false);
}
message.setForceProxy(forceProxy);
final AESemaphore sem = new AESemaphore("PlatformMessengerConfig:syncInvoke");
final Object[] result = { null };
PlatformMessenger.queueMessage(message, new PlatformMessengerListener() {
@Override
public void messageSent(PlatformMessage message) {
}
@Override
public void replyReceived(PlatformMessage message, String replyType, Map reply) {
try {
if (replyType.equals(PlatformMessenger.REPLY_EXCEPTION)) {
String e_message = (String) reply.get("message");
if (e_message != null) {
result[0] = new PlatformMessengerException(e_message);
} else {
String text = (String) reply.get("text");
Throwable e = (Throwable) reply.get("Throwable");
if (text == null && e == null) {
result[0] = new PlatformMessengerException("Unknown error");
} else if (text == null) {
result[0] = new PlatformMessengerException("Failed to send RPC", e);
} else if (e == null) {
result[0] = new PlatformMessengerException(text);
} else {
result[0] = new PlatformMessengerException(text, e);
}
}
} else {
result[0] = reply;
}
} finally {
sem.release();
}
}
});
sem.reserve();
if (result[0] instanceof PlatformMessengerException) {
throw ((PlatformMessengerException) result[0]);
}
return ((Map) result[0]);
}
use of com.biglybt.core.messenger.PlatformMessengerException in project BiglyBT by BiglySoftware.
the class PlatformMetaSearchMessenger method getTemplate.
public static templateDetails getTemplate(String extension_key, long template_id) throws PlatformMessengerException {
Map parameters = getParameter(template_id);
if (extension_key != null) {
parameters.put("extension_key", extension_key);
}
Map reply = dispatcher.syncInvoke(OP_GET_TEMPLATE, parameters);
templateInfo info = getTemplateInfo(reply);
if (info == null) {
throw (new PlatformMessengerException("Invalid reply: " + reply));
}
String name = (String) reply.get("name");
String value = (String) reply.get("value");
String engine_type = (String) reply.get("engine_id");
if (name == null || value == null || engine_type == null) {
throw (new PlatformMessengerException("Invalid reply; field missing: " + reply));
}
int type;
if (engine_type.equals("json")) {
type = templateDetails.ENGINE_TYPE_JSON;
} else if (engine_type.equals("regexp")) {
type = templateDetails.ENGINE_TYPE_REGEXP;
} else {
throw (new PlatformMessengerException("Invalid type '" + engine_type + ": " + reply));
}
return (new templateDetails(info, type, name, value));
}
use of com.biglybt.core.messenger.PlatformMessengerException in project BiglyBT by BiglySoftware.
the class PlatformSubscriptionsMessenger method updateSubscription.
public static void updateSubscription(boolean create, String name, byte[] public_key, byte[] private_key, byte[] sid, int version, boolean is_anon, String content) throws PlatformMessengerException {
String operation = create ? OP_CREATE_SUBS : OP_UPDATE_SUBS;
checkEnabled(operation);
Map parameters = new HashMap();
String sid_str = Base32.encode(sid);
String pk_str = Base32.encode(public_key);
parameters.put("name", name);
parameters.put("subscription_id", sid_str);
parameters.put("version_number", new Long(version));
parameters.put("content", content);
if (create) {
parameters.put("public_key", pk_str);
}
try {
Signature sig = CryptoECCUtils.getSignature(CryptoECCUtils.rawdataToPrivkey(private_key));
sig.update((name + pk_str + sid_str + version + content).getBytes("UTF-8"));
byte[] sig_bytes = sig.sign();
/*
Signature verify = CryptoECCUtils.getSignature( CryptoECCUtils.rawdataToPubkey( public_key ));
verify.update( ( name + pk_str + sid_str + version + content ).getBytes( "UTF-8" ));
boolean ok = verify.verify( sig_bytes );
*/
parameters.put("signature", Base32.encode(sig_bytes));
dispatcher.syncInvoke(operation, parameters, is_anon);
} catch (Throwable e) {
throw (new PlatformMessengerException("Failed to create/update subscription", e));
}
}
Aggregations