Search in sources :

Example 1 with AckResponse

use of co.krypt.krypton.protocol.AckResponse in project krypton-android by kryptco.

the class Silo method handle.

private void handle(Pairing pairing, Request request, String communicationMedium) throws Unrecoverable {
    // Allow 15 minutes of clock skew
    if (Math.abs(request.unixSeconds - (System.currentTimeMillis() / 1000)) > CLOCK_SKEW_TOLERANCE_SECONDS) {
        throw new ProtocolException("invalid request time");
    }
    if (request.body instanceof UnpairRequest) {
        unpair(pairing, false);
        new Analytics(context).postEvent("device", "unpair", "request", null, false);
    }
    synchronized ((Silo.class.getName() + request.requestID).intern()) {
        if (sendCachedResponseIfPresent(pairing, request)) {
            return;
        }
    }
    EventBus.getDefault().post(new TeamService.UpdateTeamHomeDataIfOutdated(context));
    lastRequestTimeSeconds.put(pairing, System.currentTimeMillis() / 1000);
    if (Policy.isApprovedNow(this, context, pairing, request)) {
        respondToRequest(pairing, request, true);
    } else {
        if (Policy.requestApproval(context, pairing, request)) {
            new Analytics(context).postEvent(request.analyticsCategory(), "requires approval", communicationMedium, null, false);
        }
        if (request.sendACK != null && request.sendACK) {
            Response ackResponse = Response.with(request);
            ackResponse.ackResponse = new AckResponse();
            send(pairing, ackResponse);
        }
    }
}
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) ProtocolException(co.krypt.krypton.exception.ProtocolException) TeamService(co.krypt.krypton.team.TeamService) AckResponse(co.krypt.krypton.protocol.AckResponse) UnpairRequest(co.krypt.krypton.protocol.UnpairRequest) Analytics(co.krypt.krypton.analytics.Analytics)

Aggregations

Analytics (co.krypt.krypton.analytics.Analytics)1 ProtocolException (co.krypt.krypton.exception.ProtocolException)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 Response (co.krypt.krypton.protocol.Response)1 SignResponse (co.krypt.krypton.protocol.SignResponse)1 UnpairRequest (co.krypt.krypton.protocol.UnpairRequest)1 UnpairResponse (co.krypt.krypton.protocol.UnpairResponse)1 TeamService (co.krypt.krypton.team.TeamService)1