Ejemplo n.º 1
0
 public ConnectionStatus(IConnection connection, OmniAddress address, ConnectionHandshakeType handshakeType)
 {
     this.Connection    = connection;
     this.Address       = address;
     this.HandshakeType = handshakeType;
 }
Ejemplo n.º 2
0
        private async ValueTask AddConnectionAsync(IConnection connection, OmniAddress address, ConnectionHandshakeType handshakeType, CancellationToken cancellationToken = default)
        {
            var status = new ConnectionStatus(connection, address, handshakeType);

            var myNodeProflie = new NodeProfile(await _connectionController.GetListenEndpointsAsync(cancellationToken));

            var myHelloMessage = new NodeExplorerHelloMessage(_myId, myNodeProflie);
            NodeExplorerHelloMessage?otherHelloMessage = null;

            var enqueueTask = connection.EnqueueAsync((bufferWriter) => myNodeProflie.Export(bufferWriter, _bytesPool), cancellationToken);
            var dequeueTask = connection.DequeueAsync((sequence) => otherHelloMessage = NodeExplorerHelloMessage.Import(sequence, _bytesPool), cancellationToken);

            await ValueTaskHelper.WhenAll(enqueueTask, dequeueTask);

            if (otherHelloMessage == null)
            {
                return;
            }

            status.Id          = otherHelloMessage.Id;
            status.NodeProfile = otherHelloMessage.NodeProfile;

            lock (_lockObject)
            {
                _connections.Add(status);
            }
        }