Beispiel #1
0
 public void Start(MothraSettings settings)
 {
     MothraInterop.RegisterHandlers(_discoveredPeer, _receiveGossip, _receiveRpc);
     string[] args = BuildArgs(settings);
     MothraInterop.Start(args, args.Length);
     IsStarted = true;
 }
Beispiel #2
0
        private string[] BuildArgs(MothraSettings settings)
        {
            List <string> args = new List <string>();

            // Arg0 is the program name (not an arg)
            args.Add("--");

            if (settings.DataDirectory != null)
            {
                args.Add("--datadir");
                args.Add(settings.DataDirectory);
            }

            if (settings.ListenAddress != null)
            {
                args.Add("--listen-address");
                args.Add(settings.ListenAddress);
            }

            if (settings.MaximumPeers != null)
            {
                args.Add("--maxpeers");
                args.Add(settings.MaximumPeers.ToString());
            }

            if (settings.BootNodes.Count > 0)
            {
                args.Add("--boot-nodes");
                string value = string.Join(',', settings.BootNodes);
                args.Add(value);
            }

            if (settings.Port != null)
            {
                args.Add("--port");
                args.Add(settings.Port.ToString());
            }

            if (settings.DiscoveryPort != null)
            {
                args.Add("--discovery-port");
                args.Add(settings.DiscoveryPort.ToString());
            }

            if (settings.DiscoveryAddress != null)
            {
                args.Add("--discovery-address");
                args.Add(settings.DiscoveryAddress);
            }

            if (settings.Topics.Count > 0)
            {
                args.Add("--topics");
                string value = string.Join(',', settings.Topics);
                args.Add(value);
            }

            if (settings.PeerMultiAddresses.Count > 0)
            {
                args.Add("--libp2p-addresses");
                string value = string.Join(',', settings.PeerMultiAddresses);
                args.Add(value);
            }

            if (settings.DebugLevel != null)
            {
                if (_debugLevels.TryGetValue(settings.DebugLevel.Value, out string value))
                {
                    args.Add("--debug-level");
                    args.Add(value);
                }
            }

            if (settings.VerbosityLevel != null)
            {
                args.Add("--verbosity");
                args.Add(settings.VerbosityLevel.ToString());
            }

            return(args.ToArray());
        }