ServerRoot.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using LiteDB;
  2. using NTMiner.Core;
  3. using NTMiner.Core.Impl;
  4. using NTMiner.IpSet;
  5. using NTMiner.IpSet.Impl;
  6. using System.IO;
  7. namespace NTMiner {
  8. public static class ServerRoot {
  9. public static readonly IRemoteIpSet _remoteEndPointSet = new RemoteIpSet();
  10. public static IRemoteIpSet RemoteEndPointSet {
  11. get {
  12. return _remoteEndPointSet;
  13. }
  14. }
  15. static ServerRoot() {
  16. System.Net.ServicePointManager.DefaultConnectionLimit = 512;
  17. }
  18. private static IHostConfig _hostConfig;
  19. private static readonly object _locker = new object();
  20. public static IHostConfig HostConfig {
  21. get {
  22. if (_hostConfig == null) {
  23. lock (_locker) {
  24. if (_hostConfig == null) {
  25. using (LiteDatabase db = new LiteDatabase($"filename={Path.Combine(HomePath.AppDomainBaseDirectory, NTKeyword.LocalDbFileName)}")) {
  26. var col = db.GetCollection<HostConfigData>();
  27. _hostConfig = col.FindOne(Query.All());
  28. }
  29. if (_hostConfig == null) {
  30. throw new NTMinerException("未配置HostConfigData");
  31. }
  32. }
  33. }
  34. }
  35. return _hostConfig;
  36. }
  37. }
  38. }
  39. }