69 lines
1.8 KiB
Java
69 lines
1.8 KiB
Java
package io.github.lonamiwebs.overgram.network;
|
|
|
|
import io.github.lonamiwebs.overgram.crypto.AuthKey;
|
|
import io.github.lonamiwebs.overgram.tl.TLMessage;
|
|
import io.github.lonamiwebs.overgram.tl.TLObject;
|
|
|
|
import java.security.SecureRandom;
|
|
|
|
public class MTProtoState {
|
|
|
|
public AuthKey authKey;
|
|
public long salt;
|
|
private final long id;
|
|
private long timeOffset;
|
|
private int sequence;
|
|
private long lastMsgId;
|
|
|
|
public MTProtoState() {
|
|
id = new SecureRandom().nextLong();
|
|
timeOffset = 0;
|
|
sequence = 0;
|
|
lastMsgId = 0;
|
|
authKey = null;
|
|
salt = 0;
|
|
}
|
|
|
|
public TLMessage createMessage(final TLObject object) {
|
|
throw new UnsupportedOperationException();
|
|
}
|
|
|
|
public static Object calcKey(final Object authKey, final byte[] msgKey, final boolean client) {
|
|
throw new UnsupportedOperationException();
|
|
}
|
|
|
|
public byte[] packMessage(final TLMessage message) {
|
|
throw new UnsupportedOperationException();
|
|
}
|
|
|
|
public TLMessage unpackMessage(final byte[] body) {
|
|
throw new UnsupportedOperationException();
|
|
}
|
|
|
|
public long getNewMsgId() {
|
|
final long now = System.currentTimeMillis();
|
|
long newMsgId = (((now / 1000) + timeOffset) << 32) | ((now % 1000) << 2);
|
|
if (lastMsgId >= newMsgId) {
|
|
newMsgId = lastMsgId + 4;
|
|
}
|
|
|
|
lastMsgId = newMsgId;
|
|
return newMsgId;
|
|
}
|
|
|
|
public void updateTimeOffset(long correctMsgId) {
|
|
final long now = System.currentTimeMillis() / 1000L;
|
|
final long correct = correctMsgId >> 32;
|
|
timeOffset = correct - now;
|
|
lastMsgId = 0;
|
|
}
|
|
|
|
public int getSeqNo(final boolean contentRelated) {
|
|
if (contentRelated) {
|
|
return 1 + 2 * sequence++;
|
|
} else {
|
|
return 2 * sequence;
|
|
}
|
|
}
|
|
}
|