Изменение домена с rosetta-im.com на rosetta.im
This commit is contained in:
156
src/main/java/im/rosetta/packet/Packet0Handshake.java
Normal file
156
src/main/java/im/rosetta/packet/Packet0Handshake.java
Normal file
@@ -0,0 +1,156 @@
|
||||
package im.rosetta.packet;
|
||||
|
||||
import im.rosetta.packet.runtime.HandshakeStage;
|
||||
|
||||
import io.orprotocol.Stream;
|
||||
import io.orprotocol.packet.Packet;
|
||||
|
||||
/**
|
||||
* Пакет хэндшейка между клиентом и сервером.
|
||||
* Используется для установления соединения и подтверждения от сервера что клиент
|
||||
* тот за кого себя выдает.
|
||||
*
|
||||
* Протокол таблица:
|
||||
* 0 - packetId (int16)
|
||||
* 1 - privateKey (string)
|
||||
* 2 - publicKey (string)
|
||||
* 3 - protocolVersion (int8)
|
||||
* 4 - heartbeatInterval (int8)
|
||||
* 5 - deviceId (string)
|
||||
* 6 - deviceName (string)
|
||||
* 7 - deviceOs (string)
|
||||
* 8 - handshakeStage (int8)
|
||||
*/
|
||||
public class Packet0Handshake extends Packet {
|
||||
/**
|
||||
* Публичный и приватный ключи клиента
|
||||
*/
|
||||
private String publicKey;
|
||||
/**
|
||||
* Приватный ключ клиента
|
||||
* Это не совсем приватный ключ, а лишь необратимо зашифрованная его версия
|
||||
* для идентификации клиента на сервере.
|
||||
*/
|
||||
private String privateKey;
|
||||
/**
|
||||
* Версия протокола клиента
|
||||
*/
|
||||
private int protocolVersion = 1;
|
||||
|
||||
/**
|
||||
* Интервал отправки heartbeat пакетов в секундах
|
||||
*/
|
||||
private int heartbeatInterval = 15;
|
||||
|
||||
/**
|
||||
* Минимальная информация об устройстве клиента
|
||||
*/
|
||||
private String deviceId;
|
||||
private String deviceName;
|
||||
private String deviceOs;
|
||||
|
||||
/**
|
||||
* Стадия рукопожатия
|
||||
* 0 - COMPLETED
|
||||
* 1 - NEED_DEVICE_VERIFICATION
|
||||
*/
|
||||
private HandshakeStage handshakeStage = HandshakeStage.COMPLETED;
|
||||
|
||||
|
||||
@Override
|
||||
public Stream write() {
|
||||
Stream stream = new Stream();
|
||||
stream.writeInt16(this.packetId);
|
||||
stream.writeString(this.privateKey);
|
||||
stream.writeString(this.publicKey);
|
||||
stream.writeInt8(this.protocolVersion);
|
||||
stream.writeInt8(this.heartbeatInterval);
|
||||
stream.writeString(this.deviceId);
|
||||
stream.writeString(this.deviceName);
|
||||
stream.writeString(this.deviceOs);
|
||||
stream.writeInt8(this.handshakeStage.getCode());
|
||||
return stream;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(Stream stream) {
|
||||
this.privateKey = stream.readString();
|
||||
this.publicKey = stream.readString();
|
||||
this.protocolVersion = stream.readInt8();
|
||||
this.heartbeatInterval = stream.readInt8();
|
||||
String deviceId = stream.readString();
|
||||
String deviceName = stream.readString();
|
||||
String deviceOs = stream.readString();
|
||||
this.deviceId = deviceId;
|
||||
this.deviceName = deviceName;
|
||||
this.deviceOs = deviceOs;
|
||||
this.handshakeStage = HandshakeStage.fromCode(
|
||||
stream.readInt8()
|
||||
);
|
||||
}
|
||||
|
||||
public String getPublicKey() {
|
||||
return publicKey;
|
||||
}
|
||||
|
||||
public String getPrivateKey() {
|
||||
return privateKey;
|
||||
}
|
||||
|
||||
public int getProtocolVersion() {
|
||||
return protocolVersion;
|
||||
}
|
||||
|
||||
public int getHeartbeatInterval() {
|
||||
return heartbeatInterval;
|
||||
}
|
||||
|
||||
public String getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
public String getDeviceName() {
|
||||
return deviceName;
|
||||
}
|
||||
|
||||
public String getDeviceOs() {
|
||||
return deviceOs;
|
||||
}
|
||||
|
||||
public HandshakeStage getHandshakeStage() {
|
||||
return handshakeStage;
|
||||
}
|
||||
|
||||
public void setHandshakeStage(HandshakeStage handshakeStage) {
|
||||
this.handshakeStage = handshakeStage;
|
||||
}
|
||||
|
||||
public void setDeviceId(String deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public void setDeviceName(String deviceName) {
|
||||
this.deviceName = deviceName;
|
||||
}
|
||||
|
||||
public void setDeviceOs(String deviceOs) {
|
||||
this.deviceOs = deviceOs;
|
||||
}
|
||||
|
||||
public void setHeartbeatInterval(int heartbeatInterval) {
|
||||
this.heartbeatInterval = heartbeatInterval;
|
||||
}
|
||||
|
||||
public void setProtocolVersion(int protocolVersion) {
|
||||
this.protocolVersion = protocolVersion;
|
||||
}
|
||||
|
||||
public void setPrivateKey(String privateKey) {
|
||||
this.privateKey = privateKey;
|
||||
}
|
||||
|
||||
public void setPublicKey(String publicKey) {
|
||||
this.publicKey = publicKey;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user