use of co.krypt.krypton.exception.TransportException in project krypton-android by kryptco.
the class NetworkMessage method bytes.
public byte[] bytes() throws TransportException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
out.write(header.getValue());
try {
out.write(message);
} catch (IOException e) {
throw new TransportException(e.getMessage());
}
return out.toByteArray();
}
use of co.krypt.krypton.exception.TransportException in project krypton-android by kryptco.
the class SNSTransport method registerWithAWS.
public synchronized void registerWithAWS() throws TransportException {
try {
AmazonSNSClient client = getClient();
CreatePlatformEndpointRequest request = new CreatePlatformEndpointRequest().withPlatformApplicationArn(PLATFORM_APPLICATION_ARN).withToken(token);
CreatePlatformEndpointResult result = client.createPlatformEndpoint(request);
setEndpointARN(result.getEndpointArn());
HashMap<String, String> enabledAttribute = new HashMap<>();
enabledAttribute.put("Enabled", "true");
SetEndpointAttributesRequest enableRequest = new SetEndpointAttributesRequest().withEndpointArn(endpointARN).withAttributes(enabledAttribute);
client.setEndpointAttributes(enableRequest);
} catch (AmazonClientException e) {
throw new TransportException(e.getMessage());
}
}
use of co.krypt.krypton.exception.TransportException in project krypton-android by kryptco.
the class SQSTransport method receiveMessages.
public static List<byte[]> receiveMessages(final Pairing pairing) throws TransportException {
final AmazonSQSClient client = getClient();
ReceiveMessageRequest request = new ReceiveMessageRequest(sendQueueURL(pairing));
request.setWaitTimeSeconds(10);
request.setMaxNumberOfMessages(10);
ReceiveMessageResult result = client.receiveMessage(request);
final List<DeleteMessageBatchRequestEntry> deleteEntries = new ArrayList<>();
ArrayList<byte[]> messages = new ArrayList<byte[]>();
for (Message m : result.getMessages()) {
deleteEntries.add(new DeleteMessageBatchRequestEntry(m.getMessageId(), m.getReceiptHandle()));
try {
messages.add(Base64.decode(m.getBody()));
} catch (Exception e) {
Log.e(TAG, "failed to decode message: " + e.getMessage());
}
}
if (!deleteEntries.isEmpty()) {
deleteThreadPool.submit(() -> {
try {
DeleteMessageBatchRequest deleteRequest = new DeleteMessageBatchRequest(sendQueueURL(pairing)).withEntries(deleteEntries);
client.deleteMessageBatch(deleteRequest);
} catch (Exception e) {
Log.e(TAG, "failed to delete messages: " + e.getMessage());
}
});
}
return messages;
}
use of co.krypt.krypton.exception.TransportException in project krypton-android by kryptco.
the class Silo method unpair.
public void unpair(Pairing pairing, boolean sendResponse) {
if (sendResponse) {
Response unpairResponse = new Response();
unpairResponse.requestID = "";
unpairResponse.unpairResponse = new UnpairResponse();
try {
send(pairing, unpairResponse);
} catch (CryptoException | TransportException e) {
e.printStackTrace();
}
}
synchronized (pairingsLock) {
pairingStorage.unpair(pairing);
activePairingsByUUID.remove(pairing.uuid);
SQSPoller poller = pollers.remove(pairing);
if (poller != null) {
poller.stop();
}
bluetoothTransport.remove(pairing);
}
}
Aggregations