Ejemplo n.º 1
0
        public ProfileFeature(
            ServerNodeBase network,
            ServerSettings nodeSettings,
            ILoggerFactory loggerFactory,
            DatabaseSettings databaseSettings,
            X42ClientSettings x42ClientSettings,
            IxServerLifetime serverLifetime,
            IAsyncLoopFactory asyncLoopFactory,
            X42ClientFeature x42FullNode,
            DatabaseFeatures database,
            NetworkFeatures networkFeatures,
            XServer xServer
            )
        {
            this.network           = network;
            this.nodeSettings      = nodeSettings;
            logger                 = loggerFactory.CreateLogger(GetType().FullName);
            this.databaseSettings  = databaseSettings;
            this.serverLifetime    = serverLifetime;
            this.asyncLoopFactory  = asyncLoopFactory;
            this.x42ClientSettings = x42ClientSettings;
            this.x42FullNode       = x42FullNode;
            this.database          = database;
            this.networkFeatures   = networkFeatures;
            this.xServer           = xServer;

            x42Client = new X42Node(x42ClientSettings.Name, x42ClientSettings.Address, x42ClientSettings.Port, logger, serverLifetime, asyncLoopFactory, false);
        }
Ejemplo n.º 2
0
        public X42Node(string name, IPAddress address, uint port, ILogger mainLogger, IxServerLifetime serverLifetime, IAsyncLoopFactory asyncLoopFactory, bool eventsEnabled = true)
        {
            logger = mainLogger;
            this.serverLifetime   = serverLifetime;
            this.asyncLoopFactory = asyncLoopFactory;

            monitorSleep = 3000;

            SetupNodeConnection(name, address, port);

            if (eventsEnabled)
            {
                OnConnected(address, port, ConnectionType.DirectApi);
            }
        }
Ejemplo n.º 3
0
        public X42ClientFeature(
            ServerNodeBase network,
            ILoggerFactory loggerFactory,
            X42ClientSettings x42ClientSettings,
            IServerStats nodeStats,
            IxServerLifetime serverLifetime,
            IAsyncLoopFactory asyncLoopFactory)
        {
            this.serverLifetime    = serverLifetime;
            this.asyncLoopFactory  = asyncLoopFactory;
            this.x42ClientSettings = x42ClientSettings;
            logger = loggerFactory.CreateLogger(GetType().FullName);

            nodeStats.RegisterStats(this.AddComponentStats, StatsType.Component, 1000);
        }
Ejemplo n.º 4
0
        public BaseFeature(ServerSettings serverSettings,
                           DataFolder dataFolder,
                           IxServerLifetime serverLifetime,
                           IDateTimeProvider dateTimeProvider,
                           IAsyncLoopFactory asyncLoopFactory,
                           ILoggerFactory loggerFactory,
                           XServer network)
        {
            this.serverSettings = Guard.NotNull(serverSettings, nameof(serverSettings));
            this.dataFolder     = Guard.NotNull(dataFolder, nameof(dataFolder));
            this.serverLifetime = Guard.NotNull(serverLifetime, nameof(serverLifetime));
            this.network        = network;


            this.dateTimeProvider = dateTimeProvider;
            this.asyncLoopFactory = asyncLoopFactory;
            this.loggerFactory    = loggerFactory;
            logger = loggerFactory.CreateLogger(GetType().FullName);
        }
Ejemplo n.º 5
0
 public PriceFeature(
     ServerNodeBase network,
     ILoggerFactory loggerFactory,
     DatabaseSettings databaseSettings,
     IxServerLifetime serverLifetime,
     IAsyncLoopFactory asyncLoopFactory,
     DatabaseFeatures database,
     NetworkFeatures networkFeatures,
     XServer xServer
     )
 {
     this.network          = network;
     logger                = loggerFactory.CreateLogger(GetType().FullName);
     this.databaseSettings = databaseSettings;
     this.serverLifetime   = serverLifetime;
     this.asyncLoopFactory = asyncLoopFactory;
     this.database         = database;
     this.networkFeatures  = networkFeatures;
     this.xServer          = xServer;
 }
Ejemplo n.º 6
0
        public NetworkMonitor(
            ILogger mainLogger,
            IxServerLifetime serverLifetime,
            IAsyncLoopFactory asyncLoopFactory,
            DatabaseSettings databaseSettings,
            NetworkFeatures networkFeatures,
            ServerNodeBase network,
            NetworkSettings networkSettings
            )
        {
            logger = mainLogger;
            this.serverLifetime   = serverLifetime;
            this.asyncLoopFactory = asyncLoopFactory;
            this.databaseSettings = databaseSettings;
            this.networkFeatures  = networkFeatures;
            this.network          = network;
            this.networkSettings  = networkSettings;

            NetworkStartupStatus = StartupStatus.NotStarted;
        }
Ejemplo n.º 7
0
        //(string name, IPAddress address, ushort port)

        /// <summary>
        ///     Connects To A Remote Node VIA SSH!
        /// </summary>
        /// <param name="name">Node Name</param>
        /// <param name="username">SSH Login</param>
        /// <param name="password">SSH Password</param>
        /// <param name="sshServerAddress">IP Address of SSH Server</param>
        /// <param name="sshPort">SSH Server Port (Default: 22)</param>
        /// <param name="nodeIPAddress">IP Address x42 Node Is Bound To (Default: 127.0.0.1)</param>
        /// <param name="nodePort">Port x42 Node Is Bound To (Default: 42220 - MainNet)</param>
        /// <param name="localBoundAddress">IP Address To Bind Locally (Default: 127.0.0.1)</param>
        /// <param name="localBoundPort">Local Port To Bind To (Default: 42220 - MainNet)</param>
        public X42Node(string name, string username, string password, string sshServerAddress, IxServerLifetime serverLifetime, ushort sshPort = 22,
                       string nodeIPAddress = "127.0.0.1", uint nodePort = 42220, string localBoundAddress = "127.0.0.1",
                       uint localBoundPort  = 42220)
        {
            this.serverLifetime = serverLifetime;
            try
            {
                Guard.Null(name, nameof(name), "Node Name Cannot Be Null");
                Guard.Null(username, nameof(username), "SSH Username Cannot Be Null");
                Guard.Null(password, nameof(password), "SSH Password Cannot Be Null");

                Guard.AssertTrue(IPAddress.TryParse(sshServerAddress, out IPAddress sshAddress),
                                 $"Invalid SSH IP Address Provided '{sshServerAddress}'");
                Guard.AssertTrue(IPAddress.TryParse(nodeIPAddress, out IPAddress nodeAddress),
                                 $"Invalid x42 Node IP Address Provided '{sshServerAddress}'");
                Guard.AssertTrue(IPAddress.TryParse(localBoundAddress, out IPAddress localBoundIP),
                                 $"Invalid Local Bound IP Address Provided '{sshServerAddress}'");

                Guard.AssertTrue(sshPort.IsValidPortRange(),
                                 $"Invalid Port Specified For The SSH Server, Value Provided Is '{sshPort}'");
                Guard.AssertTrue(nodePort.IsValidPortRange(),
                                 $"Invalid Port Specified For The x42 Node, Value Provided Is '{nodePort}'");
                Guard.AssertTrue(localBoundPort.IsValidPortRange(),
                                 $"Invalid Port Specified For Binding Locally, Value Provided Is '{localBoundPort}'");

                _SSHClient = new SshClient(sshServerAddress, username, password);
                _SSHClient.KeepAliveInterval      = new TimeSpan(0, 0, 5);
                _SSHClient.ConnectionInfo.Timeout = new TimeSpan(0, 0, 20);
                _SSHClient.Connect();


                if (!_SSHClient.IsConnected)
                {
                    throw new Exception(
                              $"An Error Occured When Connecting To SSH Server '{username}'@'{sshServerAddress}':'{sshPort}'");
                }

                _SSHForwardPort = new ForwardedPortLocal(localBoundPort, nodeIPAddress, nodePort);
                _SSHClient.AddForwardedPort(_SSHForwardPort);

                _SSHForwardPort.Start();

                SetupNodeConnection(name, localBoundIP, (ushort)localBoundPort);

                OnConnected(sshAddress, sshPort, ConnectionType.Ssh);
            }
            catch (Exception ex)
            {
                logger.LogInformation(
                    $"Node '{Name}' ({Address}:{Port}) An Error Occured When Connecting To The Remote Node Via SSH '{username}'@'{sshServerAddress}':'{sshPort}'",
                    ex);
                throw;
            } //end of try-catch
        }     //end of public X42Node(string name, string sshServerAddress, int port = 22, string nodeIPAddress = "127.0.0.1", int nodePort = 422220)