示例#1
0
        bool receiveCryptedAnswer(int counter, string destinationId)
        {
            // receive packet
            // compare 'counter' with received (if != -1)
            // compare 'destinationId' with received (if != null)
            // on return: packetBodyStream contains packet, starting from current position
            packetBodyStream.SetLength(0);
            if (MPPCSecurity.ReadAndDecryptPacket(channelStreamReader, packetBodyStream, alg) == false)
            {
                return(false);
            }
            packetBodyStream.Position = 0;
            int    R_counter = packetBodyStreamReader.ReadInt32();
            string R_destId  = packetBodyStreamReader.ReadString();

            //string tmp = Encoding.ASCII.GetString( packetBodyStream.GetBuffer(), (int)packetBodyStream.Position, (int)packetBodyStream.Length);
            //MPChannels.Log(string.Format(">{0},{1}/{2} {3}", Id, R_counter, R_destId, tmp));

            if (counter != -1)
            {
                if (counter != R_counter)
                {
                    return(false);
                }
            }
            if (destinationId != null)
            {
                if (destinationId != R_destId)
                {
                    return(false);
                }
            }
            return(true);
        }
示例#2
0
        bool sendCryptedPacket(string destinationId, object packet)
        {
            //MPChannels.Log(string.Format("<{0},{1}/{2} {3}", Id, packetCounter, destinationId, packet));
            packetBodyStream.SetLength(0);
            packetBodyStreamWriter.Write(packetCounter++);
            packetBodyStreamWriter.Write(destinationId);
            if (_appendPacketBody(packetBodyStreamWriter, packet) == false)
            {
                return(false);
            }

            packetBodyStream.Position = 0;
            MPPCSecurity.EncryptAndWritePacket(channelStreamWriter, packetBodyStream, alg);
            return(true);
        }