Brunet.Applications.BasicNode.Run C# (CSharp) Method

Run() public method

This should be called by the Main after all the setup is done this passes control to the _node and won't return until the program is exiting. (It is synchronous.)
public Run ( ) : void
return void
    public virtual void Run()
    {
      int sleep = 60, sleep_min = 60, sleep_max = 3600;
      DateTime start_time = DateTime.UtcNow;

      // Keep creating new nodes no matter what!
      while(_running) {
        ApplicationNode node = CreateNode(_node_config);
        _app_node = node;

        new Information(node.Node, "BasicNode", node.SecurityOverlord);
        new LogManager(node.Node);
        Console.WriteLine("Starting at {0}, {1} is connecting to {2}.",
            DateTime.UtcNow, node.Node.Address, node.Node.Realm);

        node.Node.DisconnectOnOverload = true;
        start_time = DateTime.UtcNow;

        Thread pthread = null;
        // Must do this to remove it after successfully creating the new node
        Node.StateChangeHandler add_node = null;
        if(node.PrivateNode != null) {
          // Delayed add, removes ~15 seconds off bootstrapping time
          add_node = delegate(Node n, Node.ConnectionState cs) {
            if(cs != Node.ConnectionState.Connected) {
              return;
            }
            node.Node.StateChangeEvent -= add_node;

            new Information(node.PrivateNode.Node, "PrivateBasicNode", node.SecurityOverlord);
            pthread = new Thread(node.PrivateNode.Node.Connect);
            pthread.Start();
          };
          node.Node.StateChangeEvent += add_node;
        }

        node.Node.Connect();

        if(node.PrivateNode != null) {
          ApplicationNode pnode = node.PrivateNode;
          pnode.Node.Disconnect();
          if(pthread != null) {
            pthread.Join();
          }
        }

        // Assist in garbage collection
        if(_xrm != null) {
          _xrm.Remove(node.Node);
        }
        node = null;
        _app_node = null;

        // DisconnectOnOverload seems to be having issues with pathing...
        foreach(var kvm in _type_to_pem) {
          kvm.Value.Stop();
        }

        _type_to_pem.Clear();

        if(!_running) {
          break;
        }

        DateTime now = DateTime.UtcNow;
        Thread.Sleep(sleep * 1000);

        if(now - start_time < TimeSpan.FromSeconds(sleep_max)) {
          sleep *= 2;
          sleep = (sleep > sleep_max) ? sleep_max : sleep;
        } else {
          sleep /= 2;
          sleep = (sleep < sleep_min) ? sleep_min : sleep;
        }
      }
    }

Usage Example

Ejemplo n.º 1
0
 /**
 <summary>Runs the BasicNode.  This should be implemented in all inherited
 classes.</summary>
 <remarks>
 <para>To execute this at a command-line using Mono:</para>
 <code>
 mono BasicNode.exe path/to/node_config
 </code>
 <para>To execute this at a command-line using Windows .NET:</para>
 <code>
 BasicNode.exe path/to/node_config
 </code>
 </remarks>
 <param name="args">The command line argument required is a path to a
 NodeConfig</param>
 */
 public static int Main(String[] args) {
   BasicNode node = new BasicNode(args[0]);
   node.Run();
   return 0;
 }
All Usage Examples Of Brunet.Applications.BasicNode::Run