private void OnNodeDiscovered(object sender, NodeEventArgs nodeEventArgs) { if (_logger.IsTrace) { _logger.Trace($"|NetworkTrace| {nodeEventArgs.Node:e} node discovered"); } PublicKey id = nodeEventArgs.Node.Id; if (_candidatePeers.ContainsKey(id)) { return; } Peer peer = new Peer(nodeEventArgs.Node); if (!_candidatePeers.TryAdd(id, peer)) { return; } _stats.ReportEvent(peer.Node, NodeStatsEventType.NodeDiscovered); if (_logger.IsTrace) { _logger.Trace($"{nodeEventArgs.Node:s} added to candidate nodes"); } if (pending < AvailableActivePeersCount) { #pragma warning disable 4014 // fire and forget - all the surrounding logic will be executed // exceptions can be lost here without issues SetupPeerConnection(peer); #pragma warning restore 4014 } if (_isStarted) { _peerUpdateRequested.Set(); } }
private void OnNodeDiscovered(object sender, NodeEventArgs nodeEventArgs) { if (_logger.IsTrace) { _logger.Trace($"|NetworkTrace| {nodeEventArgs.Node:e} node discovered"); } Peer peer = _peerPool.GetOrAdd(nodeEventArgs.Node); lock (_peerPool) { int newPeerPoolLength = _peerPool.CandidatePeerCount; _lastPeerPoolLength = newPeerPoolLength; if (_lastPeerPoolLength > _maxPeerPoolLength + 100) { _maxPeerPoolLength = _lastPeerPoolLength; if (_logger.IsDebug) { _logger.Debug($"Peer pool size is: {_lastPeerPoolLength}"); } } } _stats.ReportEvent(nodeEventArgs.Node, NodeStatsEventType.NodeDiscovered); if (_pending < AvailableActivePeersCount) { #pragma warning disable 4014 // fire and forget - all the surrounding logic will be executed // exceptions can be lost here without issues // this for rapid connections to newly discovered peers without having to go through the UpdatePeerLoop SetupPeerConnection(peer); #pragma warning restore 4014 } if (_isStarted) { _peerUpdateRequested.Set(); } }