use of net.iGap.request.RequestWrapper in project iGap-Android by KianIranian-STDG.
the class RegisterRepository method requestRegister.
private void requestRegister(String phoneNumber, RepositoryCallbackWithError<ErrorWithWaitTime> callback) {
if (phoneNumber == null)
return;
this.phoneNumber = phoneNumber.replace("-", "");
ProtoUserRegister.UserRegister.Builder builder = ProtoUserRegister.UserRegister.newBuilder();
builder.setCountryCode(isoCode);
builder.setPhoneNumber(Long.parseLong(this.phoneNumber));
builder.setPreferenceMethodValue(ProtoUserRegister.UserRegisterResponse.Method.VERIFY_CODE_SMS.getNumber());
builder.setRequest(ProtoRequest.Request.newBuilder().setId(HelperString.generateKey()));
builder.setAppId(BuildConfig.APP_ID);
RequestWrapper requestWrapper = new RequestWrapper(100, builder, new OnUserRegistration() {
@Override
public void onRegister(String userNameR, long userIdR, ProtoUserRegister.UserRegisterResponse.Method methodValue, List<Long> smsNumbersR, String regex, int verifyCodeDigitCount, String authorHashR, boolean callMethodSupported, long resendCodeDelay) {
/*isCallMethodSupported = callMethodSupported;*/
// because is new ui verification code number is 5 and number not not use it more
/*digitCount = verifyCodeDigitCount;*/
regexFetchCodeVerification = regex;
userName = userNameR;
userId = userIdR;
authorHash = authorHashR;
G.smsNumbers = smsNumbersR;
method = methodValue;
resendDelayTime = resendCodeDelay;
callback.onSuccess();
}
@Override
public void onRegisterError(int majorCode, int minorCode, int getWait) {
G.handler.post(() -> callback.onError(new ErrorWithWaitTime(majorCode, minorCode, getWait)));
}
});
try {
RequestQueue.sendRequest(requestWrapper);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
use of net.iGap.request.RequestWrapper in project iGap-Android by KianIranian-STDG.
the class ConnectionSecuringResponse method handler.
@Override
public void handler() {
super.handler();
ProtoConnectionSecuring.ConnectionSecuringResponse.Builder builder = (ProtoConnectionSecuring.ConnectionSecuringResponse.Builder) message;
G.currentTime = builder.getResponse().getTimestamp();
String publicKey = builder.getPublicKey();
int symmetricKeyLength = builder.getSymmetricKeyLength();
G.serverHeartBeatTiming = (builder.getHeartbeatInterval() * 1000);
String key = HelperString.generateKey(symmetricKeyLength);
if (G.symmetricKey != null) {
return;
}
G.symmetricKey = HelperString.generateSymmetricKey(key);
G.symmetricKeyString = key;
try {
RSAPublicKey rsaPublicKeyServer = (RSAPublicKey) HelperString.getPublicKeyFromPemFormat(publicKey);
PublicKey pubKeyServer = KeyFactory.getInstance("RSA").generatePublic(new RSAPublicKeySpec(rsaPublicKeyServer.getModulus(), rsaPublicKeyServer.getPublicExponent()));
RSAPublicKey rsaPublicKeyClient = (RSAPublicKey) HelperString.getPublicKeyFromPemFormat(Config.PUBLIC_KEY_CLIENT);
PublicKey pubKeyClient = KeyFactory.getInstance("RSA").generatePublic(new RSAPublicKeySpec(rsaPublicKeyClient.getModulus(), rsaPublicKeyClient.getPublicExponent()));
byte[] encryption = AESCrypt.encryptSymmetricKey(pubKeyServer, pubKeyClient, G.symmetricKey.getEncoded(), builder.getSecondaryChunkSize());
if (encryption != null) {
ProtoConnectionSecuring.ConnectionSymmetricKey.Builder connectionSymmetricKey = ProtoConnectionSecuring.ConnectionSymmetricKey.newBuilder();
connectionSymmetricKey.setSymmetricKey(ByteString.copyFrom(encryption));
connectionSymmetricKey.setVersion(2);
RequestWrapper requestWrapper = new RequestWrapper(2, connectionSymmetricKey);
RequestQueue.sendRequest(requestWrapper);
}
} catch (IOException | NoSuchAlgorithmException | InvalidKeySpecException | IllegalAccessException e) {
e.printStackTrace();
}
}
use of net.iGap.request.RequestWrapper in project iGap-Android by KianIranian-STDG.
the class RequestManager method requestQueueMapRemover.
private void requestQueueMapRemover(String key) {
try {
RequestWrapper requestWrapper = requestQueueMap.remove(key);
if (requestWrapper != null) {
if (requestWrapper.onResponse != null) {
IG_RPC.TimeOut_error error = new IG_RPC.TimeOut_error();
requestWrapper.onResponse.onReceived(null, error);
} else {
int actionId = requestWrapper.getActionId();
String className = G.lookupMap.get(actionId + net.iGap.Config.LOOKUP_MAP_RESPONSE_OFFSET);
String responseClassName = HelperClassNamePreparation.preparationResponseClassName(className);
ProtoResponse.Response.Builder responseBuilder = ProtoResponse.Response.newBuilder();
responseBuilder.setTimestamp((int) System.currentTimeMillis());
responseBuilder.setId(key);
responseBuilder.build();
ProtoError.ErrorResponse.Builder errorBuilder = ProtoError.ErrorResponse.newBuilder();
errorBuilder.setResponse(responseBuilder);
errorBuilder.setMajorCode(5);
errorBuilder.setMinorCode(1);
errorBuilder.build();
Class<?> c = Class.forName(responseClassName);
Object object;
try {
object = c.getConstructor(int.class, Object.class, Object.class).newInstance(actionId, errorBuilder, requestWrapper.identity);
} catch (NoSuchMethodException e) {
object = c.getConstructor(int.class, Object.class, String.class).newInstance(actionId, errorBuilder, requestWrapper.identity);
}
Method setTimeoutMethod = object.getClass().getMethod("timeOut");
setTimeoutMethod.invoke(object);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of net.iGap.request.RequestWrapper in project iGap-Android by KianIranian-STDG.
the class RequestManager method cancelRequest.
public boolean cancelRequest(String id) {
RequestWrapper requestWrapper = requestQueueMap.get(id);
if (requestWrapper == null)
return false;
requestQueueMap.remove(id);
return true;
}
use of net.iGap.request.RequestWrapper in project iGap-Android by KianIranian-STDG.
the class RequestManager method bindRequestToUniqueId.
public void bindRequestToUniqueId(final String reqId, final int uid) {
networkQueue.postRunnable(() -> {
RequestWrapper request = requestQueueMap.get(reqId);
if (request != null) {
List<RequestWrapper> list = new ArrayList<>();
list.add(request);
requestsByUId.put(uid, list);
}
});
}
Aggregations