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); } }
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)); } }
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)); } }
internal TcpOptionSimple(TcpOptionType optionType) : base(optionType) { }
public TcpOptionTypeRegistrationAttribute(TcpOptionType optionType) { TcpOptionType = optionType; }
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); }
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) { }
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); } }
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); } }
/// <summary> /// Initializes the option type. /// </summary> protected TcpOption(TcpOptionType optionType) { OptionType = optionType; }
protected TcpOption(TcpOptionType optionType) { this.OptionType = optionType; }
protected TcpOptionConnectionCountBase(TcpOptionType optionType, uint connectionCount) : base(optionType) { this.ConnectionCount = connectionCount; }
/// <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; }