public void FilemaskSettedToDoNotFetchAnyFiles()
        {
            //Arrange
            var channelSettings = new FromSettings()
            {
                Path                = _fromFolder.FullName,
                FileMask            = "*.txt",
                ExclusionFileMasks  = new string[] { "*.XML", "*.zip" },
                Type                = ConfigChannelType.Local,
                IgnoreCaseSensitive = true
            };
            LocalChannel channel = new LocalChannel(_workingDirectory, channelSettings);

            //Act
            var result = channel.Copy();

            //Assert
            var sourceFiles = new DirectoryInfo(channelSettings.Path).GetFiles();

            Assert.AreEqual(0, result.Count());

            Assert.AreEqual(4, sourceFiles.Count());
            Assert.IsTrue(sourceFiles.Any(d => d.Name == "EE_FEETRA_TPY_000451-0_18.xml"));
            Assert.IsTrue(sourceFiles.Any(d => d.Name == "EE_FEETRA_TPY_000452-0_18.xml"));
            Assert.IsTrue(sourceFiles.Any(d => d.Name == "EE_FEETRA_TPY_000454-0_18.XML"));
            Assert.IsTrue(sourceFiles.Any(d => d.Name == "GG_TR_529900G3SW56SHYNPR95_01_20180316_0014_01.zip"));
        }
        public void CopyInboundAllFilesWithoutLocalBackup()
        {
            //Arrange
            var channelSettings = new FromSettings()
            {
                Path = _fromFolder.FullName,
                Type = ConfigChannelType.Local
            };
            LocalChannel channel = new LocalChannel(_workingDirectory, channelSettings);
            //var files = new DirectoryInfo(channelSettings.Path).GetFiles();

            //Act
            var result = channel.Copy();

            //Assert
            Assert.AreEqual(result.Count(), _testData.GetFiles().Length);
            Assert.IsTrue(result.Any(d => d.Name == "EE_FEETRA_TPY_000451-0_18.xml"));
            Assert.IsTrue(result.Any(d => d.Name == "EE_FEETRA_TPY_000452-0_18.xml"));
            Assert.IsTrue(result.Any(d => d.Name == "EE_FEETRA_TPY_000454-0_18.XML"));
            Assert.IsTrue(result.Any(d => d.Name == "GG_TR_529900G3SW56SHYNPR95_01_20180316_0014_01.zip"));

            var _fromDataFiles = _fromFolder.GetFiles();

            Assert.AreEqual(_testData.GetFiles().Length * 2, _fromFolder.GetFiles().Length);
            Assert.IsTrue(_fromDataFiles.Any(d => d.Name == $"EE_FEETRA_TPY_000451-0_18.xml{Constants.FileExtensions.FileOps}"));
            Assert.IsTrue(_fromDataFiles.Any(d => d.Name == $"EE_FEETRA_TPY_000452-0_18.xml{Constants.FileExtensions.FileOps}"));
            Assert.IsTrue(_fromDataFiles.Any(d => d.Name == $"EE_FEETRA_TPY_000454-0_18.XML{Constants.FileExtensions.FileOps}"));
            Assert.IsTrue(_fromDataFiles.Any(d => d.Name == $"GG_TR_529900G3SW56SHYNPR95_01_20180316_0014_01.zip{Constants.FileExtensions.FileOps}"));
            Assert.IsTrue(_fromDataFiles.Any(d => d.Name == "EE_FEETRA_TPY_000451-0_18.xml"));
            Assert.IsTrue(_fromDataFiles.Any(d => d.Name == "EE_FEETRA_TPY_000452-0_18.xml"));
            Assert.IsTrue(_fromDataFiles.Any(d => d.Name == "EE_FEETRA_TPY_000454-0_18.XML"));
            Assert.IsTrue(_fromDataFiles.Any(d => d.Name == "GG_TR_529900G3SW56SHYNPR95_01_20180316_0014_01.zip"));
        }
Exemplo n.º 3
0
 public void UpdateChannel(LocalChannel channel)
 {
     lock (_syncLock)
     {
         _dbContext.SaveChanges();
     }
 }
Exemplo n.º 4
0
        public async Task TestRegistrationAfterShutdown2()
        {
            await _loopA.ShutdownGracefullyAsync(TimeSpan.Zero, TimeSpan.Zero);

            var      latch = new CountdownEvent(1);
            IChannel ch    = new LocalChannel();

            try
            {
                var f = _loopA.RegisterAsync(ch);
                f.ContinueWith(t =>
                {
                    if (t.IsSuccess())
                    {
                        latch.Signal();
                    }
                }).Ignore();
                await f;
                Assert.False(true);
            }
            catch (Exception exc)
            {
                Assert.IsType <RejectedExecutionException>(exc);
            }
            // Ensure the listener was notified.
            Assert.False(latch.Wait(TimeSpan.FromSeconds(1)));
            Assert.False(ch.IsOpen);
        }
Exemplo n.º 5
0
        private Transaction BuildSignedCloseTransaction(LocalChannel channel, TransactionSignature remoteClosingSignature, ulong feeSatoshi)
        {
            var builder = new CloseChannelTransactionBuilder(channel, _networkParameters);

            builder.FeeSatoshi = feeSatoshi;
            return(builder.BuildWithSignatures(remoteClosingSignature));
        }
        public void CopyOutboundAllFilesWithoutLocalBackup()
        {
            //Arrange
            var channelSettings = new ToSettings()
            {
                Path = _toFolder.FullName,
                Type = ConfigChannelType.Local
            };

            _testData.CopyContentTo(_workingDirectory);
            LocalChannel channel = new LocalChannel(_workingDirectory, channelSettings);

            //Act
            var result = channel.Copy();

            //Assert
            Assert.AreEqual(result.Count(), _testData.GetFiles().Length);
            Assert.IsTrue(result.Any(d => d.Name == "EE_FEETRA_TPY_000451-0_18.xml"));
            Assert.IsTrue(result.Any(d => d.Name == "EE_FEETRA_TPY_000452-0_18.xml"));
            Assert.IsTrue(result.Any(d => d.Name == "EE_FEETRA_TPY_000454-0_18.XML"));
            Assert.IsTrue(result.Any(d => d.Name == "GG_TR_529900G3SW56SHYNPR95_01_20180316_0014_01.zip"));

            var _toDataFiles = _toFolder.GetFiles();

            Assert.AreEqual(_testData.GetFiles().Length, _toFolder.GetFiles().Length);
            Assert.IsTrue(_toDataFiles.Any(d => d.Name == "EE_FEETRA_TPY_000451-0_18.xml"));
            Assert.IsTrue(_toDataFiles.Any(d => d.Name == "EE_FEETRA_TPY_000452-0_18.xml"));
            Assert.IsTrue(_toDataFiles.Any(d => d.Name == "EE_FEETRA_TPY_000454-0_18.XML"));
            Assert.IsTrue(_toDataFiles.Any(d => d.Name == "GG_TR_529900G3SW56SHYNPR95_01_20180316_0014_01.zip"));
        }
        public void CopyWithExclusionFilemaskAndFilemask()
        {
            //Arrange
            var channelSettings = new FromSettings()
            {
                Path               = _fromFolder.FullName,
                FileMask           = "*.zip",
                ExclusionFileMasks = new string[] { "EE_*_*_*1-0_18.xml", "*.XML" },
                Type               = ConfigChannelType.Local
            };
            LocalChannel channel = new LocalChannel(_workingDirectory, channelSettings);

            //Act
            var result = channel.Copy();

            //Assert
            var sourceFiles = new DirectoryInfo(channelSettings.Path).GetFiles();

            Assert.AreEqual(1, result.Count());
            Assert.IsTrue(result.Any(d => d.Name == "GG_TR_529900G3SW56SHYNPR95_01_20180316_0014_01.zip"));

            Assert.AreEqual(5, sourceFiles.Count());
            Assert.IsTrue(sourceFiles.Any(d => d.Name == "EE_FEETRA_TPY_000451-0_18.xml"));
            Assert.IsTrue(sourceFiles.Any(d => d.Name == "EE_FEETRA_TPY_000452-0_18.xml"));
            Assert.IsTrue(sourceFiles.Any(d => d.Name == $"GG_TR_529900G3SW56SHYNPR95_01_20180316_0014_01.zip{Constants.FileExtensions.FileOps}"));
            Assert.IsTrue(sourceFiles.Any(d => d.Name == "EE_FEETRA_TPY_000454-0_18.XML"));
            Assert.IsTrue(sourceFiles.Any(d => d.Name == "GG_TR_529900G3SW56SHYNPR95_01_20180316_0014_01.zip"));
        }
Exemplo n.º 8
0
        private void SendFundingLocked(IPeer peer, LocalChannel channel)
        {
            FundingLockedMessage message = new FundingLockedMessage();

            message.ChannelId = channel.ChannelId.HexToByteArray();
            message.NextPerCommitmentPoint = _commitmentService.GetNextLocalPerCommitmentPoint(channel);
            peer.Messaging.Send(message);
        }
Exemplo n.º 9
0
        public void BroadcastFundingTransaction(LocalChannel channel)
        {
            var fundingTransaction = CreateFundingTransaction(channel.FundingSatoshis, channel.FeeRatePerKw,
                                                              channel.LocalCommitmentTxParameters.FundingKey, channel.RemoteCommitmentTxParameters.FundingKey);

            _channelLoggingService.LogInfo(channel, "Funding Transaction", fundingTransaction.ToString());
            _blockchainClientService.SendTransaction(fundingTransaction.Transaction);
        }
Exemplo n.º 10
0
        private void SendShutdownMessage(LocalChannel channel, IPeer peer)
        {
            ShutdownMessage shutdownMessage = new ShutdownMessage();

            shutdownMessage.ChannelId    = channel.ChannelId.HexToByteArray();
            shutdownMessage.ScriptPubKey = _walletService.PubKeyAddress.ScriptPubKey.ToBytes(); //channel.FinalPubKeyScript;
            peer.Messaging.Send(shutdownMessage);
        }
Exemplo n.º 11
0
        private void OnMutualCloseTransaction(LocalChannel channel, Transaction spendingTx)
        {
            var oldState = channel.State;

            channel.State = LocalChannelState.Closed;
            _channelLoggingService.LogStateUpdate(channel, oldState, "Mutual Close: Closing Transaction confirmed. ");
            _channelService.RemoveChannel(channel);
        }
Exemplo n.º 12
0
 private void OnSuccessfulEstablishment(LocalChannel channel)
 {
     if (channel.State == LocalChannelState.NormalOperation)
     {
         channel.Active = true;
         ChannelActiveStateChanged(channel);
     }
 }
Exemplo n.º 13
0
        private void RespondWithShutdown(IPeer peer, LocalChannel channel, ShutdownMessage message)
        {
            ShutdownMessage shutdownMessage = new ShutdownMessage();

            shutdownMessage.ScriptPubKey = channel.LocalChannelParameters.ShutdownScriptPubKey;
            shutdownMessage.ChannelId    = channel.ChannelId.HexToByteArray();
            peer.Messaging.Send(shutdownMessage);
        }
Exemplo n.º 14
0
        private void OnNewerCommitmentTransaction(LocalChannel channel, Transaction spendingTx)
        {
            var oldState = channel.State;

            _channelLoggingService.LogWarning(channel, "A newer commitment tx got confirmed.", spendingTx.ToString());
            _unilateralCloseService.HandleNewerCommitmentTransaction(channel, spendingTx);
            channel.State = LocalChannelState.Closed;
            _channelLoggingService.LogStateUpdate(channel, oldState);
            _channelService.RemoveChannel(channel);
        }
Exemplo n.º 15
0
        private void OnRevokedCommitmentTransaction(LocalChannel channel, Transaction spendingTx)
        {
            var oldState = channel.State;

            _channelLoggingService.LogWarning(channel, "Penalty: A revoked commitment tx got confirmed.", spendingTx.ToString());
            _penaltyService.HandlePenalty(channel, spendingTx);
            channel.State = LocalChannelState.Penalty;
            _channelLoggingService.LogStateUpdate(channel, oldState);
            _channelService.RemoveChannel(channel);
        }
Exemplo n.º 16
0
        private void SignRemoteCommitmentTx(LocalChannel channel)
        {
            var builder = new CommitmentTransactionBuilder(channel, false, _networkParameters);

            Transaction rawTransaction    = builder.Build();
            Key         fundingPrivateKey = new Key(channel.LocalCommitmentTxParameters.FundingKey.PrivateKeyData);

            channel.RemoteCommitmentTxParameters.LocalSignature = builder.SignCommitmentTransaction(fundingPrivateKey, rawTransaction);
            _channelLoggingService.LogInfo(channel, "Remote Commitment Transaction", rawTransaction.ToString());
        }
Exemplo n.º 17
0
 public void AddChannel(IPeer peer, LocalChannel channel)
 {
     lock (_syncLock)
     {
         _logger.LogInformation($"Add Channel {channel.ChannelId}");
         channel.PersistentPeer = _dbContext.Peers.SingleOrDefault(p => p.Address == peer.NodeAddress.Address) ?? new PersistentPeer(peer.NodeAddress.Address, true);
         _dbContext.Add(channel);
         _dbContext.SaveChanges();
         _channels.Add(channel);
         _channelAddedProvider.NotifyOn(_taskScheduler).OnNext(channel);
     }
 }
Exemplo n.º 18
0
        private void FormChannelConnection(Server server)
        {
            if (server.Address.Equals(context.LocalAddress))
            {
                try
                {
                    IDualChannel channel = new LocalChannel(context.LocalAddress, this);
                    lock (_shardChannels)
                    {
                        _shardChannels[server] = channel;
                    }
                }
                catch (Exception e)
                {
                    if (LoggerManager.Instance.ShardLogger != null && LoggerManager.Instance.ShardLogger.IsErrorEnabled)
                    {
                        LoggerManager.Instance.ShardLogger.Error("LocalShard.FormChannel()", "Local node: " + e.ToString());
                    }
                }
            }
            else
            {
                DualChannel channel = new DualChannel(server.Address.IpAddress.ToString(), server.Address.Port, context.LocalAddress.IpAddress.ToString(), SessionTypes.Shard, _traceProvider, _channelFormatter);
                try
                {
                    if (channel.Connect(false))
                    {
                        SessionInfo sessionInfo = new SessionInfo();
                        sessionInfo.Cluster = this.context.ClusterName;
                        sessionInfo.Shard   = this.context.LocalShardName;

                        channel.SendMessage(sessionInfo, true);

                        IDualChannel acceptedChannel = _resolveDispute.GetValidChannel(_resolveDispute.SetConnectInfo(channel, ConnectInfo.ConnectStatus.CONNECT_FIRST_TIME), _shardChannels);
                        lock (_shardChannels)
                        {
                            _shardChannels[server] = acceptedChannel;
                        }

                        _shardChannels[server].RegisterRequestHandler(this);
                        _shardChannels[server].StartReceiverThread();
                    }
                }
                catch (ChannelException ex)
                {
                    if (LoggerManager.Instance.ShardLogger != null && LoggerManager.Instance.ShardLogger.IsErrorEnabled)
                    {
                        LoggerManager.Instance.ShardLogger.Error("LocalShard.Start()", "Local shard: " + Name + ": Connection with " + server.Address + " failed to establish. " + ex);
                    }
                }
            }
        }
Exemplo n.º 19
0
        public void HandleLocalFundingLocked(IPeer peer, LocalChannel channel)
        {
            if (channel.State == LocalChannelState.NormalOperation)
            {
                return;
            }

            channel.State = channel.State == LocalChannelState.FundingLocked ? LocalChannelState.NormalOperation : LocalChannelState.FundingLocked;
            channel.LocalCommitmentTxParameters.NextPerCommitmentPoint = _commitmentService.GetNextLocalPerCommitmentPoint(channel);

            _channelService.UpdateChannel(channel);
            SendFundingLocked(peer, channel);
        }
Exemplo n.º 20
0
        public void RemoveChannel(LocalChannel channel)
        {
            if (channel.State != LocalChannelState.Closed)
            {
                throw new ChannelException("Channel needs to be closed. Use ChannelCloseService to remove a channel.", channel);
            }

            lock (_syncLock)
            {
                _channels.Remove(channel);
                _dbContext.SaveChanges();
                _channelRemovedProvider.NotifyOn(_taskScheduler).OnNext(channel);
            }
        }
        private void LogChannelMessage(LocalChannel channel, string temporaryChannelId, Message message,
                                       LocalChannelLogEntryType type)
        {
            var entry = new LocalChannelLogEntry
            {
                ChannelId          = channel != null && channel.Id != 0 ? channel.Id : (int?)null,
                Timestamp          = DateTime.Now,
                EntryType          = type,
                TemporaryChannelId = temporaryChannelId,
                State          = channel?.State,
                AdditionalData = message.ToString()
            };

            Save(entry);
        }
        private void LogMessageValidationException(LocalChannel channel, string temporaryChannelId, Message message,
                                                   LocalChannelLogEntryType type, string errorText)
        {
            var entry = new LocalChannelLogEntry
            {
                ChannelId          = channel != null && channel.Id != 0 ? channel.Id : (int?)null,
                Timestamp          = DateTime.Now,
                EntryType          = type,
                TemporaryChannelId = temporaryChannelId,
                State          = channel?.State,
                Error          = LocalChannelError.ValidationError,
                ErrorText      = errorText,
                AdditionalData = message.ToString()
            };

            Save(entry);
        }
Exemplo n.º 23
0
        private void MutualClose(LocalChannel channel, IPeer peer)
        {
            var oldState = channel.State;

            if (channel.State != LocalChannelState.ClosingSigned)
            {
                channel.State = LocalChannelState.Shutdown;
            }

            channel.CloseReason = CloseReason.LocalMutualClose;

            SendShutdownMessage(channel, peer);

            _channelService.UpdateChannel(channel);
            _channelLoggingService.LogStateUpdate(channel, oldState, "Mutual Close");
            _channelClosingProvider.OnNext(channel);
        }
Exemplo n.º 24
0
        private LocalChannel CreateChannel(uint index, FundingTransaction fundingTx, OpenChannelMessage openMessage, AcceptChannelMessage acceptMessage)
        {
            LocalChannel channel = new LocalChannel();

            channel.ChannelIndex            = index;
            channel.TemporaryChannelId      = openMessage.TemporaryChannelId.ToHex();
            channel.LocalChannelParameters  = ChannelParameters.CreateFromOpenMessage(openMessage);
            channel.RemoteChannelParameters = ChannelParameters.CreateFromAcceptMessage(acceptMessage);
            channel.FundingSatoshis         = openMessage.FundingSatoshis;
            channel.PushMSat             = openMessage.PushMSat;
            channel.MinimumDepth         = acceptMessage.MinimumDepth;
            channel.FundingTransactionId = fundingTx.Transaction.GetHash().ToString();
            channel.FundingOutputIndex   = fundingTx.FundingOutputIndex;
            channel.ChannelId            = LocalChannel.DeriveChannelId(fundingTx.Transaction, fundingTx.FundingOutputIndex);
            channel.FeeRatePerKw         = openMessage.FeeratePerKw;

            return(channel);
        }
Exemplo n.º 25
0
        public async Task TestRegistrationAfterShutdown()
        {
            await _loopA.ShutdownGracefullyAsync(TimeSpan.Zero, TimeSpan.Zero);

            IChannel ch = new LocalChannel();

            try
            {
                await _loopA.RegisterAsync(ch);

                Assert.False(true);
            }
            catch (Exception exc)
            {
                Assert.IsType <RejectedExecutionException>(exc);
            }
            Assert.False(ch.IsOpen);
        }
Exemplo n.º 26
0
            private ReadError ReadChannelDelimited(LocalChannel channel, out TMessage message)
            {
                try
                {
                    if (!channel.ReadDelimited(out message))
                    {
                        return(ReadError.Unknown);
                    }

                    return(ReadError.Success);
                }
                catch (Exception ex)
                {
                    message = default;

                    if (ex is SocketException socketEx && socketEx.SocketErrorCode == SocketError.TimedOut)
                    {
                        return(ReadError.Timeout);
                    }
Exemplo n.º 27
0
        public void Close(LocalChannel channel, bool unilateralCloseOnUnavailability)
        {
            _channelLoggingService.LogInfo(channel, $"Closing {channel.ChannelId}. State: {channel.State}. Force: {unilateralCloseOnUnavailability}");
            var peer = _peerService.Peers.SingleOrDefault(p => p.NodeAddress.Address == channel.PersistentPeer.Address);

            if (peer == null && unilateralCloseOnUnavailability)
            {
                _logger.LogWarning($"Peer ({channel.PersistentPeer.Address}) is not available. Doing an unilateral close.");
                UnilateralClose(channel);
                return;
            }

            if (peer == null)
            {
                throw new PeerException("Peer is unavailable");
            }

            MutualClose(channel, peer);
        }
        public CommitmentTransactionBuilder(LocalChannel channel, bool buildLocal, NetworkParameters networkParameters)
        {
            Network = networkParameters.Network;
            Channel = channel;

            if (buildLocal)
            {
                IsFunder                 = channel.IsFunder;
                ChannelParameters        = channel.LocalChannelParameters;
                CommitmentTxParams       = channel.LocalCommitmentTxParameters;
                RemoteCommitmentTxParams = channel.RemoteCommitmentTxParameters;
            }
            else
            {
                IsFunder                 = !channel.IsFunder;
                ChannelParameters        = channel.RemoteChannelParameters;
                CommitmentTxParams       = channel.RemoteCommitmentTxParameters;
                RemoteCommitmentTxParams = channel.LocalCommitmentTxParameters;
            }
        }
Exemplo n.º 29
0
        public void Log(LocalChannel channel, string logText, LocalChannelLogEntryType type, string additionalData = "")
        {
            var entry = new LocalChannelLogEntry
            {
                Timestamp          = DateTime.Now,
                EntryType          = type,
                ChannelId          = channel != null && channel.Id != 0 ? channel.Id : (int?)null,
                TemporaryChannelId = channel?.TemporaryChannelId,
                ChannelData        = channel?.ToString(),
                State          = channel?.State,
                LogText        = logText,
                DebugData      = GetDebugData(),
                AdditionalData = additionalData
            };

            string channelData = channel != null?channel.ToString() : "";

            _logger.LogDebug($"{type}: {logText}. AdditionalData: {additionalData}. Channel: {channelData}");
            Save(entry);
        }
        public void CopyAllInboundFilesTwice()
        {
            //Arrange
            var channelSettings = new FromSettings()
            {
                Path = _fromFolder.FullName,
                Type = ConfigChannelType.Local
            };
            LocalChannel channel = new LocalChannel(_workingDirectory, channelSettings);

            //Act
            var result1 = channel.Copy();
            var result2 = channel.Copy();

            //Assert
            foreach (var item in result1)
            {
                Assert.IsTrue(result2.Any(d => d.Name == item.Name));
            }
        }
Exemplo n.º 31
0
        public void TestAllSolutions()
        {
            var core = new Core();
            var channel = new LocalChannel();
            core.Channel = channel;

            int[] assertLogic = {0};

            channel.UntestedEvent += delegate
                                         {
                                             Assert.AreEqual(0, assertLogic[0]);
                                             assertLogic[0]++;
                                             return new[] {1, 2};
                                         };
            channel.SolutionEvent += delegate(int id)
                                         {
                                             if (assertLogic[0] == 1)
                                                 Assert.AreEqual(1, id);
                                             if (assertLogic[0] == 2)
                                                 Assert.AreEqual(2, id);
                                             assertLogic[0]++;
                                             return new Solution {Id = id, Answer = "gogog", LanguageId = 1};
                                         };
            channel.ResultEvent += delegate(Result result)
                                       {
                                           if (assertLogic[0] == 3)
                                               Assert.AreEqual(1, result.Id);
                                           if (assertLogic[0] == 4)
                                               Assert.AreEqual(2, result.Id);
                                           assertLogic[0]++;
                                           return true;
                                       };

            core.TestAllSolutions();

            Assert.AreEqual(5, assertLogic[0]);
        }
Exemplo n.º 32
0
 public IChannel CreateChannel( IChannelDefinition definition )
 {
     var channel = new LocalChannel( Dispatcher, definition as LocalChannelDefinition );
     return channel;
 }