Wireguard Protocol

Wireguard is a modern, fast, and secure VPN protocol. It aims to be simpler, leaner, and more performant than other VPN protocols like IPSec and OpenVPN. It allows developers to easily integrate WireGuard VPN functionality into their applications. With Wireguard, you can establish secure VPN connections, manage configurations, and control the VPN lifecycle directly from your app's code.

Adding Wireguard protocol support

To use Wireguard, set the Protocol field to the Wireguard value from the Core.Model.Enums.Protocol enum when starting the VPN.

var sdk = new SDK();

var getNodesRequest = new GetNodesRequest
{
    Carrier = carrier,
    Protocol = Core.Model.Enums.Protocol.Wireguard,
};

var getNodesResponse = await sdk.GetNodesAsync(getNodesRequest).ConfigureAwait(false);

var getCredentialsRequest = new GetCredentialsRequest
{
    VpnNode = getNodesResponse.VpnCountries.FirstOrDefault(),
    WithCertificate = true,
    Protocol = Core.Model.Enums.Protocol.Wireguard,
    AppVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version?.ToString(),
};

var getCredentialsResponse = await sdk.GetCredentialsAsync(getCredentialsRequest).ConfigureAwait(false);
// ...

When changing the VPN protocol, it's important to call the GetNodes and GetCredentials methods before invoking StartVPN. This is necessary because by calling GetNodes and GetCredentials after changing the protocol and before starting the VPN, you ensure that your application has the necessary information (available nodes) and authentication details (credentials) to successfully establish a VPN connection using the desired protocol.

Last updated