private void EncapsulateMtu(int commandCount, long currentSendingTime) { int offset = 0; ByteWrite.SetByte(_udpBuffer, ref offset, (byte)CommandType.None); ByteWrite.SetInt(_udpBuffer, ref offset, _peerId); ByteWrite.SetLong(_udpBuffer, ref offset, currentSendingTime); ByteWrite.SetShort(_udpBuffer, ref offset, (short)commandCount); Array.Clear(_udpBuffer, offset, (int)Lengths.Crc); if (IsCrcEnabled) { long crc = _udpBuffer.CalculateCrc(_udpBufferIndex); ByteWrite.SetLong(_udpBuffer, ref offset, crc); } }
public byte[] CreateConnectCommand( short channelCount, short mtu, int protoVerison, int disconnectionTimeout, bool isCrcEnabled, BigInteger publicKey, long sendingTime) { var buffer = ByteBufferFactory.NewBuffer(); buffer.WriteByte((byte)CommandType.Connect); buffer.WriteInt(protoVerison); //4 buffer.WriteLong(sendingTime); //8 buffer.WriteShort(channelCount); //2 buffer.WriteShort(mtu); //2 buffer.WriteInt(disconnectionTimeout); //4 buffer.WriteShort((short)(isCrcEnabled == true ? 1 : 0)); //2 var publicKeyBytes = publicKey.ToByteArray(); buffer.WriteByte((byte)publicKeyBytes.Length); buffer.WriteBytes(publicKeyBytes); //4 buffer.WriteLong(0); //8 crc space var bytes = buffer.ToArray(); if (isCrcEnabled) { long crc = bytes.CalculateCrc(bytes.Length); int offset = bytes.Length - (int)Lengths.Crc; ByteWrite.SetLong(bytes, ref offset, crc); } SentCount++; return(bytes); }