public ConnectionManager( IDateTimeProvider dateTimeProvider, ILoggerFactory loggerFactory, Network network, INetworkPeerFactory networkPeerFactory, NodeSettings nodeSettings, INodeLifetime nodeLifetime, NetworkPeerConnectionParameters parameters, IPeerAddressManager peerAddressManager, IEnumerable <IPeerConnector> peerConnectors, IPeerDiscovery peerDiscovery, ConnectionManagerSettings connectionSettings) { this.connectedPeers = new NetworkPeerCollection(); this.dateTimeProvider = dateTimeProvider; this.loggerFactory = loggerFactory; this.logger = loggerFactory.CreateLogger(this.GetType().FullName); this.Network = network; this.NetworkPeerFactory = networkPeerFactory; this.NodeSettings = nodeSettings; this.nodeLifetime = nodeLifetime; this.peerAddressManager = peerAddressManager; this.PeerConnectors = peerConnectors; this.peerDiscovery = peerDiscovery; this.ConnectionSettings = connectionSettings; this.Servers = new List <NetworkPeerServer>(); this.Parameters = parameters; this.Parameters.ConnectCancellation = this.nodeLifetime.ApplicationStopping; this.Parameters.UserAgent = $"{this.NodeSettings.Agent}:{this.GetVersion()}"; this.Parameters.Version = this.NodeSettings.ProtocolVersion; }
private bool ConnectToPeer(PeerAddressManager peerAddressManager, Mock <INetworkPeerFactory> networkPeerFactoryExisting, ConnectionManagerSettings connectionManagerSettingsExisting, PeerConnectorConnectNode peerConnector, IPEndPoint endpointNode, Mock <IConnectionManager> mockConnectionManager) { peerAddressManager.AddPeer(endpointNode, IPAddress.Loopback); var networkPeer = new Mock <INetworkPeer>(); networkPeer.SetupGet(np => np.PeerEndPoint).Returns(new IPEndPoint(endpointNode.Address, endpointNode.Port)); networkPeer.SetupGet(np => np.RemoteSocketAddress).Returns(endpointNode.Address); networkPeer.SetupGet(np => np.RemoteSocketPort).Returns(endpointNode.Port); networkPeer.SetupGet(np => np.State).Returns(NetworkPeerState.HandShaked); networkPeerFactoryExisting.Setup(npf => npf.CreateConnectedNetworkPeerAsync(It.Is <IPEndPoint>(x => Equals(x, endpointNode)), It.IsAny <NetworkPeerConnectionParameters>(), It.IsAny <NetworkPeerDisposer>())).Returns(Task.FromResult(networkPeer.Object)); connectionManagerSettingsExisting.AddNode.Add(endpointNode); connectionManagerSettingsExisting.Connect.Add(endpointNode); NetworkPeerCollection connectedPeers = (NetworkPeerCollection)mockConnectionManager.Object.ConnectedPeers; foreach (INetworkPeer peer in peerConnector.ConnectorPeers) { if (!connectedPeers.Contains(peer)) { connectedPeers.Add(peer); } } mockConnectionManager.SetupGet(np => np.ConnectedPeers).Returns(connectedPeers); peerConnector.Initialize(mockConnectionManager.Object); peerConnector.OnConnectAsync().GetAwaiter().GetResult(); return(peerConnector.ConnectorPeers.Select(p => p.PeerEndPoint).Contains(endpointNode)); }
public ConnectionManager( Network network, NetworkPeerConnectionParameters parameters, NodeSettings nodeSettings, ILoggerFactory loggerFactory, INodeLifetime nodeLifetime, IAsyncLoopFactory asyncLoopFactory, IPeerAddressManager peerAddressManager, IDateTimeProvider dateTimeProvider, INetworkPeerFactory networkPeerFactory) { this.dateTimeProvider = dateTimeProvider; this.Network = network; this.NodeSettings = nodeSettings; this.nodeLifetime = nodeLifetime; this.Parameters = parameters; this.Parameters.ConnectCancellation = this.nodeLifetime.ApplicationStopping; this.loggerFactory = loggerFactory; this.logger = loggerFactory.CreateLogger(this.GetType().FullName); this.asyncLoopFactory = asyncLoopFactory; this.peerAddressManager = peerAddressManager; this.networkPeerFactory = networkPeerFactory; this.Servers = new List <NetworkPeerServer>(); this.connectedNodes = new NetworkPeerCollection(); }
private IEnumerable <INetworkPeer> GetConnectedLegacyPeersSortedByTip(NetworkPeerCollection connectedPeers) { return(from peer in connectedPeers.ToList() // not sure if connectedPeers can change, so i use ToList to get a snapshot let isLegacy = peer.PeerVersion.Version < NBitcoin.Protocol.ProtocolVersion.PROVEN_HEADER_VERSION let tip = peer.Behavior <ProvenHeadersConsensusManagerBehavior>()?.BestReceivedTip?.Height ?? 0 where isLegacy orderby tip select peer); }
public ConnectionManager(IDateTimeProvider dateTimeProvider, ILoggerFactory loggerFactory, Network network, INetworkPeerFactory networkPeerFactory, NodeSettings nodeSettings, INodeLifetime nodeLifetime, NetworkPeerConnectionParameters parameters, IPeerAddressManager peerAddressManager, IEnumerable <IPeerConnector> peerConnectors, IPeerDiscovery peerDiscovery, ISelfEndpointTracker selfEndpointTracker, ConnectionManagerSettings connectionSettings, IVersionProvider versionProvider, INodeStats nodeStats, IAsyncProvider asyncProvider) { this.connectedPeers = new NetworkPeerCollection(); this.dateTimeProvider = dateTimeProvider; this.loggerFactory = loggerFactory; this.logger = loggerFactory.CreateLogger(GetType().FullName); this.Network = network; this.NetworkPeerFactory = networkPeerFactory; this.NodeSettings = nodeSettings; this.nodeLifetime = nodeLifetime; this.asyncProvider = asyncProvider; this.peerAddressManager = peerAddressManager; this.PeerConnectors = peerConnectors; this.peerDiscovery = peerDiscovery; this.ConnectionSettings = connectionSettings; this.networkPeerDisposer = new NetworkPeerDisposer(this.loggerFactory, this.asyncProvider); this.Servers = new List <NetworkPeerServer>(); this.Parameters = parameters; this.Parameters.ConnectCancellation = this.nodeLifetime.ApplicationStopping; this.selfEndpointTracker = selfEndpointTracker; this.versionProvider = versionProvider; this.ipRangeFilteringEndpointExclusions = new List <IPEndPoint>(); this.connectedPeersQueue = asyncProvider.CreateAndRunAsyncDelegateDequeuer <INetworkPeer>( $"{nameof(ConnectionManager)}-{nameof(this.connectedPeersQueue)}", OnPeerAdded); this.disconnectedPerfCounter = new PerformanceCounter(); this.Parameters.UserAgent = $"{this.ConnectionSettings.Agent}:{versionProvider.GetVersion()} ({(int) this.NodeSettings.ProtocolVersion})"; this.Parameters.Version = this.NodeSettings.ProtocolVersion; nodeStats.RegisterStats(AddComponentStats, StatsType.Component, GetType().Name, 1100); }
public ConnectionManager(IDateTimeProvider dateTimeProvider, ILoggerFactory loggerFactory, Network network, INetworkPeerFactory networkPeerFactory, NodeSettings nodeSettings, INodeLifetime nodeLifetime, NetworkPeerConnectionParameters parameters, IPeerAddressManager peerAddressManager, IEnumerable <IPeerConnector> peerConnectors, IPeerDiscovery peerDiscovery, ISelfEndpointTracker selfEndpointTracker, ConnectionManagerSettings connectionSettings, IVersionProvider versionProvider, INodeStats nodeStats) { this.connectedPeers = new NetworkPeerCollection(); this.dateTimeProvider = dateTimeProvider; this.loggerFactory = loggerFactory; this.logger = loggerFactory.CreateLogger("Impleum.Bitcoin.FullNode"); this.Network = network; this.NetworkPeerFactory = networkPeerFactory; this.NodeSettings = nodeSettings; this.nodeLifetime = nodeLifetime; this.peerAddressManager = peerAddressManager; this.PeerConnectors = peerConnectors; this.peerDiscovery = peerDiscovery; this.ConnectionSettings = connectionSettings; this.networkPeerDisposer = new NetworkPeerDisposer(this.loggerFactory); this.Servers = new List <NetworkPeerServer>(); this.Parameters = parameters; this.Parameters.ConnectCancellation = this.nodeLifetime.ApplicationStopping; this.selfEndpointTracker = selfEndpointTracker; this.versionProvider = versionProvider; this.connectedPeersQueue = new AsyncQueue <INetworkPeer>(this.OnPeerAdded); this.disconnectedPerfCounter = new PerformanceCounter(); this.Parameters.UserAgent = $"{this.ConnectionSettings.Agent}:{versionProvider.GetVersion()} ({(int)this.NodeSettings.ProtocolVersion})"; this.Parameters.Version = this.NodeSettings.ProtocolVersion; nodeStats.RegisterStats(this.AddComponentStats, StatsType.Component, 1100); }
public ConnectionManager(IDateTimeProvider dateTimeProvider, ILoggerFactory loggerFactory, Network network, INetworkPeerFactory networkPeerFactory, NodeSettings nodeSettings, INodeLifetime nodeLifetime, NetworkPeerConnectionParameters parameters, IPeerAddressManager peerAddressManager, IEnumerable <IPeerConnector> peerConnectors, IPeerDiscovery peerDiscovery, ISelfEndpointTracker selfEndpointTracker, ConnectionManagerSettings connectionSettings, IVersionProvider versionProvider) { this.connectedPeers = new NetworkPeerCollection(); this.dateTimeProvider = dateTimeProvider; this.loggerFactory = loggerFactory; this.logger = loggerFactory.CreateLogger(this.GetType().FullName); this.Network = network; this.NetworkPeerFactory = networkPeerFactory; this.NodeSettings = nodeSettings; this.nodeLifetime = nodeLifetime; this.peerAddressManager = peerAddressManager; this.PeerConnectors = peerConnectors; this.peerDiscovery = peerDiscovery; this.ConnectionSettings = connectionSettings; this.networkPeerDisposer = new NetworkPeerDisposer(this.loggerFactory); this.Servers = new List <NetworkPeerServer>(); this.Parameters = parameters; this.Parameters.ConnectCancellation = this.nodeLifetime.ApplicationStopping; this.selfEndpointTracker = selfEndpointTracker; this.versionProvider = versionProvider; this.Parameters.UserAgent = $"{this.NodeSettings.Agent}:{versionProvider.GetVersion()}"; this.Parameters.Version = this.NodeSettings.ProtocolVersion; this.downloads = new Dictionary <INetworkPeer, PerformanceSnapshot>(); }
public void StoredPartialTransactionsTriggerSignatureRequest() { var dataFolder = new DataFolder(CreateTestDir(this)); this.Init(dataFolder); this.AddFunding(); this.AppendBlocks(this.federationGatewaySettings.MinCoinMaturity); MultiSigAddress multiSigAddress = this.wallet.MultiSigAddress; using (ICrossChainTransferStore crossChainTransferStore = this.CreateStore()) { crossChainTransferStore.Initialize(); crossChainTransferStore.Start(); Assert.Equal(this.chain.Tip.HashBlock, crossChainTransferStore.TipHashAndHeight.HashBlock); Assert.Equal(this.chain.Tip.Height, crossChainTransferStore.TipHashAndHeight.Height); BitcoinAddress address1 = (new Key()).PubKey.Hash.GetAddress(this.network); BitcoinAddress address2 = (new Key()).PubKey.Hash.GetAddress(this.network); var deposit1 = new Deposit(0, new Money(160m, MoneyUnit.BTC), address1.ToString(), crossChainTransferStore.NextMatureDepositHeight, 1); var deposit2 = new Deposit(1, new Money(60m, MoneyUnit.BTC), address2.ToString(), crossChainTransferStore.NextMatureDepositHeight, 1); MaturedBlockDepositsModel[] blockDeposits = new[] { new MaturedBlockDepositsModel( new MaturedBlockInfoModel() { BlockHash = 1, BlockHeight = crossChainTransferStore.NextMatureDepositHeight }, new[] { deposit1, deposit2 }) }; crossChainTransferStore.RecordLatestMatureDepositsAsync(blockDeposits).GetAwaiter().GetResult(); Dictionary <uint256, Transaction> transactions = crossChainTransferStore.GetTransactionsByStatusAsync( CrossChainTransferStatus.Partial).GetAwaiter().GetResult(); var requester = new PartialTransactionRequester(this.loggerFactory, crossChainTransferStore, this.asyncLoopFactory, this.nodeLifetime, this.connectionManager, this.federationGatewaySettings); var peerEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("1.2.3.4"), 5); var peer = Substitute.For <INetworkPeer>(); peer.RemoteSocketAddress.Returns(peerEndPoint.Address); peer.RemoteSocketPort.Returns(peerEndPoint.Port); peer.PeerEndPoint.Returns(peerEndPoint); peer.IsConnected.Returns(true); var peers = new NetworkPeerCollection(); peers.Add(peer); this.federationGatewaySettings.FederationNodeIpEndPoints.Returns(new[] { peerEndPoint }); this.connectionManager.ConnectedPeers.Returns(peers); requester.Start(); Thread.Sleep(100); peer.Received().SendMessageAsync(Arg.Is <RequestPartialTransactionPayload>(o => o.DepositId == 0 && o.PartialTransaction.GetHash() == transactions[0].GetHash())).GetAwaiter().GetResult(); peer.DidNotReceive().SendMessageAsync(Arg.Is <RequestPartialTransactionPayload>(o => o.DepositId == 1 && o.PartialTransaction.GetHash() == transactions[1].GetHash())).GetAwaiter().GetResult(); } }