Example #1
0
        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;
        }