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")); }
public void UpdateChannel(LocalChannel channel) { lock (_syncLock) { _dbContext.SaveChanges(); } }
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); }
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")); }
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); }
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); }
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); }
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); }
private void OnSuccessfulEstablishment(LocalChannel channel) { if (channel.State == LocalChannelState.NormalOperation) { channel.Active = true; ChannelActiveStateChanged(channel); } }
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); }
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); }
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); }
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()); }
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); } }
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); } } } }
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); }
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); }
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); }
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); }
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); }
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); }
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; } }
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)); } }
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]); }
public IChannel CreateChannel( IChannelDefinition definition ) { var channel = new LocalChannel( Dispatcher, definition as LocalChannelDefinition ); return channel; }