예제 #1
0
        /// <inheritdoc/>
        public async Task <INetworkPeer> CreateConnectedNetworkPeerAsync(
            IPEndPoint peerEndPoint,
            NetworkPeerConnectionParameters parameters = null,
            NetworkPeerDisposer networkPeerDisposer    = null)
        {
            Guard.NotNull(peerEndPoint, nameof(peerEndPoint));

            Action <INetworkPeer> onDisconnected = null;

            if (networkPeerDisposer != null)
            {
                onDisconnected = networkPeerDisposer.OnPeerDisconnectedHandler;
            }

            var peer = new NetworkPeer(peerEndPoint, this.network, parameters, this, this.dateTimeProvider, this.loggerFactory, this.selfEndpointTracker, onDisconnected, this.onSendingMessage);

            try
            {
                await peer.ConnectAsync(peer.ConnectionParameters.ConnectCancellation).ConfigureAwait(false);

                networkPeerDisposer?.AddPeer(peer);
            }
            catch
            {
                peer.Dispose();
                throw;
            }

            return(peer);
        }
예제 #2
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);
            await peer.ConnectAsync(peer.Parameters.ConnectCancellation).ConfigureAwait(false);

            return(peer);
        }
예제 #3
0
        /// <inheritdoc/>
        public async Task <INetworkPeer> CreateConnectedNetworkPeerAsync(IPEndPoint peerEndPoint, NetworkPeerConnectionParameters parameters = null)
        {
            Guard.NotNull(peerEndPoint, nameof(peerEndPoint));

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

            try
            {
                await peer.ConnectAsync(peer.ConnectionParameters.ConnectCancellation).ConfigureAwait(false);
            }
            catch (Exception e)
            {
                peer.Dispose("Connection failed", e);
                throw;
            }
            return(peer);
        }