Ejemplo n.º 1
0
 public static bool TryParse(string str, out HiddenServicePortDefinition portDefinition)
 {
     portDefinition = null;
     if (!str.Trim().StartsWith("HiddenServicePort ", StringComparison.OrdinalIgnoreCase))
         return false;
     var parts = str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
     if (parts.Length != 3)
         return false;
     if (!int.TryParse(parts[1].Trim(), out int virtualPort))
         return false;
     var addressPort = parts[2].Trim().Split(new []{':'}, StringSplitOptions.RemoveEmptyEntries);
     if (addressPort.Length != 2)
         return false;
     if (!int.TryParse(addressPort[1].Trim(), out int port))
         return false;
     if (!IPAddress.TryParse(addressPort[0].Trim(), out IPAddress address))
         return false;
     portDefinition = new HiddenServicePortDefinition() { VirtualPort = virtualPort, Endpoint = new IPEndPoint(address, port) };
     return true;
 }
Ejemplo n.º 2
0
 public static bool TryParse(string str, out Torrc value)
 {
     value = null;
     List<HiddenServiceDir> serviceDirectories = new List<HiddenServiceDir>();
     var lines = str.Split(new char[] { '\n' });
     HiddenServiceDir currentDirectory = null;
     foreach (var line in lines)
     {
         if (HiddenServiceDir.TryParse(line, out var dir))
         {
             serviceDirectories.Add(dir);
             currentDirectory = dir;
         }
         else if (HiddenServicePortDefinition.TryParse(line, out var portDef) && currentDirectory != null)
         {
             currentDirectory.ServicePorts.Add(portDef);
         }
     }
     value = new Torrc() { ServiceDirectories = serviceDirectories };
     return true;
 }