private static string GetInternalIpAddress(InternalNode currentNode, IPAddress detectedIpAddress)
 {
   return string.IsNullOrEmpty(currentNode.InternalIpAddress)
              ? detectedIpAddress.ToString()
              : currentNode.InternalIpAddress;
 }
    private string BuildNodeArguments(
        InternalNode currentNode,
        EventStoreServiceConfiguration configuration,
        int nodeCount,
        IPAddress detectedIpAddress)
    {
      // Based on https://github.com/eventstore/eventstore/wiki/Setting-Up-OSS-Cluster
      var builder = new StringBuilder();

      var internalIpAddress = GetInternalIpAddress(currentNode, detectedIpAddress);

      var externalIpAddress = GetExternalIpAddress(currentNode, detectedIpAddress);

      builder.AppendFormat("--db={0} ", currentNode.DbPath);
      builder.AppendFormat("--log={0} ", currentNode.LogPath);
      builder.AppendFormat("--int-ip={0} ", internalIpAddress);
      builder.AppendFormat("--ext-ip={0} ", externalIpAddress);

      if (!string.IsNullOrWhiteSpace(currentNode.IntHttpPrefixes))
      {
        builder.AppendFormat("--int-http-prefixes={0} ", currentNode.IntHttpPrefixes);
      }

      if (!string.IsNullOrWhiteSpace(currentNode.ExtHttpPrefixes))
      {
        builder.AppendFormat("--ext-http-prefixes={0} ", currentNode.ExtHttpPrefixes);
      }

      builder.AppendFormat("--int-tcp-port={0} ", currentNode.IntTcpPort);
      builder.AppendFormat("--ext-tcp-port={0} ", currentNode.ExtTcpPort);
      builder.AppendFormat("--int-http-port={0} ", currentNode.IntHttpPort);
      builder.AppendFormat("--ext-http-port={0} ", currentNode.ExtHttpPort);

      builder.AppendFormat(" {0} {1} ", configuration.AdditionalFlags, currentNode.AdditionalFlags);

      builder.AppendFormat("--cluster-size={0} ", nodeCount);

      builder.AppendFormat("--discover-via-dns=false ");

      var intGossipNodes = configuration.InternalNodes.Cast<InternalNode>().Where(n => !ReferenceEquals(n, currentNode)).Select(n => String.Format("{0}:{1}", GetInternalIpAddress(n, detectedIpAddress), n.IntHttpPort));
      var extGossipNodes = configuration.ExternalNodes.Cast<ExternalNode>().Select(n => String.Format("--gossip-seed={0}:{1}", n.IpAddress, n.GossipPort));
      var gossipNodes = intGossipNodes.Union(extGossipNodes).ToArray();

      if (gossipNodes.Any())
      {
        builder.AppendFormat("--gossip-seed={0}", String.Join(",", gossipNodes));
      }

      return builder.ToString();
    }