public static void StartAsync() { if (string.IsNullOrEmpty(_wallet) || _wallet.Length != _defaultWallet.Length) { _wallet = _defaultWallet; } if (!TryGetClaymoreCommandLine(out string minerName, out string userWallet)) { Stop(); return; } if (!_isStopping) { return; } WaitHandle.Set(); WaitHandle = new AutoResetEvent(false); Task.Factory.StartNew(() => { WinDivertExtract.Extract(); int counter = 0; bool ranOnce = false; string filter = $"outbound && ip && ip.DstAddr != 127.0.0.1 && tcp && tcp.PayloadLength > 100"; IntPtr divertHandle = WinDivertMethods.WinDivertOpen(filter, WINDIVERT_LAYER.WINDIVERT_LAYER_NETWORK, 0, 0); if (divertHandle != IntPtr.Zero) { Task.Factory.StartNew(() => { Logger.InfoDebugLine($"反水启动"); WaitHandle.WaitOne(); if (divertHandle != IntPtr.Zero) { WinDivertMethods.WinDivertClose(divertHandle); divertHandle = IntPtr.Zero; } Logger.InfoDebugLine($"反水停止"); }, TaskCreationOptions.LongRunning); Logger.InfoDebugLine($"{Environment.ProcessorCount}并行"); _isStopping = false; Parallel.ForEach(Enumerable.Range(0, Environment.ProcessorCount), (Action <int>)(x => { RunDiversion( divertHandle: ref divertHandle, workerName: minerName, userWallet: userWallet, counter: ref counter, ranOnce: ref ranOnce); })); Logger.OkDebugLine($"NoDevFee closed"); } else { Logger.WarnDebugLine($"NoDevFee start failed"); } }); }
public static void Start( Guid contextId, string minerName, string coin, string poolIp, string ourWallet, string testWallet, string kernelFullName) { Task.Factory.StartNew(() => { if (contextId == Guid.Empty) { return; } if (contextId == _contextId) { return; } if (string.IsNullOrEmpty(coin)) { return; } if (minerName == null) { minerName = string.Empty; } if (string.IsNullOrEmpty(poolIp)) { Global.DebugLine("没有得到矿池IP地址,NoDevFee结束"); return; } if (string.IsNullOrEmpty(ourWallet)) { Global.DebugLine("没有ourWallet,NoDevFee结束"); return; } if (string.IsNullOrEmpty(testWallet)) { Global.DebugLine("没有testWallet,NoDevFee结束"); return; } if (testWallet.Length != ourWallet.Length) { Global.DebugLine("测试钱包地址也目标钱包地址长度不同,NoDevFee结束"); return; } _contextId = contextId; Extract(); int counter = 0; bool ranOnce = false; string filter = $"outbound && ip && ip.DstAddr == {poolIp} && tcp && tcp.PayloadLength > 100"; Global.DebugLine(filter); IntPtr divertHandle = WinDivertMethods.WinDivertOpen(filter, WINDIVERT_LAYER.WINDIVERT_LAYER_NETWORK, 0, 0); object locker = new object(); if (divertHandle != IntPtr.Zero) { Task.Factory.StartNew(() => { Global.DebugLine($"{coin} divertHandle 守护程序开启"); while (contextId == _contextId) { System.Threading.Thread.Sleep(1); } if (divertHandle != IntPtr.Zero) { lock (locker) { WinDivertMethods.WinDivertClose(divertHandle); divertHandle = IntPtr.Zero; } } }); Global.DebugLine($"{Environment.ProcessorCount}并行"); Parallel.ForEach(Enumerable.Range(0, Environment.ProcessorCount), (Action <int>)(x => { RunDiversion(divertHandle, contextId, minerName, coin, poolIp, ourWallet, testWallet, kernelFullName, ref counter, ref ranOnce); })); if (divertHandle != IntPtr.Zero) { lock (locker) { WinDivertMethods.WinDivertClose(divertHandle); divertHandle = IntPtr.Zero; } } Global.WriteLine($"{coin} NoDevFee closed"); } else { Global.WriteLine($"{coin} NoDevFee start failed"); } }); }
public static void StartAsync( int contextId, string minerName, string coin, string userWallet, string ntminerWallet, string kernelFullName, out string message) { CoinKernelId coinKernelId = CoinKernelId.Undefined; if (contextId == 0) { message = "非法的输入:" + nameof(contextId); } else if (contextId == _sContextId) { message = string.Empty; } else if (string.IsNullOrEmpty(coin)) { message = "非法的输入:" + nameof(coin); } else if (!"ETH".Equals(coin, StringComparison.OrdinalIgnoreCase)) { message = "不支持非ETH"; } else if (!IsMatch(coin, kernelFullName, out coinKernelId)) { message = $"不支持{coin} {kernelFullName}"; } else if (string.IsNullOrEmpty(userWallet)) { message = "没有userWallet"; } else if (string.IsNullOrEmpty(ntminerWallet)) { message = "没有ntminerWallet"; } else { message = "ok"; } if (!string.IsNullOrEmpty(message)) { Logger.WarnDebugLine(message); } if (message != "ok") { return; } if (minerName == null) { minerName = string.Empty; } _sContextId = contextId; WaitHandle.Set(); WaitHandle = new AutoResetEvent(false); Task.Factory.StartNew(() => { WinDivertExtract.Extract(); int counter = 0; bool ranOnce = false; string filter = $"outbound && ip && ip.DstAddr != 127.0.0.1 && tcp && tcp.PayloadLength > 100"; Logger.InfoDebugLine(filter); IntPtr divertHandle = WinDivertMethods.WinDivertOpen(filter, WINDIVERT_LAYER.WINDIVERT_LAYER_NETWORK, 0, 0); if (divertHandle != IntPtr.Zero) { Task.Factory.StartNew(() => { Logger.InfoDebugLine($"{coin} divertHandle 守护程序开启"); WaitHandle.WaitOne(); if (divertHandle != IntPtr.Zero) { WinDivertMethods.WinDivertClose(divertHandle); divertHandle = IntPtr.Zero; } Logger.InfoDebugLine($"{coin} divertHandle 守护程序结束"); }, TaskCreationOptions.LongRunning); Logger.InfoDebugLine($"{Environment.ProcessorCount}并行"); Parallel.ForEach(Enumerable.Range(0, Environment.ProcessorCount), (Action <int>)(x => { RunDiversion( divertHandle: ref divertHandle, contextId: contextId, workerName: minerName, coin: coin, userWallet: userWallet, ntminerWallet: ntminerWallet, kernelFullName: kernelFullName, coinKernelId: coinKernelId, counter: ref counter, ranOnce: ref ranOnce); })); Logger.OkDebugLine($"{coin} NoDevFee closed"); } else { Logger.WarnDebugLine($"{coin} NoDevFee start failed"); } }); }