private void ExtractHosts(Match match) { int defaultPort = defaultMongoDBPort; if (_scheme == ConnectionStringScheme.MongoDBPlusSrv) { defaultPort = defaultSrvPort; } List <EndPoint> endPoints = new List <EndPoint>(); foreach (Capture host in match.Groups["host"].Captures) { if (_scheme == ConnectionStringScheme.MongoDBPlusSrv && Regex.IsMatch(host.Value, @".*:\d+")) { throw new MongoConfigurationException("Host for mongodb+srv scheme cannot specify a port."); } EndPoint endPoint; if (EndPointHelper.TryParse(host.Value, defaultPort, out endPoint)) { endPoints.Add(endPoint); } else { throw new MongoConfigurationException(string.Format("Host '{0}' is not valid.", host.Value)); } } if (_scheme == ConnectionStringScheme.MongoDBPlusSrv && endPoints.Count > 1) { throw new MongoConfigurationException("Only 1 host is allowed when using the mongodb+srv scheme."); } _hosts = endPoints; }
static void Main(string[] args) { Game.EventSystem.Add(DLLType.Model, typeof(Game).Assembly); Game.EventSystem.Add(DLLType.Hotfix, typeof(Program).Assembly); EndPoint endPoint = null; bool result = EndPointHelper.TryParse("127.0.0.1:6060", out endPoint); Console.WriteLine($"EndPoint Parse result:{result} endPoint:{endPoint}"); Game.Scene.AddComponent <OpcodeTypeComponent>(); Game.Scene.AddComponent <MessageDispatherComponent>(); Game.Scene.AddComponent <NetOuterComponent, IPEndPoint>((IPEndPoint)endPoint); while (true) { try { Thread.Sleep(1); Game.EventSystem.Update(); } catch (Exception e) { Log.Error(e); } } Console.ReadLine(); }
private void ValidateResolvedHosts(string original, List <string> resolved) { // Helper functions... Func <string, string[]> getParentParts = x => x.Split('.').Skip(1).ToArray(); // Indicates whether "a" ends with "b" Func <string[], string[], bool> endsWith = (a, b) => { if (a.Length < b.Length) { return(false); } // loop from back to front making sure that all of b is at the back of a, in order. for (int ai = a.Length - 1, bi = b.Length - 1; bi >= 0; ai--, bi--) { if (a[ai] != b[bi]) { return(false); } } return(true); }; if (resolved.Count == 0) { throw new MongoConfigurationException($"No hosts were found in the SRV record for {original}."); } // for each resolved host, make sure that it ends with domain of the parent. var originalParentParts = getParentParts(original); foreach (var resolvedHost in resolved) { EndPoint endPoint; if (!EndPointHelper.TryParse(resolvedHost, 0, out endPoint) || !(endPoint is DnsEndPoint)) { throw new MongoConfigurationException($"Unable to parse {resolvedHost} as a hostname."); } var host = ((DnsEndPoint)endPoint).Host; if (!endsWith(getParentParts(host), originalParentParts)) { throw new MongoConfigurationException($"Hosts in the SRV record must have the same parent domain as the seed host."); } } }
private void ExtractHosts(Match match) { List <EndPoint> endPoints = new List <EndPoint>(); foreach (Capture host in match.Groups["host"].Captures) { EndPoint endPoint; if (EndPointHelper.TryParse(host.Value, out endPoint)) { endPoints.Add(endPoint); } else { throw new MongoConfigurationException(string.Format("Host '{0}' is not valid.", host.Value)); } } _hosts = endPoints; }
private void ValidateResolvedHosts(string original, List <string> resolved) { if (resolved.Count == 0) { throw new MongoConfigurationException($"No hosts were found in the SRV record for {original}."); } // for each resolved host, make sure that it ends with domain of the parent. foreach (var resolvedHost in resolved) { EndPoint endPoint; if (!EndPointHelper.TryParse(resolvedHost, 0, out endPoint) || !(endPoint is DnsEndPoint)) { throw new MongoConfigurationException($"Unable to parse {resolvedHost} as a hostname."); } var dnsEndPoint = (DnsEndPoint)endPoint; var host = ((DnsEndPoint)endPoint).Host; if (!HasValidParentDomain(original, dnsEndPoint)) { throw new MongoConfigurationException($"Hosts in the SRV record must have the same parent domain as the seed host."); } } }