Beispiel #1
0
        private void OnRemoteConnectionInitialized(object sender, ConnectionInitializedEventArgs eventArgs)
        {
            var id = eventArgs.Session.RemoteNodeId;

            if (!_activePeers.TryGetValue(id, out Peer peer))
            {
                if (_logger.IsErrorEnabled)
                {
                    _logger.Error($"Initiated rlpx connection with Peer without adding it to Active collection: {id.ToString(false)}");
                }
                return;
            }

            peer.Session = eventArgs.Session;
            peer.Session.PeerDisconnected    += OnPeerDisconnected;
            peer.Session.ProtocolInitialized += async(s, e) => await OnProtocolInitialized(s, e);

            if (!_isDiscoveryEnabled || peer.NodeLifecycleManager != null)
            {
                return;
            }

            //In case peer was initiated outside of discovery and discovery is enabled, we are adding it to discovery for future use (e.g. trusted peer)
            var manager = _discoveryManager.GetNodeLifecycleManager(peer.Node);

            peer.NodeLifecycleManager = manager;
        }
Beispiel #2
0
        private void OnRemoteConnectionInitialized(object sender, ConnectionInitializedEventArgs eventArgs)
        {
            if (eventArgs.ClientConnectionType == ClientConnectionType.In)
            {
                //If connection was initiated by remote peer we allow handshake to take place before potencially disconnecting
                eventArgs.Session.ProtocolInitialized += async(s, e) => await OnProtocolInitialized(s, e);

                eventArgs.Session.PeerDisconnected += async(s, e) => await OnPeerDisconnected(s, e);

                if (_logger.IsInfoEnabled)
                {
                    _logger.Info($"Initiated IN connection (PeerManager)(handshake completed) for peer: {eventArgs.Session.RemoteNodeId}");
                }
                return;
            }

            var id = eventArgs.Session.RemoteNodeId;

            if (!_activePeers.TryGetValue(id, out Peer peer))
            {
                if (_logger.IsErrorEnabled)
                {
                    _logger.Error($"Initiated rlpx connection (out) with Peer without adding it to Active collection: {id}");
                }
                return;
            }

            peer.ClientConnectionType = eventArgs.ClientConnectionType;
            peer.Session = eventArgs.Session;
            peer.Session.PeerDisconnected += async(s, e) => await OnPeerDisconnected(s, e);

            peer.Session.ProtocolInitialized += async(s, e) => await OnProtocolInitialized(s, e);

            if (_logger.IsInfoEnabled)
            {
                _logger.Info($"Initializing OUT connection (PeerManager) for peer: {eventArgs.Session.RemoteNodeId}");
            }

            if (!_isDiscoveryEnabled || peer.NodeLifecycleManager != null)
            {
                return;
            }

            //In case peer was initiated outside of discovery and discovery is enabled, we are adding it to discovery for future use (e.g. trusted peer)
            var manager = _discoveryManager.GetNodeLifecycleManager(peer.Node);

            peer.NodeLifecycleManager = manager;
        }