private void parseClientSyncMetaData(ClientSync sync, ByteBuffer buf, int options, int payloadLength) throws PlatformEncDecException { sync.setRequestId(buf.getInt()); ClientSyncMetaData md = new ClientSyncMetaData(); if (hasOption(options, CLIENT_META_SYNC_TIMEOUT_OPTION)) { md.setTimeout((long) buf.getInt()); } if (hasOption(options, CLIENT_META_SYNC_KEY_HASH_OPTION)) { md.setEndpointPublicKeyHash(getNewByteBuffer(buf, PUBLIC_KEY_HASH_SIZE)); } if (hasOption(options, CLIENT_META_SYNC_PROFILE_HASH_OPTION)) { md.setProfileHash(getNewByteBuffer(buf, PROFILE_HASH_SIZE)); } if (hasOption(options, CLIENT_META_SYNC_SDK_TOKEN_OPTION)) { md.setSdkToken(getUtf8String(buf, Constants.SDK_TOKEN_SIZE)); } sync.setClientSyncMetaData(md); }
public String getAppToken() { return metaData.getApplicationToken(); }
protected EndpointObjectHash getEndpointObjectHash(ClientSync request) { return EndpointObjectHash.fromBytes( request.getClientSyncMetaData().getEndpointPublicKeyHash().array()); } }
private void addAppTokenToClientSyncMetaData(ClientSyncMetaData clientSyncMetaData) { clientSyncMetaData.setApplicationToken(getAppToken(clientSyncMetaData.getSdkToken())); }
metaData.setProfileHash(ByteBuffer.wrap(profile.getProfileHash())); context.setProfileSyncResponse(profileSyncResponse); LOG.debug("[{}][{}] fetching profile.", context.getEndpointKey(), context.getRequestHash()); EndpointObjectHash endpointHash = EndpointObjectHash.fromBytes( metaData.getEndpointPublicKeyHash().array()); profile = profileService.getProfile(endpointHash); LOG.trace("[{}][{}] fetched profile {}.", if (!Arrays.equals(profile.getProfileHash(), toByteArray(metaData.getProfileHash()))) { LOG.debug("[{}] Profile hash mismatch. Profile resync needed", context.getEndpointKey()); if (LOG.isTraceEnabled()) { MessageEncoderDecoder.bytesToHex(profile.getProfileHash())); LOG.trace("[{}] client profile hash is {}", context.getEndpointKey(), MessageEncoderDecoder.bytesToHex(toByteArray(metaData.getProfileHash()))); metaData.getApplicationToken(), context.getEndpointKey(), profile, false);
request.setRequestId(other.getRequestId()); request.getClientSyncMetaData() .setProfileHash(other.getClientSyncMetaData().getProfileHash()); LOG.debug("[{}] Updated request id and profile hash", channelUuid); ClientSync diff = new ClientSync(); diff.setClientSyncMetaData(other.getClientSyncMetaData()); diff.setUseConfigurationRawSchema(other.isUseConfigurationRawSchema()); if (request.getClientSyncMetaData().getApplicationToken() != null) { LOG.debug("Setting application token, as it was null: {}", request.getClientSyncMetaData().getApplicationToken()); diff.getClientSyncMetaData() .setApplicationToken(request.getClientSyncMetaData().getApplicationToken()); } else { LOG.trace("[{}] Application token is null for request", request);
private EndpointProfileDto updateEndpoint(String endpointId, int requestHash, ClientSyncMetaData metaData, ProfileClientSync request) { LOG.debug("[{}][{}] update endpoint. request: {}", endpointId, requestHash, request); EndpointObjectHash endpointKeyHash = EndpointObjectHash.fromBytes( toByteArray(metaData.getEndpointPublicKeyHash())); UpdateProfileRequest updateRequest = new UpdateProfileRequest( metaData.getApplicationToken(), endpointKeyHash, request.getEndpointAccessToken(), request.getProfileBody().array(), metaData.getSdkToken()); EndpointProfileDto endpointProfile = profileService.updateProfile(updateRequest); LOG.debug("profile updated. id: {}, endpointKeyHash: {}", endpointProfile.getId(), endpointProfile.getEndpointKeyHash()); return endpointProfile; }
private EndpointProfileDto registerEndpoint(String endpointId, int requestHash, ClientSyncMetaData metaData, ProfileClientSync request) { LOG.debug("[{}][{}] register endpoint. request: {}", endpointId, requestHash, request); byte[] endpointKey = toByteArray(request.getEndpointPublicKey()); byte[] profileBody = toByteArray(request.getProfileBody()); RegisterProfileRequest registerProfileRequest = new RegisterProfileRequest( metaData.getApplicationToken(), endpointKey, metaData.getSdkToken(), profileBody, request.getEndpointAccessToken()); EndpointProfileDto endpointProfile = profileService.registerProfile(registerProfileRequest); LOG.debug("profile registered. id: {}, endpointKeyHash: {}", endpointProfile.getId(), endpointProfile.getEndpointKeyHash()); return endpointProfile; }
/** * Return true if client sync information is valid or false if not. * * @return true if valid, false if not */ public boolean isValid() { ClientSyncMetaData md = this.getClientSyncMetaData(); // TODO: validate if public key hash matches hash of public key during // profile registration command. if (md.getProfileHash() == null) { ProfileClientSync profileRequest = this.getProfileSync(); if (profileRequest == null || profileRequest.getEndpointPublicKey() == null) { return false; } } return true; }
@Override public SyncContext syncUseConfigurationRawSchema(SyncContext context, boolean useConfigurationRawSchema) { EndpointProfileDto profile = context.getEndpointProfile(); if (profile.isUseConfigurationRawSchema() != useConfigurationRawSchema) { ClientSyncMetaData metaData = context.getMetaData(); EndpointObjectHash endpointKeyHash = EndpointObjectHash.fromBytes( toByteArray(metaData.getEndpointPublicKeyHash())); profile = profileService.updateProfile(metaData, endpointKeyHash, useConfigurationRawSchema); profile = syncProfileState( metaData.getApplicationToken(), context.getEndpointKey(), profile, false); context.setNotificationVersion(profile); } return context; }
private String getSdkToken(ClientSync request) { return request.getClientSyncMetaData().getSdkToken(); }
private long getDelay(SyncRequestMessage requestMessage, long start) { return requestMessage.getRequest() .getClientSyncMetaData() .getTimeout() - (System.currentTimeMillis() - start); }
private static ClientSyncMetaData convert(SyncRequestMetaData source) { if (source == null) { return null; } return new ClientSyncMetaData( null, source.getSdkToken(), source.getEndpointPublicKeyHash(), source.getProfileHash(), source.getTimeout()); }
? !clientSyncMetaData.equals(that.clientSyncMetaData) : that.clientSyncMetaData != null) { return false;
@Override public int hashCode() { int result = requestId; result = 31 * result + (clientSyncMetaData != null ? clientSyncMetaData.hashCode() : 0); result = 31 * result + (bootstrapSync != null ? bootstrapSync.hashCode() : 0); result = 31 * result + (profileSync != null ? profileSync.hashCode() : 0); result = 31 * result + (forceConfigurationSync ? 1 : 0); result = 31 * result + (configurationSync != null ? configurationSync.hashCode() : 0); result = 31 * result + (forceNotificationSync ? 1 : 0); result = 31 * result + (notificationSync != null ? notificationSync.hashCode() : 0); result = 31 * result + (userSync != null ? userSync.hashCode() : 0); result = 31 * result + (eventSync != null ? eventSync.hashCode() : 0); result = 31 * result + (logSync != null ? logSync.hashCode() : 0); result = 31 * result + (useConfigurationRawSchema ? 1 : 0); return result; }
@Override public EndpointProfileDto updateProfile(ClientSyncMetaData metaData, EndpointObjectHash keyHash, boolean useConfigurationRawSchema) { LOG.debug("Updating Profile for {}", keyHash); EndpointProfileDto dto = endpointService.findEndpointProfileByKeyHash(keyHash.getData()); AppSeqNumber appSeqNumber = cacheService.getAppSeqNumber(metaData.getApplicationToken()); SdkProfileDto sdkProfile = cacheService.getSdkProfileBySdkToken(metaData.getSdkToken()); Function<EndpointProfileDto, EndpointProfileDto> updateFunction = profile -> { populateVersionStates(appSeqNumber.getTenantId(), profile, sdkProfile); profile.setGroupState(new ArrayList<>()); profile.setUseConfigurationRawSchema(useConfigurationRawSchema); profile.setSequenceNumber(0); return profile; }; return updateProfile(updateFunction.apply(dto), (storedProfile, newProfile) -> { return updateFunction.apply(storedProfile); }); }
@Override public SyncContext syncConfiguration(SyncContext context, ConfigurationClientSync request) throws GetDeltaException { if (request != null) { GetDeltaResponse confResponse = calculateConfigurationDelta( context.getMetaData().getApplicationToken(), request, context); ConfigurationServerSync confSyncResponse = buildConfSyncResponse(confResponse); context.setConfigurationSyncResponse(confSyncResponse); } return context; }
@Override public SyncContext processEventListenerRequests(SyncContext context, EventClientSync request) { if (request != null) { ClientSyncMetaData metaData = context.getMetaData(); LOG.trace("[{}][{}] procesing event sync request {}.", context.getEndpointKey(), context.getRequestHash(), request); EventServerSync eventSyncResponse = processEventSyncResponse( context.getEndpointKey(), context.getRequestHash(), metaData.getApplicationToken(), request, context.getEndpointProfile()); context.setEventSyncResponse(eventSyncResponse); } return context; }
@Override public SyncContext syncNotification(SyncContext context, NotificationClientSync request) { if (request != null) { GetNotificationResponse notificationResponse = calculateNotificationDelta( context.getMetaData().getApplicationToken(), request, context); context.setSubscriptionStates(notificationResponse.getSubscriptionStates()); NotificationServerSync nfSyncResponse = buildNotificationSyncResponse(notificationResponse); context.setNotificationSyncResponse(nfSyncResponse); if (notificationResponse.isSubscriptionListChanged()) { EndpointProfileDto profileDto = context.getEndpointProfile(); Function<EndpointProfileDto, EndpointProfileDto> updateFunction = profile -> { profile.setSubscriptions(new ArrayList<>(notificationResponse.getSubscriptionSet())); return profile; }; context.setNotificationVersion(profileService.updateProfile( updateFunction.apply(profileDto), (storedProfile, newProfile) -> { return updateFunction.apply(storedProfile); })); } } return context; }