Ejemplo n.º 1
0
        internal void onTcpEvents(TcpStruct localTcpInfo, TcpStruct remoteTcpInfo, TcpOptionType type, ITcpReader tcpReader)
        {
            switch (type)
            {
            case TcpOptionType.StartListen:
                _listenning = true;
                break;

            case TcpOptionType.StopListen:
                _listenning = false;
                _listenWork = false;
                break;

            case TcpOptionType.ClientConnected:
                break;

            case TcpOptionType.Connected:
                break;

            case TcpOptionType.Disconnected:
                break;

            case TcpOptionType.Connecting:
                Thread.Sleep(0);
                break;

            default:
                break;
            }
            if (OnTcpEvents != null)
            {
                OnTcpEvents(localTcpInfo, remoteTcpInfo, type, tcpReader);
            }
        }
Ejemplo n.º 2
0
        internal override sealed Option Read(byte[] buffer, ref int offset, int length)
        {
            int num = offset + length;

            if (offset == num)
            {
                return((Option)null);
            }
            TcpOptionType optionType = (TcpOptionType)buffer[offset++];

            switch (optionType)
            {
            case TcpOptionType.EndOfOptionList:
                return((Option)TcpOption.End);

            case TcpOptionType.NoOperation:
                return((Option)TcpOption.Nop);

            default:
                return(OptionComplexFactory <TcpOptionType> .Read(optionType, buffer, ref offset, num - offset));
            }
        }
Ejemplo n.º 3
0
        internal sealed override V4Option Read(byte[] buffer, ref int offset, int length)
        {
            int offsetEnd = offset + length;

            if (offset == offsetEnd)
            {
                return(null);
            }

            TcpOptionType optionType = (TcpOptionType)buffer[offset++];

            switch (optionType)
            {
            case TcpOptionType.EndOfOptionList:
                return(End);

            case TcpOptionType.NoOperation:
                return(Nop);

            default:
                return((V4Option)OptionComplexFactory <TcpOptionType> .Read(optionType, buffer, ref offset, offsetEnd - offset));
            }
        }
Ejemplo n.º 4
0
 internal TcpOptionSimple(TcpOptionType optionType)
     : base(optionType)
 {
 }
 public TcpOptionTypeRegistrationAttribute(TcpOptionType optionType)
 {
     TcpOptionType = optionType;
 }
Ejemplo n.º 6
0
 internal void onTcpEvents(TcpStruct localTcpInfo, TcpStruct remoteTcpInfo, TcpOptionType type, __listen__readSmmp tcpReader)
 {
     switch (type)
     {
         case TcpOptionType.StartListen:
             _listenning = true;
             break;
         case TcpOptionType.StopListen:
             _listenning = false;
             _listenWork = false;
             break;
         case TcpOptionType.ClientConnected:
             break;
         case TcpOptionType.Connected:
             break;
         case TcpOptionType.Disconnected:
             if (_tcpMode == TcpMode.Client)
                 _tcpMode = TcpMode.Unknown;
             break;
         case TcpOptionType.Connecting:
             Thread.Sleep(0);
             break;
         default:
             break;
     }
     if (OnTcpEvents != null) OnTcpEvents(localTcpInfo, remoteTcpInfo, type, tcpReader);
 }
Ejemplo n.º 7
0
 internal void onError(TcpStruct localTcpInfo, TcpStruct remoteTcpInfo, TcpError error, Exception ex, TcpOptionType type, __listen__readSmmp tcpReader)
 {
     if (OnError != null) OnError(localTcpInfo, remoteTcpInfo, error, ex, type, tcpReader);
 }
 /// <summary>
 /// Creates a complex option using the given option type.
 /// </summary>
 protected TcpOptionComplex(TcpOptionType type)
     : base(type)
 {
 }
Ejemplo n.º 9
0
        public static TcpOption NextTcpOption(this Random random, int maximumOptionLength)
        {
            if (maximumOptionLength == 0)
            {
                throw new ArgumentOutOfRangeException("maximumOptionLength", maximumOptionLength, "option length must be positive");
            }

            if (maximumOptionLength >= TcpOptionUnknown.OptionMinimumLength && random.Next(100) > 90)
            {
                return(random.NextTcpOptionUnknown(maximumOptionLength));
            }

            List <TcpOptionType> impossibleOptionTypes = new List <TcpOptionType>();

            if (maximumOptionLength < TcpOptionMaximumSegmentSize.OptionLength)
            {
                impossibleOptionTypes.Add(TcpOptionType.MaximumSegmentSize);
            }
            if (maximumOptionLength < TcpOptionWindowScale.OptionLength)
            {
                impossibleOptionTypes.Add(TcpOptionType.WindowScale);
            }
            if (maximumOptionLength < TcpOptionSelectiveAcknowledgment.OptionMinimumLength)
            {
                impossibleOptionTypes.Add(TcpOptionType.SelectiveAcknowledgment);
            }
            if (maximumOptionLength < TcpOptionSelectiveAcknowledgmentPermitted.OptionLength)
            {
                impossibleOptionTypes.Add(TcpOptionType.SelectiveAcknowledgmentPermitted);
            }
            if (maximumOptionLength < TcpOptionEcho.OptionLength)
            {
                impossibleOptionTypes.Add(TcpOptionType.Echo);
            }
            if (maximumOptionLength < TcpOptionEchoReply.OptionLength)
            {
                impossibleOptionTypes.Add(TcpOptionType.EchoReply);
            }
            if (maximumOptionLength < TcpOptionTimestamp.OptionLength)
            {
                impossibleOptionTypes.Add(TcpOptionType.Timestamp);
            }
            if (maximumOptionLength < TcpOptionPartialOrderServiceProfile.OptionLength)
            {
                impossibleOptionTypes.Add(TcpOptionType.PartialOrderServiceProfile);
            }
            if (maximumOptionLength < TcpOptionPartialOrderConnectionPermitted.OptionLength)
            {
                impossibleOptionTypes.Add(TcpOptionType.PartialOrderConnectionPermitted);
            }
            if (maximumOptionLength < TcpOptionConnectionCountBase.OptionLength)
            {
                impossibleOptionTypes.Add(TcpOptionType.ConnectionCount);
                impossibleOptionTypes.Add(TcpOptionType.ConnectionCountNew);
                impossibleOptionTypes.Add(TcpOptionType.ConnectionCountEcho);
            }
            if (maximumOptionLength < TcpOptionAlternateChecksumRequest.OptionLength)
            {
                impossibleOptionTypes.Add(TcpOptionType.AlternateChecksumRequest);
            }
            if (maximumOptionLength < TcpOptionAlternateChecksumData.OptionMinimumLength)
            {
                impossibleOptionTypes.Add(TcpOptionType.AlternateChecksumData);
            }
            if (maximumOptionLength < TcpOptionMd5Signature.OptionLength)
            {
                impossibleOptionTypes.Add(TcpOptionType.Md5Signature);
            }
            if (maximumOptionLength < TcpOptionMood.OptionMaximumLength)
            {
                impossibleOptionTypes.Add(TcpOptionType.Mood);
            }

            impossibleOptionTypes.Add(TcpOptionType.QuickStartResponse);
            impossibleOptionTypes.Add(TcpOptionType.UserTimeout);
            impossibleOptionTypes.Add(TcpOptionType.SelectiveNegativeAcknowledgements); // TODO: Support Selective Negative Acknowledgements.

            TcpOptionType optionType = random.NextEnum <TcpOptionType>(impossibleOptionTypes);

            switch (optionType)
            {
            case TcpOptionType.EndOfOptionList:
                return(TcpOption.End);

            case TcpOptionType.NoOperation:
                return(TcpOption.Nop);

            case TcpOptionType.MaximumSegmentSize:
                return(new TcpOptionMaximumSegmentSize(random.NextUShort()));

            case TcpOptionType.WindowScale:
                return(new TcpOptionWindowScale(random.NextByte()));

            case TcpOptionType.SelectiveAcknowledgment:
                int numBlocks = random.Next((maximumOptionLength - TcpOptionSelectiveAcknowledgment.OptionMinimumLength) / 8 + 1);
                TcpOptionSelectiveAcknowledgmentBlock[] blocks = new TcpOptionSelectiveAcknowledgmentBlock[numBlocks];
                for (int i = 0; i != numBlocks; ++i)
                {
                    blocks[i] = new TcpOptionSelectiveAcknowledgmentBlock(random.NextUInt(), random.NextUInt());
                }
                return(new TcpOptionSelectiveAcknowledgment(blocks));

            case TcpOptionType.SelectiveAcknowledgmentPermitted:
                return(new TcpOptionSelectiveAcknowledgmentPermitted());

            case TcpOptionType.Echo:
                return(new TcpOptionEcho(random.NextUInt()));

            case TcpOptionType.EchoReply:
                return(new TcpOptionEchoReply(random.NextUInt()));

            case TcpOptionType.Timestamp:
                return(new TcpOptionTimestamp(random.NextUInt(), random.NextUInt()));

            case TcpOptionType.PartialOrderServiceProfile:
                return(new TcpOptionPartialOrderServiceProfile(random.NextBool(), random.NextBool()));

            case TcpOptionType.PartialOrderConnectionPermitted:
                return(new TcpOptionPartialOrderConnectionPermitted());

            case TcpOptionType.ConnectionCount:
                return(new TcpOptionConnectionCount(random.NextUInt()));

            case TcpOptionType.ConnectionCountEcho:
                return(new TcpOptionConnectionCountEcho(random.NextUInt()));

            case TcpOptionType.ConnectionCountNew:
                return(new TcpOptionConnectionCountNew(random.NextUInt()));

            case TcpOptionType.AlternateChecksumRequest:
                return(new TcpOptionAlternateChecksumRequest(random.NextEnum <TcpOptionAlternateChecksumType>()));

            case TcpOptionType.AlternateChecksumData:
                return(new TcpOptionAlternateChecksumData(random.NextBytes(random.Next(maximumOptionLength - TcpOptionAlternateChecksumData.OptionMinimumLength + 1))));

            case TcpOptionType.Md5Signature:
                return(new TcpOptionMd5Signature(random.NextBytes(TcpOptionMd5Signature.OptionValueLength)));

            case TcpOptionType.Mood:
                return(new TcpOptionMood(random.NextEnum(TcpOptionMoodEmotion.None)));

            default:
                throw new InvalidOperationException("optionType = " + optionType);
            }
        }
Ejemplo n.º 10
0
 internal void onError(TcpStruct localTcpInfo, TcpStruct remoteTcpInfo, TcpError error, Exception ex, TcpOptionType type, ITcpReader tcpReader)
 {
     if (OnError != null)
     {
         OnError(localTcpInfo, remoteTcpInfo, error, ex, type, tcpReader);
     }
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Initializes the option type.
 /// </summary>
 protected TcpOption(TcpOptionType optionType)
 {
     OptionType = optionType;
 }
Ejemplo n.º 12
0
 protected TcpOption(TcpOptionType optionType)
 {
     this.OptionType = optionType;
 }
Ejemplo n.º 13
0
 protected TcpOptionConnectionCountBase(TcpOptionType optionType, uint connectionCount)
     : base(optionType)
 {
     this.ConnectionCount = connectionCount;
 }
 public TcpOptionTypeRegistrationAttribute(TcpOptionType optionType)
 {
     TcpOptionType = optionType;
 }
 /// <summary>
 /// Creates a connection count option according to the given option type and given connection count value.
 /// </summary>
 protected TcpOptionConnectionCountBase(TcpOptionType optionType, uint connectionCount)
     : base(optionType)
 {
     ConnectionCount = connectionCount;
 }
Ejemplo n.º 16
0
 internal TcpOptionSimple(TcpOptionType optionType)
     : base(optionType)
 {
 }