Пример #1
0
        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);
        }
Пример #2
0
 public bool IsSameExtension(HandshakeExtension other)
 {
     if (other == null)
     {
         throw new ArgumentNullException("other");
     }
     return(Name.Equals(other.Name));
 }
Пример #3
0
 public void ResetRead()
 {
     _state = HandshakeFrameState.VersionMajor;
     _receiveStateBytesLeft = 1; //identity length
     _receiveBufferOffset   = 0;
     _receiveStateLength    = -1;
     RequiredExtensions     = new HandshakeExtension[0];
     OptionalExtensions     = new HandshakeExtension[0];
     Identity = "";
 }
Пример #4
0
        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
            };
        }
Пример #5
0
        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;
        }
Пример #7
0
 protected bool Equals(HandshakeExtension other)
 {
     return(string.Equals(Name, other.Name));
 }
Пример #8
0
 public void Parse(HandshakeExtension info)
 {
 }
Пример #9
0
 public HandshakeExtension Negotiate(HandshakeExtension remoteEndPointExtension)
 {
     return new HandshakeExtension(Name);
 }
Пример #10
0
 public bool IsSameExtension(HandshakeExtension other)
 {
     if (other == null) throw new ArgumentNullException("other");
     return Name.Equals(other.Name);
 }
Пример #11
0
 protected bool Equals(HandshakeExtension other)
 {
     return string.Equals(Name, other.Name);
 }
Пример #12
0
 public HandshakeFrame()
 {
     RequiredExtensions = new HandshakeExtension[0];
     OptionalExtensions = new HandshakeExtension[0];
     Identity = "";
 }
Пример #13
0
 public void ResetRead()
 {
     _state = HandshakeFrameState.VersionMajor;
     _receiveStateBytesLeft = 1; //identity length
     _receiveBufferOffset = 0;
     _receiveStateLength = -1;
     RequiredExtensions = new HandshakeExtension[0];
     OptionalExtensions = new HandshakeExtension[0];
     Identity = "";
 }
Пример #14
0
 public HandshakeFrame()
 {
     RequiredExtensions = new HandshakeExtension[0];
     OptionalExtensions = new HandshakeExtension[0];
     Identity           = "";
 }
Пример #15
0
        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;
        }