/// <summary> /// Reads the WireGuard service configuration from file. /// </summary> /// <param name="filePath">File path of WireGuard service configuration file.</param> /// <returns>Success status of reading from the WireGuard service configuration file.</returns> public bool ReadFromFile(string filePath) { if (!File.Exists(filePath)) { return(false); } var parser = new IniParser.FileIniDataParser(); var iniData = parser.ReadFile(filePath); Interface = new InterfaceProperties() { PrivateKey = iniData["Interface"]["PrivateKey"], Address = iniData["Interface"]["Address"], DNS = iniData["Interface"]["DNS"], }; Peer = new PeerProperties() { PublicKey = iniData["Peer"]["PublicKey"], AllowedIPs = iniData["Peer"]["AllowedIPs"], Endpoint = iniData["Peer"]["Endpoint"], }; return(true); }
/// <summary> /// Sets the endpoint in a conf file, as well as a public key. /// </summary> /// <param name="endpoint">The endpoint of the peer.</param> /// <param name="publicKey">The public key of the peer.</param> /// <param name="allowedIPs">A space-delimited string of the allowed IPs for the peer.</param> /// <param name="dns">The DNS server address of the interface.</param> public void SetEndpoint(string endpoint, string publicKey, string allowedIPs, string dns) { var newPeer = Peer; newPeer.Endpoint = endpoint; newPeer.AllowedIPs = allowedIPs; newPeer.PublicKey = publicKey; Peer = newPeer; var newInterface = Interface; newInterface.DNS = dns; Interface = newInterface; WriteToFile(filePath); }
/// <summary> /// Initializes a new instance of the <see cref="Config"/> class. /// </summary> /// <param name="privateKey">Private key of the interface.</param> /// <param name="address">Address of the interface.</param> /// <param name="dns">DNS of the interface.</param> public Config(string privateKey, string address, string dns) { Interface = new InterfaceProperties() { PrivateKey = privateKey, Address = address, DNS = dns, }; Peer = new PeerProperties() { PublicKey = string.Empty, AllowedIPs = string.Empty, Endpoint = string.Empty, }; }
/// <summary> /// Initializes a new instance of the <see cref="ProbeMatchMsg"/> class /// </summary> /// <param name="instanceId">The instance id of the probe message</param> /// <param name="messageNumber">The number of the probe message</param> /// <param name="matches">The properties </param> public ProbeMatchMsg(string instanceId, uint messageNumber, PeerProperties[] matches) { this.instanceId = instanceId; this.messageNumber = messageNumber; this.matches = matches; }