Example #1
0
        private async Task <NodeGreetingMessage> ReadGreetingAsync(CancellationToken cancellationToken)
        {
            var read = await _streamSocket.ReadAsync(_singleByteBuffer, 0, 1, cancellationToken).ConfigureAwait(false);

            if (read == 0)
            {
                throw new RedFoxProtocolException("Error receiving greeting message from remote machine");
            }

            var headerLength = _singleByteBuffer[0];
            var header       = new byte[headerLength];

            var offset = 0;

            while (headerLength - offset > 0)
            {
                read = await _streamSocket.ReadAsync(header, offset, headerLength - offset, cancellationToken);

                if (read == 0)
                {
                    throw new RedFoxProtocolException("Error receiving greeting message from remote machine");
                }
                offset += read;
            }

            return(NodeGreetingMessage.DeserializeWithoutLength(header));
        }
Example #2
0
        private NodeGreetingMessage ReadGreeting()
        {
            var read = _streamSocket.Read(_singleByteBuffer, 0, 1);

            if (read == 0)
            {
                throw new RedFoxProtocolException("Error receiving greeting message from remote machine");
            }

            var headerLength = _singleByteBuffer[0];
            var header       = new byte[headerLength];

            var offset = 0;

            while (headerLength - offset > 0)
            {
                read = _streamSocket.Read(header, offset, headerLength - offset);
                if (read == 0)
                {
                    throw new RedFoxProtocolException("Error receiving greeting message from remote machine");
                }
                offset += read;
            }

            return(NodeGreetingMessage.DeserializeWithoutLength(header));
        }
        public NodeGreetingMessageVerifier(NodeType localNodeType, NodeType expectedRemoteNodeType, params NodeType[] allowOtherRemoteNoteTypes)
        {
            _expectedRemoteNodeTypes = new HashSet<NodeType> { expectedRemoteNodeType };
            if (allowOtherRemoteNoteTypes != null) _expectedRemoteNodeTypes.UnionWith(allowOtherRemoteNoteTypes);

            _greetingMessage = new NodeGreetingMessage(localNodeType);
        }
        public void WriteGreeting(NodeGreetingMessage greetingMessage)
        {
            var messageFrame = new MessageFrame {
                RawMessage = greetingMessage.Serialize()
            };

            _queueSocket.Write(messageFrame);
        }
        public NodeGreetingMessageVerifier(NodeType localNodeType, NodeType expectedRemoteNodeType, params NodeType[] allowOtherRemoteNoteTypes)
        {
            _expectedRemoteNodeTypes = new HashSet <NodeType> {
                expectedRemoteNodeType
            };
            if (allowOtherRemoteNoteTypes != null)
            {
                _expectedRemoteNodeTypes.UnionWith(allowOtherRemoteNoteTypes);
            }

            _greetingMessage = new NodeGreetingMessage(localNodeType);
        }
        public static NodeGreetingMessage DeserializeWithoutLength(byte[] buffer, int offset = 0)
        {
            if (buffer == null) throw new ArgumentNullException("buffer");
            if (buffer.Length < 2) 
                throw new RedFoxProtocolException(String.Format("Protocol header (excluding size) must have at least 2 bytes payload but had only {0} bytes", buffer.Length));

            if (buffer[offset] != ProtocolVersion)
                throw new RedFoxProtocolException(String.Format("Protocol version {0} is not supported (expected {1})", buffer[0], ProtocolVersion));

            var message = new NodeGreetingMessage((NodeType)buffer[offset + 1]);
            return message;
        }
Example #7
0
        public static NodeGreetingMessage DeserializeWithoutLength(byte[] buffer, int offset = 0)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }
            if (buffer.Length < 2)
            {
                throw new RedFoxProtocolException(String.Format("Protocol header (excluding size) must have at least 2 bytes payload but had only {0} bytes", buffer.Length));
            }

            if (buffer[offset] != ProtocolVersion)
            {
                throw new RedFoxProtocolException(String.Format("Protocol version {0} is not supported (expected {1})", buffer[0], ProtocolVersion));
            }

            var message = new NodeGreetingMessage((NodeType)buffer[offset + 1]);

            return(message);
        }
 public async Task WriteGreetingAsync(NodeGreetingMessage greetingMessage, CancellationToken cancellationToken)
 {
     WriteGreeting(greetingMessage);
 }
 public void WriteGreeting(NodeGreetingMessage greetingMessage)
 {
     var messageFrame = new MessageFrame { RawMessage = greetingMessage.Serialize() };
     _queueSocket.Write(messageFrame);
 }
Example #10
0
 public async Task WriteGreetingAsync(NodeGreetingMessage greetingMessage, CancellationToken cancellationToken)
 {
     var serialized = greetingMessage.Serialize();
     await _streamSocket.WriteAsync(serialized, 0, serialized.Length, cancellationToken);
 }
Example #11
0
        public void WriteGreeting(NodeGreetingMessage greetingMessage)
        {
            var serialized = greetingMessage.Serialize();

            _streamSocket.Write(serialized, 0, serialized.Length);
        }
 public async Task WriteGreetingAsync(NodeGreetingMessage greetingMessage, CancellationToken cancellationToken)
 {
     var serialized = greetingMessage.Serialize();
     await _streamSocket.WriteAsync(serialized, 0, serialized.Length, cancellationToken);
 }
 public void WriteGreeting(NodeGreetingMessage greetingMessage)
 {
     var serialized = greetingMessage.Serialize();
     _streamSocket.Write(serialized, 0, serialized.Length);
 }
        private NodeGreetingMessage ReadGreeting()
        {
            var messageFrame = _queueSocket.Read();

            return(NodeGreetingMessage.DeserializeWithoutLength(messageFrame.RawMessage, 1));
        }
 public async Task WriteGreetingAsync(NodeGreetingMessage greetingMessage, CancellationToken cancellationToken)
 {
     WriteGreeting(greetingMessage);
 }