private void InitEthProtocol(ISession session, Eth62ProtocolHandler handler) { handler.ProtocolInitialized += (sender, args) => { if (!RunBasicChecks(session, handler.ProtocolCode, handler.ProtocolVersion)) { return; } var typedArgs = (EthProtocolInitializedEventArgs)args; _stats.ReportEthInitializeEvent(session.Node, new EthNodeDetails { ChainId = typedArgs.ChainId, BestHash = typedArgs.BestHash, GenesisHash = typedArgs.GenesisHash, ProtocolVersion = typedArgs.ProtocolVersion, TotalDifficulty = typedArgs.TotalDifficulty }); bool isValid = _protocolValidator.DisconnectOnInvalid(Protocol.Eth, session, args); if (isValid) { handler.ClientId = session.Node.ClientId; if (_syncPeers.TryAdd(session.SessionId, handler)) { _syncManager.AddPeer(handler); _transactionPool.AddPeer(handler); if (_logger.IsDebug) { _logger.Debug($"{handler.ClientId} sync peer {session} created."); } } else { if (_logger.IsTrace) { _logger.Trace($"Not able to add a sync peer on {session} for {session.Node:s}"); } session.InitiateDisconnect(DisconnectReason.AlreadyConnected, "sync peer"); } if (_logger.IsTrace) { _logger.Trace($"Finalized ETH protocol initialization on {session} - adding sync peer {session.Node:s}"); } //Add/Update peer to the storage and to sync manager _peerStorage.UpdateNodes(new[] { new NetworkNode(session.Node.Id, session.Node.Host, session.Node.Port, _stats.GetOrAdd(session.Node).NewPersistedNodeReputation) }); } else { if (_logger.IsTrace) { _logger.Trace($"|NetworkTrace| {handler.ProtocolCode}{handler.ProtocolVersion} is invalid on {session}"); } } }; }
public void should_add_peers() { _transactionPool = CreatePool(_noTransactionStorage); var peers = GetPeers(); foreach ((ISynchronizationPeer peer, _) in peers) { _transactionPool.AddPeer(peer); } }
public void should_delete_peers() { _transactionPool = CreatePool(_noTransactionStorage); var peers = GetPeers(); foreach ((ISynchronizationPeer peer, _) in peers) { _transactionPool.AddPeer(peer); } foreach ((ISynchronizationPeer peer, _) in peers) { _transactionPool.RemovePeer(peer.Node.Id); } }
private void InitEthProtocol(ISession session, Eth62ProtocolHandler handler) { handler.ProtocolInitialized += (sender, args) => { if (!RunBasicChecks(session, handler.ProtocolCode, handler.ProtocolVersion)) { return; } var typedArgs = (EthProtocolInitializedEventArgs)args; _stats.ReportEthInitializeEvent(session.Node, new EthNodeDetails { ChainId = typedArgs.ChainId, BestHash = typedArgs.BestHash, GenesisHash = typedArgs.GenesisHash, ProtocolVersion = typedArgs.ProtocolVersion, TotalDifficulty = typedArgs.TotalDifficulty }); bool isValid = _protocolValidator.DisconnectOnInvalid(Protocol.Eth, session, args); if (isValid) { if (_syncPeers.TryAdd(session.SessionId, handler)) { _syncManager.AddPeer(handler); _transactionPool.AddPeer(handler); } else { session.InitiateDisconnect(DisconnectReason.ClientQuitting); } handler.ClientId = session.Node.ClientId; if (_logger.IsTrace) { _logger.Trace($"Eth version {handler.ProtocolVersion} initialized, adding sync peer: {session.Node.Id}"); } //Add/Update peer to the storage and to sync manager _peerStorage.UpdateNodes(new[] { new NetworkNode(session.Node.Id, session.Node.Host, session.Node.Port, _stats.GetOrAdd(session.Node).NewPersistedNodeReputation) }); } if (_logger.IsTrace) { _logger.Trace($"ETH Protocol Initialized: {session.RemoteNodeId}"); } }; }