コード例 #1
0
ファイル: PacketFactory.cs プロジェクト: jinyuttt/netudt
        /**
         * create the right type of control packet based on the packet data
         * @param packetData
         * @return
         */
        public static ControlPacket CreateControlPacket(byte[] encodedData, int length)
        {
            ControlPacket packet = null;

            int  pktType        = PacketUtil.DecodeType(encodedData, 0);
            long additionalInfo = PacketUtil.Decode(encodedData, 4);
            long timeStamp      = PacketUtil.Decode(encodedData, 8);
            long destID         = PacketUtil.Decode(encodedData, 12);

            byte[] controlInformation = new byte[length - 16];
            Array.Copy(encodedData, 16, controlInformation, 0, controlInformation.Length);

            //TYPE 0000:0
            if ((int)ControlPacketType.CONNECTION_HANDSHAKE == pktType)
            {
                packet = new ConnectionHandshake(controlInformation);
            }
            //TYPE 0001:1
            else if ((int)ControlPacketType.KEEP_ALIVE == pktType)
            {
                packet = new KeepAlive();
            }
            //TYPE 0010:2
            else if ((int)ControlPacketType.ACK == pktType)
            {
                packet = new Acknowledgement(additionalInfo, controlInformation);
            }
            //TYPE 0011:3
            else if ((int)ControlPacketType.NAK == pktType)
            {
                packet = new NegativeAcknowledgement(controlInformation);
            }
            //TYPE 0101:5
            else if ((int)ControlPacketType.SHUTDOWN == pktType)
            {
                packet = new Shutdown();
            }
            //TYPE 0110:6
            else if ((int)ControlPacketType.ACK2 == pktType)
            {
                packet = new Acknowledgment2(additionalInfo, controlInformation);
            }
            //TYPE 0111:7
            else if ((int)ControlPacketType.MESSAGE_DROP_REQUEST == pktType)
            {
                packet = new MessageDropRequest(controlInformation);
            }
            //TYPE 1111:8
            else if ((int)ControlPacketType.USER_DEFINED == pktType)
            {
                packet = new UserDefined(controlInformation);
            }

            if (packet != null)
            {
                packet.TimeStamp     = timeStamp;
                packet.DestinationID = destID;
            }
            return(packet);
        }
コード例 #2
0
        void Decode(byte[] data)
        {
            udtVersion     = PacketUtil.Decode(data, 0);
            socketType     = PacketUtil.Decode(data, 4);
            initialSeqNo   = PacketUtil.Decode(data, 8);
            packetSize     = PacketUtil.Decode(data, 12);
            maxFlowWndSize = PacketUtil.Decode(data, 16);
            connectionType = PacketUtil.Decode(data, 20);
            socketID       = PacketUtil.Decode(data, 24);
            if (data.Length > 28)
            {
                cookie = PacketUtil.Decode(data, 28);
            }

            if (data.Length > 32)
            {
                //IP6
                peerIP[0] = PacketUtil.Decode(data, 32);

                peerIP[1] = PacketUtil.Decode(data, 36);

                peerIP[2] = PacketUtil.Decode(data, 40);

                peerIP[3] = PacketUtil.Decode(data, 44);
            }
        }
コード例 #3
0
ファイル: DataPacket.cs プロジェクト: jinyuttt/netudt
 void Decode(byte[] encodedData, int length)
 {
     packetSequenceNumber = PacketUtil.Decode(encodedData, 0);
     messageNumber        = PacketUtil.Decode(encodedData, 4);
     timeStamp            = PacketUtil.Decode(encodedData, 8);
     destinationID        = PacketUtil.Decode(encodedData, 12);
     data = new byte[length - 16];
     Array.Copy(encodedData, 16, data, 0, data.Length);
 }
コード例 #4
0
ファイル: Acknowledgement.cs プロジェクト: jinyuttt/netudt
 void DecodeControlInformation(byte[] data)
 {
     ackNumber = PacketUtil.Decode(data, 0);
     if (data.Length > 4)
     {
         roundTripTime         = PacketUtil.Decode(data, 4);
         roundTripTimeVariance = PacketUtil.Decode(data, 8);
         bufferSize            = PacketUtil.Decode(data, 12);
     }
     if (data.Length > 16)
     {
         pktArrivalSpeed       = PacketUtil.Decode(data, 16);
         estimatedLinkCapacity = PacketUtil.Decode(data, 20);
     }
 }
コード例 #5
0
 void decode(byte[] data)
 {
     msgFirstSeqNo = PacketUtil.Decode(data, 0);
     msgLastSeqNo  = PacketUtil.Decode(data, 4);
 }