Search in sources :

Example 1 with TransportException

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();
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) TransportException(co.krypt.krypton.exception.TransportException)

Example 2 with TransportException

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());
    }
}
Also used : HashMap(java.util.HashMap) SetEndpointAttributesRequest(com.amazonaws.services.sns.model.SetEndpointAttributesRequest) CreatePlatformEndpointResult(com.amazonaws.services.sns.model.CreatePlatformEndpointResult) AmazonClientException(com.amazonaws.AmazonClientException) CreatePlatformEndpointRequest(com.amazonaws.services.sns.model.CreatePlatformEndpointRequest) AmazonSNSClient(com.amazonaws.services.sns.AmazonSNSClient) TransportException(co.krypt.krypton.exception.TransportException)

Example 3 with TransportException

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;
}
Also used : DeleteMessageBatchRequest(com.amazonaws.services.sqs.model.DeleteMessageBatchRequest) ReceiveMessageRequest(com.amazonaws.services.sqs.model.ReceiveMessageRequest) Message(com.amazonaws.services.sqs.model.Message) NetworkMessage(co.krypt.krypton.protocol.NetworkMessage) ArrayList(java.util.ArrayList) AmazonSQSClient(com.amazonaws.services.sqs.AmazonSQSClient) DeleteMessageBatchRequestEntry(com.amazonaws.services.sqs.model.DeleteMessageBatchRequestEntry) TransportException(co.krypt.krypton.exception.TransportException) ReceiveMessageResult(com.amazonaws.services.sqs.model.ReceiveMessageResult)

Example 4 with TransportException

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);
    }
}
Also used : HostsResponse(co.krypt.krypton.protocol.HostsResponse) GitSignResponse(co.krypt.krypton.protocol.GitSignResponse) MeResponse(co.krypt.krypton.protocol.MeResponse) SignResponse(co.krypt.krypton.protocol.SignResponse) UnpairResponse(co.krypt.krypton.protocol.UnpairResponse) AckResponse(co.krypt.krypton.protocol.AckResponse) Response(co.krypt.krypton.protocol.Response) SQSPoller(co.krypt.krypton.transport.SQSPoller) CryptoException(co.krypt.krypton.exception.CryptoException) TransportException(co.krypt.krypton.exception.TransportException) UnpairResponse(co.krypt.krypton.protocol.UnpairResponse)

Aggregations

TransportException (co.krypt.krypton.exception.TransportException)4 CryptoException (co.krypt.krypton.exception.CryptoException)1 AckResponse (co.krypt.krypton.protocol.AckResponse)1 GitSignResponse (co.krypt.krypton.protocol.GitSignResponse)1 HostsResponse (co.krypt.krypton.protocol.HostsResponse)1 MeResponse (co.krypt.krypton.protocol.MeResponse)1 NetworkMessage (co.krypt.krypton.protocol.NetworkMessage)1 Response (co.krypt.krypton.protocol.Response)1 SignResponse (co.krypt.krypton.protocol.SignResponse)1 UnpairResponse (co.krypt.krypton.protocol.UnpairResponse)1 SQSPoller (co.krypt.krypton.transport.SQSPoller)1 AmazonClientException (com.amazonaws.AmazonClientException)1 AmazonSNSClient (com.amazonaws.services.sns.AmazonSNSClient)1 CreatePlatformEndpointRequest (com.amazonaws.services.sns.model.CreatePlatformEndpointRequest)1 CreatePlatformEndpointResult (com.amazonaws.services.sns.model.CreatePlatformEndpointResult)1 SetEndpointAttributesRequest (com.amazonaws.services.sns.model.SetEndpointAttributesRequest)1 AmazonSQSClient (com.amazonaws.services.sqs.AmazonSQSClient)1 DeleteMessageBatchRequest (com.amazonaws.services.sqs.model.DeleteMessageBatchRequest)1 DeleteMessageBatchRequestEntry (com.amazonaws.services.sqs.model.DeleteMessageBatchRequestEntry)1 Message (com.amazonaws.services.sqs.model.Message)1