Search in sources :

Example 11 with DataInput

use of im.actor.runtime.bser.DataInput in project actor-platform by actorapp.

the class ManagedConnection method onDropPackage.

// Drop
private synchronized void onDropPackage(byte[] data) throws IOException {
    DataInput drop = new DataInput(data);
    long messageId = drop.readLong();
    int errorCode = drop.readByte();
    int messageLen = drop.readInt();
    String message = new String(drop.readBytes(messageLen), "UTF-8");
    Log.w(TAG, "Drop received: " + message);
    throw new IOException("Drop received: " + message);
}
Also used : DataInput(im.actor.runtime.bser.DataInput) IOException(java.io.IOException)

Example 12 with DataInput

use of im.actor.runtime.bser.DataInput in project actor-platform by actorapp.

the class ManagedConnection method onAckPackage.

// Ack
private synchronized void onAckPackage(byte[] data) throws IOException {
    DataInput ackContent = new DataInput(data);
    int frameId = ackContent.readInt();
    CommonTimer timerCompat = packageTimers.remove(frameId);
    if (timerCompat == null) {
        return;
    }
    timerCompat.cancel();
    refreshTimeouts();
}
Also used : DataInput(im.actor.runtime.bser.DataInput) CommonTimer(im.actor.runtime.threading.CommonTimer)

Example 13 with DataInput

use of im.actor.runtime.bser.DataInput in project actor-platform by actorapp.

the class MemoryListEngine method loadValue.

private T loadValue(long key) {
    T res = cache.lookup(key);
    if (res != null) {
        return res;
    }
    ListEngineRecord record = storage.loadItem(key);
    if (record == null) {
        return null;
    }
    try {
        res = creator.createInstance();
        res.parse(new BserValues(BserParser.deserialize(new DataInput(record.getData()))));
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
    cache.onObjectLoaded(key, res);
    return res;
}
Also used : DataInput(im.actor.runtime.bser.DataInput) ListEngineRecord(im.actor.runtime.storage.ListEngineRecord) BserValues(im.actor.runtime.bser.BserValues) IOException(java.io.IOException)

Example 14 with DataInput

use of im.actor.runtime.bser.DataInput in project actor-platform by actorapp.

the class ManagedConnection method onHandshakePackage.

private synchronized void onHandshakePackage(byte[] data) throws IOException {
    // Log.d(TAG, "Handshake response received");
    DataInput handshakeResponse = new DataInput(data);
    int protoVersion = handshakeResponse.readByte();
    int apiMajor = handshakeResponse.readByte();
    int apiMinor = handshakeResponse.readByte();
    byte[] sha256 = handshakeResponse.readBytes(32);
    byte[] localSha256 = Crypto.SHA256(handshakeRandomData);
    if (!Arrays.equals(sha256, localSha256)) {
        Log.w(TAG, "SHA 256 is incorrect");
        // Log.d(TAG, "Local SHA256: " + CryptoUtils.hex(localSha256));
        throw new IOException("SHA 256 is incorrect");
    }
    if (protoVersion != mtprotoVersion) {
        Log.w(TAG, "Incorrect Proto Version, expected: " + mtprotoVersion + ", got " + protoVersion + ";");
        throw new IOException("Incorrect Proto Version, expected: " + mtprotoVersion + ", got " + protoVersion + ";");
    }
    if (apiMajor != apiMajorVersion) {
        Log.w(TAG, "Incorrect Api Major Version, expected: " + apiMajor + ", got " + apiMajor + ";");
        throw new IOException("Incorrect Api Major Version, expected: " + apiMajor + ", got " + apiMajor + ";");
    }
    if (apiMinor != apiMinorVersion) {
        Log.w(TAG, "Incorrect Api Minor Version, expected: " + apiMinor + ", got " + apiMinor + ";");
        throw new IOException("Incorrect Api Minor Version, expected: " + apiMinor + ", got " + apiMinor + ";");
    }
    // Log.d(TAG, "Handshake successful");
    isHandshakePerformed = true;
    factoryCallback.onConnectionCreated(this);
    handshakeTimeout.cancel();
    pingTask.schedule(PING_TIMEOUT);
}
Also used : DataInput(im.actor.runtime.bser.DataInput) IOException(java.io.IOException)

Aggregations

DataInput (im.actor.runtime.bser.DataInput)14 IOException (java.io.IOException)12 BserValues (im.actor.runtime.bser.BserValues)5 CommonTimer (im.actor.runtime.threading.CommonTimer)2 AutoreleasePool (com.google.j2objc.annotations.AutoreleasePool)1 AbsContentContainer (im.actor.core.entity.content.internal.AbsContentContainer)1 EncryptedCBCPackage (im.actor.core.network.mtp.entity.EncryptedCBCPackage)1 EncryptedPackage (im.actor.core.network.mtp.entity.EncryptedPackage)1 ProtoMessage (im.actor.core.network.mtp.entity.ProtoMessage)1 ProtoPackage (im.actor.core.network.mtp.entity.ProtoPackage)1 ProtoStruct (im.actor.core.network.mtp.entity.ProtoStruct)1 RpcError (im.actor.core.network.mtp.entity.rpc.RpcError)1 RpcFloodWait (im.actor.core.network.mtp.entity.rpc.RpcFloodWait)1 RpcInternalError (im.actor.core.network.mtp.entity.rpc.RpcInternalError)1 RpcOk (im.actor.core.network.mtp.entity.rpc.RpcOk)1 ListEngineRecord (im.actor.runtime.storage.ListEngineRecord)1