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);
}
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();
}
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;
}
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);
}
Aggregations