public static HandshakeExtension Parse(string nameAndProperties) { var pos = nameAndProperties.IndexOf(':'); if (pos == -1) { return(new HandshakeExtension(nameAndProperties)); } var extension = new HandshakeExtension(nameAndProperties.Substring(0, pos)); var properties = nameAndProperties.Substring(pos + 1).Split(','); foreach (var property in properties) { pos = property.IndexOf('='); if (pos == -1) { throw new FormatException( "Extension was not formatted correctly, missing equal sign for a property. Extension: " + nameAndProperties); } var key = property.Substring(0, pos); var value = Uri.UnescapeDataString(property.Substring(pos + 1)); extension.Properties.Add(key, value); } return(extension); }
public bool IsSameExtension(HandshakeExtension other) { if (other == null) { throw new ArgumentNullException("other"); } return(Name.Equals(other.Name)); }
public void ResetRead() { _state = HandshakeFrameState.VersionMajor; _receiveStateBytesLeft = 1; //identity length _receiveBufferOffset = 0; _receiveStateLength = -1; RequiredExtensions = new HandshakeExtension[0]; OptionalExtensions = new HandshakeExtension[0]; Identity = ""; }
public IAckSender CreateAckSender(IConnection connection, byte extensionId, HandshakeExtension extProperties) { var msgsPerAck = MessagesPerAck; if (extProperties.Properties.ContainsKey("MessagesPerAck")) msgsPerAck = int.Parse(extProperties.Properties["MessagesPerAck"]); var expire = AckExpireTime; if (extProperties.Properties.ContainsKey("AckExpireTime")) expire = TimeSpan.FromMilliseconds(int.Parse(extProperties.Properties["AckExpireTime"])); return new AckSender(connection, extensionId) { Threshold = msgsPerAck, TimeoutBeforeSendingAck = expire }; }
public IAckReceiver CreateAckReceiver(IConnection connection, byte extensionId, Action<MessageFrame> deliverMessageMethod, HandshakeExtension extProperties) { var msgsPerAck = MessagesPerAck; if (extProperties.Properties.ContainsKey("MessagesPerAck")) msgsPerAck = int.Parse(extProperties.Properties["MessagesPerAck"]); var expire = AckExpireTime; if (extProperties.Properties.ContainsKey("AckExpireTime")) expire = TimeSpan.FromMilliseconds(int.Parse(extProperties.Properties["AckExpireTime"])); return new AckReceiver(connection, deliverMessageMethod, MessagesPerAck) { TimeoutBeforeResendingMessage = expire.Add(TimeSpan.FromMilliseconds(20)) //for network latency }; }
public static HandshakeExtension Parse(string nameAndProperties) { var pos = nameAndProperties.IndexOf(':'); if (pos == -1) { return new HandshakeExtension(nameAndProperties); } var extension = new HandshakeExtension(nameAndProperties.Substring(0, pos)); var properties = nameAndProperties.Substring(pos + 1).Split(','); foreach (var property in properties) { pos = property.IndexOf('='); if (pos == -1) throw new FormatException( "Extension was not formatted correctly, missing equal sign for a property. Extension: " + nameAndProperties); var key = property.Substring(0, pos); var value = Uri.UnescapeDataString(property.Substring(pos + 1)); extension.Properties.Add(key, value); } return extension; }
protected bool Equals(HandshakeExtension other) { return(string.Equals(Name, other.Name)); }
public void Parse(HandshakeExtension info) { }
public HandshakeExtension Negotiate(HandshakeExtension remoteEndPointExtension) { return new HandshakeExtension(Name); }
public bool IsSameExtension(HandshakeExtension other) { if (other == null) throw new ArgumentNullException("other"); return Name.Equals(other.Name); }
protected bool Equals(HandshakeExtension other) { return string.Equals(Name, other.Name); }
public HandshakeFrame() { RequiredExtensions = new HandshakeExtension[0]; OptionalExtensions = new HandshakeExtension[0]; Identity = ""; }
public HandshakeExtension Negotiate(HandshakeExtension remoteEndPointExtension) { var frame = new HandshakeExtension(Name); if (remoteEndPointExtension.Properties.ContainsKey("MessagesPerAck")) { var value = Math.Max(int.Parse(remoteEndPointExtension.Properties["MessagesPerAck"]), MessagesPerAck); frame.Properties.Add("MessagesPerAck", value.ToString()); } if (remoteEndPointExtension.Properties.ContainsKey("AckExpireTime")) { var value = Math.Min(int.Parse(remoteEndPointExtension.Properties["AckExpireTime"]), AckExpireTime.TotalMilliseconds); frame.Properties.Add("AckExpireTime", value.ToString()); } return frame; }