This class provides a layer on top of BasicNode to support creating multiple Brunet.Nodes in a single application.
Inheritance: BasicNode
Ejemplo n.º 1
0
    public static int Main(String[] args) {
      P2PNodeParameters parameters = new P2PNodeParameters();
      if(parameters.Parse(args) != 0) {
        Console.WriteLine(parameters.ErrorMessage);
        parameters.ShowHelp();
        return -1;
      } else if(parameters.Help) {
        parameters.ShowHelp();
        return 0;
      }

      NodeConfig node_config = parameters.NodeConfig;
      if(node_config.NodeAddress == null) {
        node_config.NodeAddress = Utils.GenerateAHAddress().ToString();
        node_config.WriteConfig();
      }

      BasicNode node = null;
      if(parameters.Count == 1) {
        node = new BasicNode(node_config);
      } else {
        node = new MultiNode(node_config, parameters.Count);
      }
      node.Run();

      return 0;
    }
Ejemplo n.º 2
0
        public static int Main(String[] args)
        {
            P2PNodeParameters parameters = new P2PNodeParameters();

            if (parameters.Parse(args) != 0)
            {
                Console.WriteLine(parameters.ErrorMessage);
                parameters.ShowHelp();
                return(-1);
            }
            else if (parameters.Help)
            {
                parameters.ShowHelp();
                return(0);
            }

            NodeConfig node_config = parameters.NodeConfig;

            if (node_config.NodeAddress == null)
            {
                node_config.NodeAddress = Utils.GenerateAHAddress().ToString();
                node_config.WriteConfig();
            }

            BasicNode node = null;

            if (parameters.Count == 1)
            {
                node = new BasicNode(node_config);
            }
            else
            {
                node = new MultiNode(node_config, parameters.Count);
            }
            node.Run();

            return(0);
        }
Ejemplo n.º 3
0
    /**
    <summary>Runs the MultiNode.</summary>
    <remarks>
    <para>To execute this at a command-line using Mono with 10 nodes:</para>
    <code>
    mono MultiNode.exe path/to/node_config 10
    </code>
    <para>To execute this at a command-line using Windows .NET with 15 nodes:
    </para>
    <code>
    MultiNode.exe path/to/node_config 15
    </code>
    </remarks>
    <param name="args">The command line arguments required are a path to a
    NodeConfig and the count of Brunet.Nodes to run.</param>
    */
    public static new int Main(String[] args) {
      int count = 0;
      try {
        count = Int32.Parse(args[1]);
      }
      catch {
        Console.WriteLine("Input paramters are %0 %1, where %0 is a config" +
            " file and %1 is the count of nodes.");
        return 0;
      }

      MultiNode node = new MultiNode(args[0], count);
      node.Run();
      return 0;
    }
Ejemplo n.º 4
0
    public static int Main(String[] args) {
      string node_config_path = string.Empty;
      string str_count = string.Empty;
      int count = 1;
      bool show_help = false;

      OptionSet opts = new OptionSet() {
        { "n|NodeConfig=", "Path to a NodeConfig file.",
          v => node_config_path = v },
        { "c|Count=", "Number of nodes to instantiate.",
          v => str_count = v },
        { "h|help", "Display this help and exit.",
          v => show_help = v != null },
      };

      try {
        opts.Parse(args);
      } catch (OptionException e) {
        Console.WriteLine("P2PNode: ");
        Console.WriteLine(e.Message);
        Console.WriteLine("Try `P2PNode --help' for more information.");
        return -1;
      }

      if(show_help) {
        ShowHelp(opts);
        return -1;
      }

      if(node_config_path == string.Empty || !File.Exists(node_config_path)) {
        Console.WriteLine("P2PNode: ");
        Console.WriteLine("\tMissing NodeConfig.");
        Console.WriteLine("Try `P2PNode --help' for more information.");
        return -1;
      }

      if(str_count != string.Empty && !Int32.TryParse(str_count, out count) && count > 0) {
        Console.WriteLine("P2PNode: ");
        Console.WriteLine("\tInvalid count.  Count must be a positive integer.");
        Console.WriteLine("Try `P2PNode --help' for more information.");
        return -1;
      }

      NodeConfig node_config = null;
      try {
        ConfigurationValidator cv = new ConfigurationValidator();
        cv.Validate(node_config_path, "Node.xsd");
        node_config = Utils.ReadConfig<NodeConfig>(node_config_path);
        node_config.Path = node_config_path;
      } catch (Exception e) {
        Console.WriteLine("Invalid NodeConfig file:");
        Console.WriteLine("\t" + e);
        return -1;
      }

      if(node_config.NodeAddress == null) {
        node_config.NodeAddress = (Utils.GenerateAHAddress()).ToString();
        node_config.WriteConfig();
      }

      if(count == 1) {
        BasicNode node = new BasicNode(node_config);
        node.Run();
      } else {
        MultiNode node = new MultiNode(node_config, count);
        node.Run();
      }
      return 0;
    }