示例#1
0
        public HostRouteData ToRouteData()
        {
            var routeData = new HostRouteData();

            routeData.HostId      = this.Id;
            routeData.HostIntAddr = InternalAddress.ToIPv4String();
            routeData.HostExtAddr = ExternalAddress.ToIPv4String();
            routeData.HostName    = this.UniqueName;
            routeData.IsClient    = this.IsClientMode;
            foreach (var aId in this.actorDic.Keys.ToArray())
            {
                routeData.ActorIds.Add(aId);
            }
            return(routeData);
        }
示例#2
0
        public bool AddHost(HostRouteData hostData, bool noReg=false)
        {
            if (!hostData.IsClient)
            {
                string hostName   = hostData.HostName;
                ulong hostId      = hostData.HostId;
                string address    = hostData.HostIntAddr;
                string extAddress = hostData.HostExtAddr;

                mRouteData.mHNAME2ADDR[hostName] = address;
                mRouteData.mADDR2HNAME[address] = hostName;

                //AddAddressID(addrId, hostId);

                AddNameId(hostName, hostId);

#if !CLIENT
                CacheAddr2ExAddr.SetWithoutLock(address, extAddress); 
                CacheHNAME2ADDR.SetWithoutLock(hostName, address); 
#endif

                mRouteData.mIP2EXTIP[Basic.ToIP(address)]    = Basic.ToIP(extAddress);
                mRouteData.mEXTIP2IP[Basic.ToIP(extAddress)] = Basic.ToIP(address);

                if (!Global.Host.IsIdHost() && !noReg
#if CLIENT
                )
#else
                    && !Global.SingleProcessMode)
#endif
                {
#if !CLIENT
                    Global.IdHostRef.AddHostId(hostId, hostName, address, extAddress, (ok, idAll) =>
                    {
                        Log.Info("AddHost to Id.App", ok, hostId, hostName, address, extAddress);
                        //Global.IdHostRef.GetIdAll(hostId, (ok2, idAll) =>
                        //{
                        if (ok)
                        {
                            Log.Error(idAll.ToString());
                            mRouteData.UpdateFrom(idAll);
                        }
                        else
                        {
                            bool done = false;
                            while (!done)
                            {
                                var task = Global.IdHostRef.AddHostIdAsync(hostId, hostName, address, extAddress);
                                task.Wait();
                                if (task.Result.arg0)
                                {
                                    done = true;
                                    Log.Error(task.Result.arg1.ToString());
                                    mRouteData.UpdateFrom(task.Result.arg1);
                                }
                                else
                                {
                                    Thread.Sleep(100);
                                }
                            }
                        }
                        //});
                    });
#else
                    return true;
#endif
                }

                return true;
#endif
            }
            else
            {
                return RegisterClientHost(hostId, hostName, address, noReg);
            }
        }