public void SetChecksum(ref byte[] packet)
        {
            RPH rph = RPH.Deserialize(packet);
            var md5 = MD5.Create();

            rph._checksum = BitConverter.ToInt32(md5.ComputeHash(packet), 0);
            byte[] newHead = rph.Serialize();
            Array.Copy(newHead, packet, newHead.Length);
        }
        public bool IsCorrupt(RPH rph)
        {
            int checksum = rph._checksum;

            rph._checksum = 0;
            byte[] packet       = rph.Serialize();
            var    md5          = MD5.Create();
            int    calcChecksum = BitConverter.ToInt32(md5.ComputeHash(packet), 0);

            return(checksum != calcChecksum);
        }
        public void SendSyn(int filelength, string fileEnding)
        {
            // Establish the connection
            RPH syn = RPH.CreateSynPacket(filelength, fileEnding);

            byte[] dgram = syn.Serialize();
            SetChecksum(ref dgram);
            try
            {
                _sendingSocket?.SendTo(dgram, _endPoint);
            }
            catch (SocketException e)
            {
                Console.WriteLine(e.ToString());
                _tries++;
                if (_tries > MaxConTries)
                {
                    return;
                }
                SendSyn(filelength, fileEnding);
                _tries = 0;
            }
        }
Ejemplo n.º 4
0
 public bool IsCorrupt(RPH rph)
 {
     int checksum = rph._checksum;
     rph._checksum = 0;
     byte[] packet = rph.Serialize();
     var md5 = MD5.Create();
     int calcChecksum = BitConverter.ToInt32(md5.ComputeHash(packet), 0);
     return checksum != calcChecksum;
 }