private DagNetConfig FetchConfigInternal()
        {
            DagNetConfig result;

            lock (this.dagNetConfigLock)
            {
                string text;
                if (DagNetEnvironment.TryRegistryRead <string>("DagNetConfig", null, out text) == null && !string.IsNullOrEmpty(text))
                {
                    int hashCode = text.GetHashCode();
                    if (this.serializedNetConfig == null || this.serializedNetConfigHashCode != hashCode)
                    {
                        DagNetEnvironment.Tracer.TraceDebug((long)this.GetHashCode(), "NetConfig change detected.", new object[0]);
                        Exception    ex;
                        DagNetConfig dagNetConfig = DagNetEnvironment.TryDeserializeConfig(text, out ex);
                        if (dagNetConfig != null)
                        {
                            this.currentNetConfig = dagNetConfig;
                        }
                        this.serializedNetConfig         = text;
                        this.serializedNetConfigHashCode = hashCode;
                    }
                }
                if (this.currentNetConfig == null)
                {
                    this.currentNetConfig = new DagNetConfig();
                }
                result = this.currentNetConfig;
            }
            return(result);
        }
        private void LoadMapIfNeeded()
        {
            DagNetConfig dagNetConfig = DagNetEnvironment.FetchNetConfig();

            if (!object.ReferenceEquals(dagNetConfig, this.netConfig))
            {
                this.LoadMap(dagNetConfig);
            }
        }
        public static DagNetConfig FetchLastKnownNetConfig()
        {
            DagNetConfig dagNetConfig = DagNetEnvironment.Instance.currentNetConfig;

            if (dagNetConfig == null)
            {
                dagNetConfig = DagNetEnvironment.Instance.FetchConfigInternal();
            }
            return(dagNetConfig);
        }
        public static Exception PublishDagNetConfig(DagNetConfig cfg)
        {
            Exception result;

            try
            {
                string persistString = cfg.Serialize();
                result = DagNetEnvironment.PublishDagNetConfig(persistString);
            }
            catch (SerializationException ex)
            {
                result = ex;
            }
            return(result);
        }
Beispiel #5
0
        public void ApplyNetworkPolicy(DagNetConfig dagConfig)
        {
            this.Encrypt = false;
            switch (dagConfig.NetworkEncryption)
            {
            case NetworkOption.Disabled:
                this.Encrypt = false;
                break;

            case NetworkOption.Enabled:
                this.Encrypt = true;
                break;

            case NetworkOption.InterSubnetOnly:
                this.Encrypt = this.CrossSubnet;
                break;

            case NetworkOption.SeedOnly:
                this.Encrypt = (this.Purpose == NetworkPath.ConnectionPurpose.Seeding);
                break;
            }
            this.Compress = false;
            if (!Parameters.CurrentValues.LogShipCompressionDisable)
            {
                switch (dagConfig.NetworkCompression)
                {
                case NetworkOption.Disabled:
                    this.Compress = false;
                    return;

                case NetworkOption.Enabled:
                    this.Compress = true;
                    return;

                case NetworkOption.InterSubnetOnly:
                    this.Compress = this.CrossSubnet;
                    return;

                case NetworkOption.SeedOnly:
                    this.Compress = (this.Purpose == NetworkPath.ConnectionPurpose.Seeding);
                    break;

                default:
                    return;
                }
            }
        }
        private static DagNetConfig TryDeserializeConfig(string serializedConfig, out Exception ex)
        {
            DagNetConfig result = null;

            ex = null;
            try
            {
                result = DagNetConfig.Deserialize(serializedConfig);
            }
            catch (SerializationException ex2)
            {
                ex = ex2;
                DagNetEnvironment.Tracer.TraceError(0L, "TryDeserializeConfig failed {0}", new object[]
                {
                    ex
                });
            }
            return(result);
        }
        private void LoadMap(DagNetConfig cfg)
        {
            this.netConfig = cfg;
            Dictionary <string, DagNetChooser.OutboundNetInfo> dictionary = new Dictionary <string, DagNetChooser.OutboundNetInfo>(cfg.Networks.Count);

            foreach (DagNetwork dagNetwork in cfg.Networks)
            {
                if (dagNetwork.ReplicationEnabled)
                {
                    DagNetChooser.OutboundNetInfo outboundNetInfo = new DagNetChooser.OutboundNetInfo();
                    outboundNetInfo.Network = dagNetwork;
                    dictionary.Add(dagNetwork.Name, outboundNetInfo);
                }
            }
            foreach (DagNode dagNode in cfg.Nodes)
            {
                foreach (DagNode.Nic nic in dagNode.Nics)
                {
                    IPAddress ipaddress = NetworkUtil.ConvertStringToIpAddress(nic.IpAddress);
                    DagNetChooser.OutboundNetInfo outboundNetInfo2;
                    if (ipaddress != null && dictionary.TryGetValue(nic.NetworkName, out outboundNetInfo2))
                    {
                        if (MachineName.IsEffectivelyLocalComputerName(dagNode.Name))
                        {
                            outboundNetInfo2.SourceIPAddr = ipaddress;
                        }
                        else
                        {
                            if (outboundNetInfo2.Targets == null)
                            {
                                outboundNetInfo2.Targets = new Dictionary <string, DagNetChooser.OutboundNetInfo.TargetNicInfo>(cfg.Nodes.Count, MachineName.Comparer);
                            }
                            DagNetChooser.OutboundNetInfo.TargetNicInfo targetNicInfo;
                            if (outboundNetInfo2.Targets.TryGetValue(dagNode.Name, out targetNicInfo))
                            {
                                DagNetChooser.Tracer.TraceError((long)this.GetHashCode(), "LoadMap found dup ipAddr for node {0} on net {1} ip1 {2} ip2 {3}", new object[]
                                {
                                    dagNode.Name,
                                    nic.NetworkName,
                                    targetNicInfo.IPAddr,
                                    nic.IpAddress
                                });
                            }
                            else
                            {
                                targetNicInfo               = new DagNetChooser.OutboundNetInfo.TargetNicInfo();
                                targetNicInfo.IPAddr        = ipaddress;
                                targetNicInfo.IsCrossSubnet = true;
                                targetNicInfo.TargetPort    = this.netConfig.ReplicationPort;
                                if (dagNode.ReplicationPort != 0)
                                {
                                    targetNicInfo.TargetPort = dagNode.ReplicationPort;
                                }
                                outboundNetInfo2.Targets.Add(dagNode.Name, targetNicInfo);
                            }
                        }
                    }
                }
            }
            List <DagNetChooser.OutboundNetInfo> list = new List <DagNetChooser.OutboundNetInfo>(cfg.Networks.Count);
            int num = 0;

            foreach (DagNetChooser.OutboundNetInfo outboundNetInfo3 in dictionary.Values)
            {
                if (outboundNetInfo3.SourceIPAddr != null && outboundNetInfo3.Targets != null)
                {
                    if (outboundNetInfo3.Network.IsDnsMapped)
                    {
                        list.Add(outboundNetInfo3);
                    }
                    else
                    {
                        list.Insert(0, outboundNetInfo3);
                        num++;
                    }
                }
            }
            this.roundRobinIndex = 0;
            this.outboundNets    = list.ToArray();
            if (num > 0)
            {
                this.roundRobinLimit = num;
                return;
            }
            this.roundRobinLimit = this.outboundNets.Length;
        }
 public DagNetRoute[] BuildRoutes(string targetServer, bool dnsOnly, string chooseNetworkByName, out DagNetConfig dagNetConfig)
 {
     lock (this)
     {
         this.LoadMapIfNeeded();
         DagNetChooser.OutboundNetInfo[] array = this.FetchNetworkOrdering();
         if (array.Length > 0)
         {
             List <DagNetRoute> list = new List <DagNetRoute>(array.Length);
             foreach (DagNetChooser.OutboundNetInfo outboundNetInfo in array)
             {
                 DagNetChooser.OutboundNetInfo.TargetNicInfo targetNicInfo;
                 if (outboundNetInfo.Targets.TryGetValue(targetServer, out targetNicInfo) && (!dnsOnly || outboundNetInfo.Network.IsDnsMapped) && (chooseNetworkByName == null || StringUtil.IsEqualIgnoreCase(chooseNetworkByName, outboundNetInfo.Network.Name)))
                 {
                     list.Add(new DagNetRoute
                     {
                         NetworkName   = outboundNetInfo.Network.Name,
                         SourceIPAddr  = outboundNetInfo.SourceIPAddr,
                         TargetPort    = targetNicInfo.TargetPort,
                         TargetIPAddr  = targetNicInfo.IPAddr,
                         IsCrossSubnet = targetNicInfo.IsCrossSubnet
                     });
                     if (dnsOnly || chooseNetworkByName != null)
                     {
                         break;
                     }
                 }
             }
             dagNetConfig = this.netConfig;
             return(list.ToArray());
         }
     }
     dagNetConfig = this.netConfig;
     return(null);
 }
 public DagNetRoute[] BuildRoutes(string targetServer, out DagNetConfig dagNetConfig)
 {
     return(this.BuildRoutes(targetServer, false, null, out dagNetConfig));
 }
Beispiel #10
0
        public static DagNetRoute[] ProposeRoutes(string targetServer, out DagNetConfig dagNetConfig)
        {
            DagNetChooser netChooser = DagNetEnvironment.NetChooser;

            return(netChooser.BuildRoutes(targetServer, out dagNetConfig));
        }
Beispiel #11
0
        private int GetCurrentReplicationPort()
        {
            DagNetConfig dagNetConfig = DagNetEnvironment.FetchLastKnownNetConfig();

            return(dagNetConfig.ReplicationPort);
        }