public async Task is_static_should_report_correctly() { _staticNodesManager.IsStatic(Enode).Should().BeFalse(); await _staticNodesManager.AddAsync(Enode, false); _staticNodesManager.IsStatic(Enode).Should().BeTrue(); }
private void ProcessIncomingConnection(ISession session) { void CheckIfNodeIsStatic(Node node) { if (_staticNodesManager.IsStatic(node.ToString("e"))) { node.IsStatic = true; } } CheckIfNodeIsStatic(session.Node); if (_logger.IsTrace) { _logger.Trace($"INCOMING {session}"); } // if we have already initiated connection before if (_activePeers.TryGetValue(session.RemoteNodeId, out Peer existingActivePeer)) { AddSession(session, existingActivePeer); return; } if (!session.Node.IsStatic && _activePeers.Count >= MaxActivePeers) { int initCount = 0; foreach (KeyValuePair <PublicKey, Peer> pair in _activePeers) { // we need to count initialized as we may have a list of active peers that is just being initialized // and we do not know yet whether they are fine or not if (pair.Value.InSession?.State == SessionState.Initialized || pair.Value.OutSession?.State == SessionState.Initialized) { initCount++; } } if (initCount >= MaxActivePeers) { if (_logger.IsTrace) { _logger.Trace($"Initiating disconnect with {session} {DisconnectReason.TooManyPeers} {DisconnectType.Local}"); } session.InitiateDisconnect(DisconnectReason.TooManyPeers, $"{initCount}"); return; } } Peer peer = _peerPool.GetOrAdd(session.Node); AddSession(session, peer); }