Exemplo n.º 1
0
        /// <inheritdoc/>
        public async Task <NetworkPeer> CreateConnectedNetworkPeerAsync(Network network, NetworkAddress peerAddress, NetworkPeerConnectionParameters parameters = null)
        {
            Guard.NotNull(network, nameof(network));
            Guard.NotNull(peerAddress, nameof(peerAddress));

            var peer = new NetworkPeer(peerAddress, network, parameters, this, this.dateTimeProvider, this.loggerFactory);

            try
            {
                await peer.ConnectAsync(peer.Parameters.ConnectCancellation).ConfigureAwait(false);
            }
            catch (Exception e)
            {
                peer.Dispose("Connection failed", e);
                throw;
            }
            return(peer);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes parts of the object that are common for both inbound and outbound peers.
        /// </summary>
        /// <param name="inbound"><c>true</c> for inbound peers, <c>false</c> for outbound peers.</param>
        /// <param name="peerAddress">Information about the peer including its network address, protocol version, time of last contact.</param>
        /// <param name="network">Specification of the network the node runs on - regtest/testnet/mainnet.</param>
        /// <param name="parameters">Various settings and requirements related to how the connections with peers are going to be established, or <c>null</c> to use default parameters.</param>
        /// <param name="dateTimeProvider">Provider of time functions.</param>
        /// <param name="loggerFactory">Factory for creating loggers.</param>
        private NetworkPeer(bool inbound, NetworkAddress peerAddress, Network network, NetworkPeerConnectionParameters parameters, IDateTimeProvider dateTimeProvider, ILoggerFactory loggerFactory)
        {
            this.loggerFactory    = loggerFactory;
            this.dateTimeProvider = dateTimeProvider;

            this.preferredTransactionOptions = network.NetworkOptions;
            this.SupportedTransactionOptions = network.NetworkOptions & ~NetworkOptions.All;

            this.Inbound     = inbound;
            this.LastSeen    = peerAddress.Time.UtcDateTime;
            this.PeerAddress = peerAddress;
            this.Network     = network;
            this.Behaviors   = new NetworkPeerBehaviorsCollection(this);

            this.Parameters = parameters ?? new NetworkPeerConnectionParameters();
            this.MyVersion  = this.Parameters.CreateVersion(this.PeerAddress.Endpoint, network, this.dateTimeProvider.GetTimeOffset());
        }
Exemplo n.º 3
0
        /// <inheritdoc/>
        public async Task <NetworkPeer> CreateConnectedNetworkPeerAsync(Network network, IPEndPoint endPoint, NetworkPeerConnectionParameters parameters = null)
        {
            Guard.NotNull(network, nameof(network));
            Guard.NotNull(endPoint, nameof(endPoint));

            var peerAddress = new NetworkAddress()
            {
                Time     = this.dateTimeProvider.GetTimeOffset(),
                Endpoint = endPoint
            };

            return(await this.CreateConnectedNetworkPeerAsync(network, peerAddress, parameters));
        }