Ejemplo n.º 1
0
        private IBoltProtocol SelectBoltProtocol(BoltProtocolVersion version, IDictionary <string, string> routingContext)
        {
            var boltProtocol = BoltProtocolFactory.ForVersion(version, routingContext);

            Reader = boltProtocol.NewReader(_tcpSocketClient.ReadStream, _bufferSettings, _logger);
            Writer = boltProtocol.NewWriter(_tcpSocketClient.WriteStream, _bufferSettings, _logger);
            return(boltProtocol);
        }
Ejemplo n.º 2
0
        private IBoltProtocol SelectBoltProtocol(int version)
        {
            var boltProtocol = BoltProtocolFactory.ForVersion(version);

            Reader = boltProtocol.NewReader(_tcpSocketClient.ReadStream, _bufferSettings, _logger);
            Writer = boltProtocol.NewWriter(_tcpSocketClient.WriteStream, _bufferSettings, _logger);
            return(boltProtocol);
        }
Ejemplo n.º 3
0
        public void Start()
        {
            _connMetricsListener?.ConnectionConnecting(_connEvent);
            _tcpSocketClient.Connect(_uri);

            SetOpened();
            _logger?.Debug($"~~ [CONNECT] {_uri}");
            _connMetricsListener?.ConnectionConnected(_connEvent);

            var version = DoHandshake();

            _boltProtocol = BoltProtocolFactory.Create(version, _tcpSocketClient, _bufferSettings, _logger);
        }
Ejemplo n.º 4
0
        public Task StartAsync()
        {
            TaskCompletionSource <object> tcs = new TaskCompletionSource <object>();

            _connMetricsListener?.ConnectionConnecting(_connEvent);
            _tcpSocketClient.ConnectAsync(_uri)
            .ContinueWith(t =>
            {
                if (t.IsFaulted)
                {
                    tcs.SetException(t.Exception.GetBaseException());
                }
                else if (t.IsCanceled)
                {
                    tcs.SetCanceled();
                }
                else
                {
                    SetOpened();
                    _logger?.Debug($"~~ [CONNECT] {_uri}");
                    _connMetricsListener?.ConnectionConnected(_connEvent);
                    return(DoHandshakeAsync());
                }

                return(Task.FromResult(-1));
            }, TaskContinuationOptions.ExecuteSynchronously).Unwrap()
            .ContinueWith(t =>
            {
                int version = t.Result;

                if (version != -1)
                {
                    try
                    {
                        _boltProtocol = BoltProtocolFactory.Create(version, _tcpSocketClient, _bufferSettings, _logger);
                        tcs.SetResult(null);
                    }
                    catch (AggregateException exc)
                    {
                        tcs.SetException(exc.GetBaseException());
                    }
                    catch (Exception exc)
                    {
                        tcs.SetException(exc);
                    }
                }
            }, TaskContinuationOptions.ExecuteSynchronously);

            return(tcs.Task);
        }
Ejemplo n.º 5
0
        private int DoHandshake()
        {
            var data = BoltProtocolFactory.PackSupportedVersions();

            _tcpSocketClient.WriteStream.Write(data, 0, data.Length);
            _tcpSocketClient.WriteStream.Flush();
            _logger?.Debug("C: [HANDSHAKE] ", data);

            data = new byte[4];
            _tcpSocketClient.ReadStream.Read(data, 0, data.Length);

            var agreedVersion = BoltProtocolFactory.UnpackAgreedVersion(data);

            _logger?.Debug($"S: [HANDSHAKE] {agreedVersion}");
            return(agreedVersion);
        }
Ejemplo n.º 6
0
        private async Task <int> DoHandshakeAsync()
        {
            var data = BoltProtocolFactory.PackSupportedVersions();
            await _tcpSocketClient.WriteStream.WriteAsync(data, 0, data.Length).ConfigureAwait(false);

            await _tcpSocketClient.WriteStream.FlushAsync().ConfigureAwait(false);

            _logger?.Debug("C: [HANDSHAKE] ", data);

            data = new byte[4];
            await _tcpSocketClient.ReadStream.ReadAsync(data, 0, data.Length).ConfigureAwait(false);

            var agreedVersion = BoltProtocolFactory.UnpackAgreedVersion(data);

            _logger?.Debug($"S: [HANDSHAKE] {agreedVersion}");
            return(agreedVersion);
        }
Ejemplo n.º 7
0
        private async Task <BoltProtocolVersion> DoHandshakeAsync()
        {
            var data = BoltProtocolFactory.PackSupportedVersions(NumSupportedVersions);
            await _tcpSocketClient.WriteStream.WriteAsync(data, 0, data.Length).ConfigureAwait(false);

            await _tcpSocketClient.WriteStream.FlushAsync().ConfigureAwait(false);

            _logger?.Debug("C: [HANDSHAKE] {0}", data.ToHexString());

            data = new byte[4];
            var read = await _tcpSocketClient.ReadStream.ReadAsync(data, 0, data.Length).ConfigureAwait(false);

            if (read < data.Length)
            {
                throw new IOException($"Unexpected end of stream when performing handshake, read returned {read}");
            }

            var agreedVersion = BoltProtocolFactory.UnpackAgreedVersion(data);

            _logger?.Debug("S: [HANDSHAKE] {0}.{1}", agreedVersion.MajorVersion, agreedVersion.MinorVersion);
            return(agreedVersion);
        }