private static string GetSign(IGetSignData data, string loginName, string password, ulong timestamp) { var sb = data.GetSignData(); sb.Append("LoginName").Append(loginName).Append("Password").Append(password).Append("Timestamp").Append(timestamp); return(HashUtil.Sha1(sb.ToString())); }
static void Main() { NTMinerConsole.SetIsMainUiOk(true); NTMinerConsole.DisbleQuickEditMode(); DevMode.SetDevMode(); Windows.ConsoleHandler.Register(Exit); string thisServerAddress = ServerRoot.HostConfig.ThisServerAddress; Console.Title = $"{ServerAppType.WsServer.GetName()}_{thisServerAddress}"; // 通过WsServer的网络缓解对WebApiServer的外网流量的压力。WsServer调用WebApiServer的时候走内网调用节省外网带宽 RpcRoot.SetOfficialServerAddress(ServerRoot.HostConfig.RpcServerLocalAddress); // 用本节点的地址作为队列名,消费消息时根据路由键区分消息类型 string queue = $"{ServerAppType.WsServer.GetName()}.{thisServerAddress}"; string durableQueue = queue + MqKeyword.DurableQueueEndsWith; AbstractMqMessagePath[] mqMessagePaths = new AbstractMqMessagePath[] { new ReadOnlyUserMqMessagePath(durableQueue), new MinerSignMqMessagePath(durableQueue), new WsServerNodeMqMessagePath(queue), new OperationMqMessagePath(queue), new MinerClientMqMessagePath(queue, thisServerAddress) }; if (!MqRedis.Create(ServerAppType.WsServer, mqMessagePaths, out IMqRedis mqRedis)) { NTMinerConsole.UserError("启动失败,无法继续,因为服务器上下文创建失败"); return; } MinerClientMqSender = new MinerClientMqSender(mqRedis); SpeedDataRedis = new SpeedDataRedis(mqRedis); WsServerNodeRedis = new WsServerNodeRedis(mqRedis); OperationMqSender = new OperationMqSender(mqRedis); UserMqSender = new UserMqSender(mqRedis); _wsServerNodeMqSender = new WsServerNodeMqSender(mqRedis); WsServerNodeAddressSet = new WsServerNodeAddressSet(WsServerNodeRedis, _wsServerNodeMqSender); var minerRedis = new ReadOnlyMinerRedis(mqRedis); var userRedis = new ReadOnlyUserRedis(mqRedis); VirtualRoot.StartTimer(); RpcRoot.SetRpcUser(new RpcUser(ServerRoot.HostConfig.RpcLoginName, HashUtil.Sha1(ServerRoot.HostConfig.RpcPassword))); RpcRoot.SetIsOuterNet(false); // 构造函数中异步访问redis初始化用户列表,因为是异步的所以提前构造 UserSet = new ReadOnlyUserSet(userRedis); MinerSignSet = new MinerSignSet(minerRedis); _wsServer = new SharpWsServerAdapter(ServerRoot.HostConfig); MinerClientSessionSet = new MinerClientSessionSet(_wsServer.MinerClientWsSessions); MinerStudioSessionSet = new MinerStudioSessionSet(_wsServer.MinerStudioWsSessions); _started = _wsServer.Start(); if (!_started) { NTMinerConsole.UserError("启动失败,无法继续,因为_wsServer启动失败"); return; } VirtualRoot.RaiseEvent(new WebSocketServerStatedEvent()); Console.ReadKey(true); Exit(); }
public static void ExportWorkJson(MineWorkData mineWorkData, out string localJson, out string serverJson) { localJson = string.Empty; serverJson = string.Empty; try { LocalJsonDb localJsonObj = new LocalJsonDb(Instance, mineWorkData); ServerJsonDb serverJsonObj = new ServerJsonDb(Instance, localJsonObj); localJson = VirtualRoot.JsonSerializer.Serialize(localJsonObj); serverJson = VirtualRoot.JsonSerializer.Serialize(serverJsonObj); mineWorkData.ServerJsonSha1 = HashUtil.Sha1(serverJson); } catch (Exception e) { Logger.ErrorDebugLine(e); } }
public static string CalcSign(string loginName, string passwordSha1, long timestamp, ISignableData data = null) { StringBuilder sb; if (data == null) { sb = new StringBuilder(); } else { sb = data.GetSignData(); } sb.Append("LoginName").Append(loginName).Append("Password").Append(passwordSha1).Append("Timestamp").Append(timestamp); return(HashUtil.Sha1(sb.ToString())); }
public void Test1() { SpeedDto speedDto1 = VirtualRoot.JsonSerializer.Deserialize <SpeedDto>(File.ReadAllText(Path.Combine(TestUtil.DataDirFullName, "speedData.json"))); WsMessage message = new WsMessage(Guid.NewGuid(), WsMessage.Speed) { Data = speedDto1 }; byte[] data = Encoding.UTF8.GetBytes(VirtualRoot.JsonSerializer.Serialize(message)); double dataSize = data.Length / NTKeyword.DoubleK; Console.WriteLine($"原始大小 {dataSize.ToString()} kb"); data = message.SignToBytes(HashUtil.Sha1("password1")); double dataNewSize = data.Length / NTKeyword.DoubleK; Assert.IsTrue(VirtualRoot.BinarySerializer.IsGZipped(data)); Console.WriteLine($"序列化后大小 {dataNewSize.ToString()} kb,是原来大小的 {(dataNewSize * 100 / dataSize).ToString()} %"); message = VirtualRoot.BinarySerializer.Deserialize <WsMessage>(data); Assert.IsTrue(message.TryGetData(out SpeedDto speedDto2)); Assert.AreEqual(speedDto1.ClientId, speedDto2.ClientId); }
public static string CalcSign(this WsMessage message, string password) { return(HashUtil.Sha1(GetSignData(message).Append(password).ToString())); }
private static void UpdateAsync() { Task.Factory.StartNew(() => { try { Task <byte[]> htmlDataTask = GetHtmlAsync("https://www.f2pool.com/"); byte[] htmlData = null; try { Task.WaitAll(new Task[] { htmlDataTask }, 60 * 1000); htmlData = htmlDataTask.Result; } catch { } if (htmlData != null && htmlData.Length != 0) { NTMinerConsole.UserOk($"{DateTime.Now.ToString()} - 鱼池首页html获取成功"); string html = Encoding.UTF8.GetString(htmlData); double usdCny = PickUsdCny(html); NTMinerConsole.UserInfo($"usdCny={usdCny.ToString()}"); List <IncomeItem> incomeItems = PickIncomeItems(html); NTMinerConsole.UserInfo($"鱼池首页有{incomeItems.Count.ToString()}个币种"); FillCny(incomeItems, usdCny); NeatenSpeedUnit(incomeItems); if (incomeItems != null && incomeItems.Count != 0) { RpcRoot.Login(new RpcUser(Config.RpcLoginName, HashUtil.Sha1(Config.RpcPassword))); RpcRoot.SetIsOuterNet(false); RpcRoot.OfficialServer.CalcConfigBinaryService.GetCalcConfigsAsync(data => { NTMinerConsole.UserInfo($"NTMiner有{data.Count.ToString()}个币种"); HashSet <string> coinCodes = new HashSet <string>(StringComparer.OrdinalIgnoreCase); foreach (CalcConfigData calcConfigData in data) { IncomeItem incomeItem = incomeItems.FirstOrDefault(a => string.Equals(a.CoinCode, calcConfigData.CoinCode, StringComparison.OrdinalIgnoreCase)); if (incomeItem != null) { coinCodes.Add(calcConfigData.CoinCode); calcConfigData.Speed = incomeItem.Speed; calcConfigData.SpeedUnit = incomeItem.SpeedUnit; calcConfigData.NetSpeed = incomeItem.NetSpeed; calcConfigData.NetSpeedUnit = incomeItem.NetSpeedUnit; calcConfigData.IncomePerDay = incomeItem.IncomeCoin; calcConfigData.IncomeUsdPerDay = incomeItem.IncomeUsd; calcConfigData.IncomeCnyPerDay = incomeItem.IncomeCny; calcConfigData.ModifiedOn = DateTime.Now; if (calcConfigData.ModifiedOn.AddMinutes(15) > calcConfigData.ModifiedOn.Date.AddDays(1)) { calcConfigData.BaseNetSpeed = calcConfigData.NetSpeed; calcConfigData.BaseNetSpeedUnit = calcConfigData.NetSpeedUnit; } else if (calcConfigData.BaseNetSpeed != 0) { if (calcConfigData.NetSpeedUnit == calcConfigData.BaseNetSpeedUnit) { calcConfigData.DayWave = (calcConfigData.NetSpeed - calcConfigData.BaseNetSpeed) / calcConfigData.BaseNetSpeed; } else { if (string.IsNullOrEmpty(calcConfigData.BaseNetSpeedUnit)) { calcConfigData.BaseNetSpeedUnit = calcConfigData.NetSpeedUnit; } var netSpeed = calcConfigData.NetSpeed.FromUnitSpeed(calcConfigData.NetSpeedUnit); var baseNetSpeed = calcConfigData.BaseNetSpeed.FromUnitSpeed(calcConfigData.BaseNetSpeedUnit); calcConfigData.DayWave = (netSpeed - baseNetSpeed) / baseNetSpeed; } } } } RpcRoot.OfficialServer.CalcConfigService.SaveCalcConfigsAsync(data, callback: (res, e) => { if (!res.IsSuccess()) { VirtualRoot.Out.ShowError(res.ReadMessage(e), autoHideSeconds: 4); } }); foreach (IncomeItem incomeItem in incomeItems) { if (coinCodes.Contains(incomeItem.CoinCode)) { continue; } NTMinerConsole.UserInfo(incomeItem.ToString()); } foreach (var incomeItem in incomeItems) { if (!coinCodes.Contains(incomeItem.CoinCode)) { continue; } NTMinerConsole.UserOk(incomeItem.ToString()); } NTMinerConsole.UserOk($"更新了{coinCodes.Count.ToString()}个币种:{string.Join(",", coinCodes)}"); int unUpdatedCount = data.Count - coinCodes.Count; NTMinerConsole.UserWarn($"{unUpdatedCount.ToString()}个币种未更新{(unUpdatedCount == 0 ? string.Empty : ":" + string.Join(",", data.Select(a => a.CoinCode).Except(coinCodes)))}"); }); } } } catch (Exception e) { Logger.ErrorDebugLine(e); } }); }
public string GetSign(string password) { StringBuilder sb = GetSignData().Append(nameof(UserData.Password)).Append(password); return(HashUtil.Sha1(sb.ToString())); }
public static string GetRemotePassword(Guid clientId) { return(HashUtil.Sha1($"{HashUtil.Sha1(PasswordSha1)}{clientId}")); }
public void Sha1Test() { Assert.AreEqual(string.Empty, HashUtil.Sha1(string.Empty)); Assert.AreEqual(string.Empty, HashUtil.Sha1((string)null)); }