Exemple #1
0
        public async Task <bool> Connect(
            //[ModelBinder(BinderType = typeof(PeerConnectionStringModelBinders))]
            [FromBody] string connectionString)
        {
            if (PeerConnectionString.TryCreate(connectionString, out var conn))
            {
                var isNewPeer =
                    await _connectionHandler.NewOutbound(conn.EndPoint, conn.NodeId);

                return(isNewPeer);
            }

            throw new HttpRequestException($"Invalid connection string {connectionString}");
        }
        private async Task HandleOutboundConnectQueue()
        {
            var t             = _channelProvider.GetOutboundConnectionRequestQueue(_network.CryptoCode);
            var chanMan       = _peerManagerProvider.GetPeerManager(_network).ChannelManager;
            var knownChannels = chanMan.ListChannels(_pool);

            while (await t.Reader.WaitToReadAsync())
            {
                var req = await t.Reader.ReadAsync();

                try
                {
                    await _p2PConnectionHandler.NewOutbound(req.EndPoint, req.NodeId).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex.ToString());
                    _logger.LogError($"Failed to resume the connection for {req}. Force-closing the channel.");
                    var channelDetail = knownChannels.First(c => c.RemoteNetworkId.Equals(req.NodeId));
                    chanMan.ForceCloseChannel(channelDetail.ChannelId);
                }
            }
        }