コード例 #1
0
        /// <summary>
        /// RealTimeTelemetryManager constructor for RealTimeTelemetryManager instance creation
        /// </summary>
        /// <param name="nodeId">Node Id </param>
        /// <param name="jsonRpcUrl">JSON Rpc of Parity </param>
        /// <param name="webSocketUrl">Web Socket URL of Parity </param>
        /// <param name="ingressEndPoint">Ingress REal time restful End Point </param>
        /// <param name="ingressFingerPrint">Ingress Finger Print </param>
        /// <param name="signer">Payload Signer instance reference </param>
        /// <param name="ftpMgr">FTPManager instance reference </param>
        /// <param name="verbose">if detailed logs are required set verbose to true </param>
        /// <returns>returns instance of RealTimeTelemetryManager</returns>
        /// <exception cref="System.ArgumentException">Thrown when any of provided argument is null or empty.</exception>
        public RealTimeTelemetryManager(string nodeId, string jsonRpcUrl, string webSocketUrl, string ingressEndPoint, string ingressFingerPrint, PayloadSigner signer, FtpManager ftpMgr, bool verbose = true)
        {
            if (string.IsNullOrWhiteSpace(nodeId))
            {
                throw new ArgumentException("Node ID is empty", nameof(nodeId));
            }

            if (string.IsNullOrWhiteSpace(jsonRpcUrl))
            {
                throw new ArgumentException("RPC URL is empty", nameof(jsonRpcUrl));
            }

            if (string.IsNullOrWhiteSpace(webSocketUrl))
            {
                throw new ArgumentException("Web Socket URL is empty", nameof(webSocketUrl));
            }

            if (string.IsNullOrWhiteSpace(ingressEndPoint))
            {
                throw new ArgumentException("Ingress END Point is empty", nameof(ingressEndPoint));
            }

            if (string.IsNullOrWhiteSpace(ingressFingerPrint))
            {
                throw new ArgumentException("Ingress Finger Point is empty", nameof(ingressFingerPrint));
            }

            _ftpMgr = ftpMgr ?? throw new ArgumentException("FTP Manager is null", nameof(ftpMgr));
            _signer = signer ?? throw new ArgumentException("Signer is null", nameof(signer));

            _webSocketUri = webSocketUrl;
            _jsonRpcUrl   = jsonRpcUrl;
            _nodeId       = nodeId;
            _verbose      = verbose;


            _tti = new TalkToIngress(ingressEndPoint, ingressFingerPrint);
        }
コード例 #2
0
        /// <summary>
        /// Program entry point
        /// </summary>
        /// <param name="args">Command Line arguments</param>
        private static void Main(string[] args)
        {
            Console.WriteLine("Telemetry signer starting...");
            _lastFlush      = DateTime.UtcNow;
            _flushHighspeed = false;

            _configuration = new SignerConfiguration
            {
                NodeId                 = GetConfig("TELEMETRY_NODE_ID", "4816d758dd37833a3a5551001dac8a5fa737a342"),
                IngressHost            = GetConfig("TELEMETRY_INGRESS_HOST", "https://localhost:5010"),
                TelegrafSocket         = GetConfig("INFLUX_SOCKET", "/var/run/influxdb.sock"),
                ParityEndpoint         = GetConfig("RPC_ENDPOINT", "http://localhost:8545"),
                PersistanceDirectory   = GetConfig("TELEMETRY_INTERNAL_DIR", "./"),
                IngressFingerprint     = GetConfig("TELEMETRY_INGRESS_FINGERPRINT", string.Empty),
                ParityWebSocketAddress = GetConfig("PARITY_WEB_SOCKET", string.Empty),

                FtpHost        = GetConfig("SFTP_HOST", string.Empty),
                FtpPort        = int.Parse(GetConfig("SFTP_PORT", "22")),
                FtpUser        = GetConfig("SFTP_USER", string.Empty),
                FtpPass        = GetConfig("SFTP_PASS", string.Empty),
                FtpFingerPrint = GetConfig("SFTP_FINGER_PRINT", string.Empty),
                FtpDir         = GetConfig("FTP_DIR", "/")
            };

            Console.WriteLine("Configuration:");
            Console.WriteLine($"\tReading from: {_configuration.TelegrafSocket}");
            Console.WriteLine($"\tSending telemetry to: {_configuration.IngressHost}");
            Console.WriteLine($"\tIngress fingerprint: {_configuration.IngressFingerprint}");
            Console.WriteLine($"\tUsing NodeId: {_configuration.NodeId}");

            if (args.Length > 0 && args[0] == "--genkeys")
            {
                Console.WriteLine("Telemetry signer generating keys...");
                PayloadSigner sig    = new PayloadSigner(_configuration.NodeId, new FileKeyStore(_configuration.PersistanceDirectory));
                string        pubkey = sig.GenerateKeys();
                Console.WriteLine("This nodes Public Key:");
                Console.WriteLine(pubkey);
                return;
            }

            // Prepare thread-safe queue
            _globalQueue = new ConcurrentQueue <string>();

            // load keys
            _signer = new PayloadSigner(_configuration.NodeId, new FileKeyStore(_configuration.PersistanceDirectory));
            _signer.Init();

            //init FTP Manager
            _ftpMgr = new FtpManager(_configuration.FtpUser, _configuration.FtpPass, _configuration.FtpHost, _configuration.FtpPort,
                                     _configuration.FtpFingerPrint, _configuration.FtpDir);

            Task.Run(() =>
            {
                // Prepare flush timer
                _flushTimer = new Timer(FlushToIngress);
                _flushTimer.Change(5000, 10000);

                TelegrafSocketReader reader = new TelegrafSocketReader(_configuration.TelegrafSocket);
                reader.Read(_globalQueue);
            });

            //Real time telemetry subscription and sending to ingress
            RealTimeTelemetryManager ps = new RealTimeTelemetryManager(
                _configuration.NodeId,
                _configuration.ParityEndpoint,
                _configuration.ParityWebSocketAddress,
                (_configuration.IngressHost + "/api/ingress/realtime"),
                _configuration.IngressFingerprint, _signer, _ftpMgr);

            ps.SubscribeAndPost(true);
        }