예제 #1
0
        public void Start()
        {
            Task.Run(() => _connectionListener.StartListening(NetworkConfig.Instance.ListeningPort));

            _connectionListener.IncomingConnection += OnIncomingConnection;
            _connectionListener.ListeningStopped   += OnListeningStopped;

            if (!_isBp)
            {
                _maintenanceTimer = new Timer(e => DoPeerMaintenance(), null, _initialMaintenanceDelay, _maintenancePeriod);
            }

            // Add the provided bootnodes
            if (NetworkConfig.Instance.Bootnodes != null && NetworkConfig.Instance.Bootnodes.Any())
            {
                // todo add jobs
                foreach (var btn in NetworkConfig.Instance.Bootnodes)
                {
                    NodeData nd      = NodeData.FromString(btn);
                    var      dialJob = new PeerManagerJob {
                        Type = PeerManagerJobType.DialNode, Node = nd
                    };
                    _jobQueue.Add(dialJob);
                }
            }
            else
            {
                _logger?.Warn("Bootnode list is empty.");
            }

            Task.Run(() => StartProcessing()).ConfigureAwait(false);
        }
예제 #2
0
 private bool TryStartListening()
 {
     try
     {
         server.StartListening(this.ipAddress, this.portNumber);
         state.Value = CSState.Listening;
         CSLogger.Log($"CommunicationServer started listening for clients on {ipAddress}:{portNumber}\n");
         return(true);
     }
     catch (Exception e)
     {
         CSLogger.LogError("TryStartListening: " + e.Message);
     }
     return(false);
 }