Basic SDK Functions
The functions below are essential to start, stop and communicate with the VPN SDK.
User Login Credentials Needed
You must have an active user account in order to create a minimum viable VPN product. Press the 'Add a New User' button at https://app.vpnwholesaler.com/users to create one.
At the bare minimum and considering that you already have login credentials for an active VPN account, you should implement the following functions and commands in order to create a minimum viable VPN product:
- Initialize SDK
- Set API domain
- Login
- Set VPN type
- Set Binary Path
- Start VPN connection
- Stop VPN connection
- Finalize SDK
Initialize SDK​
Intializes the SDK with a callback and sets necessary path to OpenVPN binary.
Login required: No
Code: InitOVSCore
Input:
- C
- Java
int InitOVSCore(callback)
int InitOVSCore(OVSNotifyCB callback, Activity context)
Input Parameters:
Callback - reference to callback function with following signature:
void (char* notify_data)
Response:
int - returns 0 if SDK was intialized sucessfully and other value in case of failure
Code sample:
- macOS
- Android
First, include the provided CoreAPI.h to your project:
#include "CoreAPI.h"
You can handle JSON using JSON-C:
#include <json-c/json.h>
Then you should define callback function:
static void EVCoreNotify(const char *szNotify)
{
}
The callback function should accept JSON encoded as string.
Once that's done, you can go ahead and intialize SDK by providing path to openvpn binary:
int main(int argc, const char * argv[]) {
// insert code here...
int ret;
ret = InitOVSCore(EVCoreNotify);
if (ret != 0)
{
exit(1);
}
...
}
It is recommended to implement event listener in your Activity class in the following way:
public class MainActivity extends BaseActivity implements VPNSDK.CommandNotifyCB {
@Override
public void onNotify(int notification, int error, Object data) {
switch (notification) {
// Following is called when VPN status was changed
case VPNSDK.OVS_NOTIFY_CODES.OVS_NOTIFY_VPN_CONNECT_FAILED:
case VPNSDK.OVS_NOTIFY_CODES.OVS_NOTIFY_VPN_ABNOMARLY_DISCONNECTED:
case VPNSDK.OVS_NOTIFY_CODES.OVS_NOTIFY_VPN_DISCONNECTED: {
// Do something when VPN was disconnected
break;
}
case VPNSDK.OVS_NOTIFY_CODES.OVS_NOTIFY_VPN_CONNECTING: {
// Do something when VPN was started to connect
break;
}
case VPNSDK.OVS_NOTIFY_CODES.OVS_NOTIFY_VPN_CONNECTED: {
// Do something when VPN was connected
break;
}
// Following is called when we request VPN status explicitly
case VPNSDK.OVS_NOTIFY_CODES.OVS_NOTIFY_GET_STATUS: {
int state = (Integer)((Map)data).get("VPN_Status");
switch (state) {
case VPNSDK.VPN_NOTIFY_STATUS.VPN_NOTIFY_DISCONNECTED:
case VPNSDK.VPN_NOTIFY_STATUS.VPN_NOTIFY_ABNORMALLY_DISCONNECTED:
case VPNSDK.VPN_NOTIFY_STATUS.VPN_NOTIFY_CONN_FAILED: {
// Do something when VPN was disconnected
break;
}
case VPNSDK.VPN_NOTIFY_STATUS.VPN_NOTIFY_ASSIGNIP:
case VPNSDK.VPN_NOTIFY_STATUS.VPN_NOTIFY_GETCONFIG:
case VPNSDK.VPN_NOTIFY_STATUS.VPN_NOTIFY_AUTH:
case VPNSDK.VPN_NOTIFY_STATUS.VPN_NOTIFY_CONNECTING: {
// Do something when VPN was started to connect
break;
}
case VPNSDK.VPN_NOTIFY_STATUS.VPN_NOTIFY_CONNECTED: {
// Do something when VPN was connected
break;
}
}
break;
}
}
}
}
Then you can initialize the SDK using the following code:
VPNSDK.InitOVSCore(this, this);
Finalize SDK​
Unloads SDK and finalizes all running threads. It is necessary to call this method before exit to avoid leaks.
Login required: No
Code: FinalizeOVSCore()
Input: None
Response: None
Code sample:
- macOS
- Android
FinalizeOVSCore();
VPNSDK.FinalizeOVSCore();
Send command​
Asynchronously sends command to SDK. Command result will be returned by calling the callback that was specified on initialization.
All operations in SDK are called asynchronously, and therefore a single callback is used to receive responses from all SDK functions. All responses are encoded as JSON and described in the relevant sections.
Login required: Depending on the command
CmdProc Code: CmdProc(szCmdData)
Input:
{
"cmd": int,
"data: { Command parameters }
}
Response:
Generally, responses carry the following JSON structure:
{
"code": integer
"err": integer
"data": { object }
}
Where:
code - the invoked command's notification event.
err - error code.
data - response based on the notification code.