use of sugar.free.sightparser.applayer.descriptors.Service in project SightRemote by TebbeUbben.
the class RequestWorker method requestNext.
private void requestNext(Pipeline pipeline) {
if (messageRequests.size() == 0)
return;
MessageRequest messageRequest = null;
while (messageRequests.size() != 0) {
messageRequest = messageRequests.get(0);
if (!messageRequest.getBinder().isBinderAlive()) {
messageRequests.remove(messageRequest);
if (messageRequests.size() == 0)
return;
else
continue;
} else
break;
}
Service service = messageRequest.getAppLayerMessage().getService();
if (!pipeline.getActivatedServices().contains(service)) {
messageRequest.setMessageStatus(MessageStatus.ACTIVATING_SERVICE);
if (service.getServicePassword() != null) {
if (service.getServicePassword().length() != 16)
pipeline.receive(new InvalidServicePasswordError(messageRequest.getAppLayerMessage().getClass(), (short) 0x99F0));
else {
ServiceChallengeMessage serviceChallenge = new ServiceChallengeMessage();
serviceChallenge.setServiceID(service.getServiceID());
serviceChallenge.setVersion(service.getVersion());
pipeline.send(serviceChallenge);
}
} else {
ActivateServiceMessage activateService = new ActivateServiceMessage();
activateService.setServiceID(service.getServiceID());
activateService.setVersion(service.getVersion());
activateService.setServicePassword(new byte[16]);
pipeline.send(activateService);
}
} else {
messageRequest.setMessageStatus(MessageStatus.PENDING);
if (service.getServicePassword() != null && service.getServicePassword().length() != 16)
pipeline.receive(new InvalidServicePasswordError(messageRequest.getAppLayerMessage().getClass(), (short) 0x99F0));
else
pipeline.send(messageRequest.getAppLayerMessage());
}
}
use of sugar.free.sightparser.applayer.descriptors.Service in project SightRemote by TebbeUbben.
the class RequestWorker method onInboundMessage.
@Override
public void onInboundMessage(final Object message, Pipeline pipeline) throws Exception {
synchronized (messageRequests) {
if (messageRequests.size() == 0)
return;
if (message instanceof DisconnectedError) {
for (MessageRequest messageRequest : new ArrayList<>(messageRequests)) {
sendError(messageRequest, (Exception) message);
messageRequests.remove(messageRequest);
}
return;
}
MessageRequest messageRequest = messageRequests.get(0);
if (message instanceof Exception) {
sendError(messageRequest, (Exception) message);
messageRequests.remove(messageRequest);
requestNext(pipeline);
return;
}
if (messageRequest.getMessageStatus() == MessageStatus.ACTIVATING_SERVICE) {
Service service = messageRequest.getAppLayerMessage().getService();
if (message instanceof ServiceChallengeMessage) {
byte[] password = Cryptograph.getServicePasswordHash(service.getServicePassword(), ((ServiceChallengeMessage) message).getRandomData());
ActivateServiceMessage activateService = new ActivateServiceMessage();
activateService.setServicePassword(password);
activateService.setServiceID(service.getServiceID());
activateService.setVersion(service.getVersion());
pipeline.send(activateService);
} else if (message instanceof ActivateServiceMessage) {
pipeline.getActivatedServices().add(service);
requestNext(pipeline);
}
} else if (messageRequest.getMessageStatus() == MessageStatus.PENDING && message instanceof AppLayerMessage) {
sendMessage(messageRequest, (AppLayerMessage) message);
messageRequests.remove(messageRequest);
requestNext(pipeline);
}
}
}
Aggregations