예제 #1
0
        static DefaultChannelId()
        {
            int    processId       = -1;
            string customProcessId = SystemPropertyUtil.Get("io.netty.processId");

            if (customProcessId is object)
            {
                if (!int.TryParse(customProcessId, out processId))
                {
                    processId = -1;
                }
                if (processId < 0 || processId > MaxProcessId)
                {
                    processId = -1;
                    Logger.Warn("-Dio.netty.processId: {} (malformed)", customProcessId);
                }
                else if (Logger.DebugEnabled)
                {
                    Logger.Debug("-Dio.netty.processId: {} (user-set)", processId);
                }
            }
            if (processId < 0)
            {
                processId = DefaultProcessId();
                if (Logger.DebugEnabled)
                {
                    Logger.Debug("-Dio.netty.processId: {} (auto-detected)", processId);
                }
            }
            ProcessId = processId;
            byte[] machineId       = null;
            string customMachineId = SystemPropertyUtil.Get("io.netty.machineId");

            if (customMachineId is object)
            {
                if (MachineIdPattern.Match(customMachineId).Success)
                {
                    machineId = ParseMachineId(customMachineId);
                    if (Logger.DebugEnabled)
                    {
                        Logger.Debug("-Dio.netty.machineId: {} (user-set)", customMachineId);
                    }
                }
                else
                {
                    Logger.Warn("-Dio.netty.machineId: {} (malformed)", customMachineId);
                }
            }

            if (machineId is null)
            {
                machineId = DefaultMachineId();
                if (Logger.DebugEnabled)
                {
                    Logger.Debug("-Dio.netty.machineId: {} (auto-detected)", MacAddressUtil.FormatAddress(machineId));
                }
            }
            MachineId = machineId;
        }
예제 #2
0
 static byte[] DefaultMachineId()
 {
     byte[] bestMacAddr = MacAddressUtil.GetBestAvailableMac();
     if (bestMacAddr == null)
     {
         bestMacAddr = new byte[MacAddressUtil.MacAddressLength];
         ThreadLocalRandom.Value.NextBytes(bestMacAddr);
         Logger.Warn(
             "Failed to find a usable hardware address from the network interfaces; using random bytes: {}",
             MacAddressUtil.FormatAddress(bestMacAddr));
     }
     return(bestMacAddr);
 }