public override void OnUdpMessageInput(IUdpSession session, ref WrappedReader reader, WrappedArgs args) { //消息类型 var messageType = reader.ReadInt32(); var buffer = reader.ReadBuffer((int)reader.Length); //频道号 var convSpan = buffer.Slice(buffer.Start, 4).First.Span; var conv = base.OrderOperators.ReadUInt32(convSpan); if (!this.sessions.ContainsKey(conv)) { return; } var kcpSession = this.sessions[conv]; if (messageType == k_message) { base.SendKcpMessageTo(kcpSession, ref buffer); } else if (messageType == c_message) { base.SendUdpMessageTo(kcpSession, ref buffer); } }
public void InputUdpMessage(ref ReadOnlySequence <byte> buffer) { var udpBuffer = buffer.Slice(buffer.GetPosition(4)); var reader = new WrappedReader(udpBuffer, this.Order, this.readerFlushDelegate); this.Pipeline.OnTransportRead(this, ref reader); reader.Flush(); }
public void OnTransportRead(IUdpSession session, ref WrappedReader reader, WrappedArgs args) { long length = reader.Length; var buffer = reader.ReadBuffer((int)length); //string str= System.Text.Encoding.UTF8.GetString(buffer.FirstSpan); //Console.WriteLine($"{nameof(UdpFilter_2)}.{nameof(OnTransportRead)}>>LoaclAddress:{session.LocalAddress} remoteAddress:{session.RcvAddress}>>" + str); }
public void OnTransportRead(IKcpSession session, ref WrappedReader reader, WrappedArgs args) { int length = (int)reader.Length; var buffer = reader.ReadBuffer(length); //string str = System.Text.Encoding.UTF8.GetString(buffer.FirstSpan); //Console.WriteLine($"频道:{session.Conv},收到消息:{str}" ); }
public void OnTransportRead(IUdpSession session, ref WrappedReader reader, WrappedArgs args) { this.buffers.Clear(); var buffer = reader.ReadBuffer((int)reader.Length); this.buffers.Add(buffer.First.GetBinaryArray()); args.Value = this.buffers; }
public void OnTransportRead(IUdpSession session, ref WrappedReader reader, WrappedArgs args) { if (this.isInvalid || this.isStop) { return; } this.controller.OnUdpMessageInput(session, ref reader, args); }
public void OnTransportRead(TSession session, ref WrappedReader reader) { this.readArgs.Value = null; int count = this.filters.Count; for (int i = 0; i < count; i++) { this.filters[i].OnTransportRead(session, ref reader, this.readArgs); } }
public void OnTransportRead(ITcpSession session, ref WrappedReader reader, WrappedArgs args) { List <ReadOnlySequence <byte> > buffers = (List <ReadOnlySequence <byte> >)args.Value; for (int i = 0; i < buffers.Count; i++) { session.Write(SocketConfig.message); } session.FlushAsync().NoAwait(); }
public void OnTransportRead(ITcpSession session, ref WrappedReader reader, WrappedArgs args) { this.buffers.Clear(); args.Value = this.buffers; while (reader.TryFindPosition(this.symbol, out SequencePosition endPosition)) { var buffer = reader.ReadBuffer(endPosition); var length = buffer.Length - this.symbol.Length; this.buffers.Add(buffer.Slice(buffer.Start, length)); } }
public void OnTransportRead(ITcpSession session, ref WrappedReader reader, WrappedArgs args) { Console.WriteLine($"{nameof(TcpTestFilter_Client)}.{nameof(OnTransportRead)}"); List <ReadOnlySequence <byte> > buffers = (List <ReadOnlySequence <byte> >)args.Value; for (int i = 0; i < buffers.Count; i++) { var buffer = buffers[i]; string str = System.Text.Encoding.UTF8.GetString(buffer.FirstSpan); Console.WriteLine("收到》》" + str); } }
private void OnKcpRcvEvent(uint conv, ref ReadOnlySequence <byte> sequence) { try { var reader = new WrappedReader(sequence, this.Order, this.readerFlushDelegate); this.Pipeline.OnTransportRead(this, ref reader); reader.Flush(); } catch (Exception e) { this.DeliverException(e); return; } }
public virtual SamlSecurityToken ReadToken(XmlReader reader, SecurityTokenSerializer keyInfoSerializer, SecurityTokenResolver outOfBandTokenResolver) { if (reader == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader"); } WrappedReader reader3 = new WrappedReader(XmlDictionaryReader.CreateDictionaryReader(reader)); SamlAssertion assertion = this.LoadAssertion(reader3, keyInfoSerializer, outOfBandTokenResolver); if (assertion == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLUnableToLoadAssertion"))); } return(new SamlSecurityToken(assertion)); }
private void OnRcvPipelineRead() { ReadDgramResult readDgramResult = RcvPipeReader.Read(); if (readDgramResult.IsEmpty) { return; } int count = 0; bool isReadComplete = false; ASegment head = readDgramResult.Head; ASegment tail = readDgramResult.Tail; ASegment segment = head; try { while (!isReadComplete) { this.RcvAddress = (EndPoint)segment.Token; var memory = segment.GetReadableMemory(); var reader = new WrappedReader(new ReadOnlySequence <byte>(memory), this.Order, this.readerFlushCallback); this.filterPipeline.OnTransportRead(this, ref reader); reader.Flush(); count++; if (segment == tail) { isReadComplete = true; } else { segment = segment.ChildSegment; } } this.RcvPipeReader.ReaderAdvance(count); this.RcvPipeReader.ReceiveAsync(); } catch (Exception e) { this.DeliverException(e); this.RcvPipeReader.Complete(); } }
private void TransportReadNotify(ReadOnlySequence <byte> buffer) { var reader = new WrappedReader(buffer, this.Order, this.readerFlushCallback); try { this.filterPipeline.OnTransportRead(this, ref reader); } catch (Exception ex) { this.DeliverException(ex); } finally { reader.Flush(); } }
public virtual SamlSecurityToken ReadToken(XmlReader reader, SecurityTokenSerializer keyInfoSerializer, SecurityTokenResolver outOfBandTokenResolver) { if (reader == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader"); } XmlDictionaryReader dictionaryReader = XmlDictionaryReader.CreateDictionaryReader(reader); WrappedReader wrappedReader = new WrappedReader(dictionaryReader); SamlAssertion assertion = LoadAssertion(wrappedReader, keyInfoSerializer, outOfBandTokenResolver); if (assertion == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLUnableToLoadAssertion))); } //if (assertion.Signature == null) // throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SamlTokenMissingSignature))); return(new SamlSecurityToken(assertion)); }
public void OnTransportRead(ITcpSession session, ref WrappedReader reader, WrappedArgs args) { this.buffers.Clear(); args.Value = this.buffers; while (reader.IsLengthEnough(this.currentReadLength)) { if (this.currentReadPart == PackPart.Head) { this.currentReadLength = reader.ReadInt32(); if (this.currentReadLength > this.maxPackLength) { throw new Exception("pack length error!!!" + currentReadLength); } this.currentReadPart = PackPart.Body; } else if (this.currentReadPart == PackPart.Body) { this.buffers.Add(reader.ReadBuffer(this.currentReadLength)); this.currentReadLength = PackHeaderBytesLen; this.currentReadPart = PackPart.Head; } } }
public override string Read() { return(WrappedReader == null ? "x,y" : WrappedReader.Read() + ",x,y"); }
public override string Read() { return(WrappedReader == null ? "paddle" : WrappedReader.Read() + ",paddle"); }
public virtual void ReadXml(XmlDictionaryReader reader, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer, SecurityTokenResolver outOfBandTokenResolver) { if (reader == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("ReadXml")); } if (samlSerializer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer")); } WrappedReader reader3 = new WrappedReader(XmlDictionaryReader.CreateDictionaryReader(reader)); SamlDictionary samlDictionary = samlSerializer.DictionaryManager.SamlDictionary; if (!reader3.IsStartElement(samlDictionary.Assertion, samlDictionary.Namespace)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLElementNotRecognized", new object[] { reader3.LocalName }))); } string attribute = reader3.GetAttribute(samlDictionary.MajorVersion, null); if (string.IsNullOrEmpty(attribute)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLAssertionMissingMajorVersionAttributeOnRead"))); } int num = int.Parse(attribute, CultureInfo.InvariantCulture); attribute = reader3.GetAttribute(samlDictionary.MinorVersion, null); if (string.IsNullOrEmpty(attribute)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLAssertionMissingMinorVersionAttributeOnRead"))); } int num2 = int.Parse(attribute, CultureInfo.InvariantCulture); if ((num != SamlConstants.MajorVersionValue) || (num2 != SamlConstants.MinorVersionValue)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLTokenVersionNotSupported", new object[] { num, num2, SamlConstants.MajorVersionValue, SamlConstants.MinorVersionValue }))); } attribute = reader3.GetAttribute(samlDictionary.AssertionId, null); if (string.IsNullOrEmpty(attribute)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLAssertionIdRequired"))); } if (!this.IsAssertionIdValid(attribute)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLAssertionIDIsInvalid", new object[] { attribute }))); } this.assertionId = attribute; attribute = reader3.GetAttribute(samlDictionary.Issuer, null); if (string.IsNullOrEmpty(attribute)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLAssertionMissingIssuerAttributeOnRead"))); } this.issuer = attribute; attribute = reader3.GetAttribute(samlDictionary.IssueInstant, null); if (!string.IsNullOrEmpty(attribute)) { this.issueInstant = DateTime.ParseExact(attribute, SamlConstants.AcceptedDateTimeFormats, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None).ToUniversalTime(); } reader3.MoveToContent(); reader3.Read(); if (reader3.IsStartElement(samlDictionary.Conditions, samlDictionary.Namespace)) { this.conditions = samlSerializer.LoadConditions(reader3, keyInfoSerializer, outOfBandTokenResolver); if (this.conditions == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLUnableToLoadCondtions"))); } } if (reader3.IsStartElement(samlDictionary.Advice, samlDictionary.Namespace)) { this.advice = samlSerializer.LoadAdvice(reader3, keyInfoSerializer, outOfBandTokenResolver); if (this.advice == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLUnableToLoadAdvice"))); } } while (reader3.IsStartElement()) { if (reader3.IsStartElement(samlSerializer.DictionaryManager.XmlSignatureDictionary.Signature, samlSerializer.DictionaryManager.XmlSignatureDictionary.Namespace)) { break; } SamlStatement item = samlSerializer.LoadStatement(reader3, keyInfoSerializer, outOfBandTokenResolver); if (item == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLUnableToLoadStatement"))); } this.statements.Add(item); } if (this.statements.Count == 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLAssertionRequireOneStatementOnRead"))); } if (reader3.IsStartElement(samlSerializer.DictionaryManager.XmlSignatureDictionary.Signature, samlSerializer.DictionaryManager.XmlSignatureDictionary.Namespace)) { this.ReadSignature(reader3, keyInfoSerializer, outOfBandTokenResolver, samlSerializer); } reader3.MoveToContent(); reader3.ReadEndElement(); this.tokenStream = reader3.XmlTokens; if (this.signature != null) { this.VerifySignature(this.signature, this.verificationKey); } this.BuildCryptoList(); }
public virtual void ReadXml(XmlDictionaryReader reader, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer, SecurityTokenResolver outOfBandTokenResolver) { if (reader == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("ReadXml")); } if (samlSerializer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer")); } XmlDictionaryReader dictionaryReader = XmlDictionaryReader.CreateDictionaryReader(reader); WrappedReader wrappedReader = new WrappedReader(dictionaryReader); #pragma warning suppress 56506 // samlSerializer.DictionaryManager is never null. SamlDictionary dictionary = samlSerializer.DictionaryManager.SamlDictionary; if (!wrappedReader.IsStartElement(dictionary.Assertion, dictionary.Namespace)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLElementNotRecognized, wrappedReader.LocalName))); } string attributeValue = wrappedReader.GetAttribute(dictionary.MajorVersion, null); if (string.IsNullOrEmpty(attributeValue)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLAssertionMissingMajorVersionAttributeOnRead))); } int majorVersion = Int32.Parse(attributeValue, CultureInfo.InvariantCulture); attributeValue = wrappedReader.GetAttribute(dictionary.MinorVersion, null); if (string.IsNullOrEmpty(attributeValue)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLAssertionMissingMinorVersionAttributeOnRead))); } int minorVersion = Int32.Parse(attributeValue, CultureInfo.InvariantCulture); if ((majorVersion != SamlConstants.MajorVersionValue) || (minorVersion != SamlConstants.MinorVersionValue)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLTokenVersionNotSupported, majorVersion, minorVersion, SamlConstants.MajorVersionValue, SamlConstants.MinorVersionValue))); } attributeValue = wrappedReader.GetAttribute(dictionary.AssertionId, null); if (string.IsNullOrEmpty(attributeValue)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLAssertionIdRequired))); } if (!IsAssertionIdValid(attributeValue)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLAssertionIDIsInvalid, attributeValue))); } this.assertionId = attributeValue; attributeValue = wrappedReader.GetAttribute(dictionary.Issuer, null); if (string.IsNullOrEmpty(attributeValue)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLAssertionMissingIssuerAttributeOnRead))); } this.issuer = attributeValue; attributeValue = wrappedReader.GetAttribute(dictionary.IssueInstant, null); if (!string.IsNullOrEmpty(attributeValue)) { this.issueInstant = DateTime.ParseExact( attributeValue, SamlConstants.AcceptedDateTimeFormats, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None).ToUniversalTime(); } wrappedReader.MoveToContent(); wrappedReader.Read(); if (wrappedReader.IsStartElement(dictionary.Conditions, dictionary.Namespace)) { this.conditions = samlSerializer.LoadConditions(wrappedReader, keyInfoSerializer, outOfBandTokenResolver); if (this.conditions == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLUnableToLoadCondtions))); } } if (wrappedReader.IsStartElement(dictionary.Advice, dictionary.Namespace)) { this.advice = samlSerializer.LoadAdvice(wrappedReader, keyInfoSerializer, outOfBandTokenResolver); if (this.advice == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLUnableToLoadAdvice))); } } while (wrappedReader.IsStartElement()) { #pragma warning suppress 56506 // samlSerializer.DictionaryManager is never null. if (wrappedReader.IsStartElement(samlSerializer.DictionaryManager.XmlSignatureDictionary.Signature, samlSerializer.DictionaryManager.XmlSignatureDictionary.Namespace)) { break; } else { SamlStatement statement = samlSerializer.LoadStatement(wrappedReader, keyInfoSerializer, outOfBandTokenResolver); if (statement == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLUnableToLoadStatement))); } this.statements.Add(statement); } } if (this.statements.Count == 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLAssertionRequireOneStatementOnRead))); } if (wrappedReader.IsStartElement(samlSerializer.DictionaryManager.XmlSignatureDictionary.Signature, samlSerializer.DictionaryManager.XmlSignatureDictionary.Namespace)) { this.ReadSignature(wrappedReader, keyInfoSerializer, outOfBandTokenResolver, samlSerializer); } wrappedReader.MoveToContent(); wrappedReader.ReadEndElement(); this.tokenStream = wrappedReader.XmlTokens; if (this.signature != null) { VerifySignature(this.signature, this.verificationKey); } BuildCryptoList(); }
public abstract void OnUdpMessageInput(IUdpSession session, ref WrappedReader reader, WrappedArgs args);
public override string Read() { return(WrappedReader == null ? "type" : WrappedReader.Read() + ",type"); }