Initialization


You must initialize the AnyFirewall™ Engine before any data can be sent or received. The initialization includes setting the Eyeball AnyFirewall™ Server address and credentials required to allocate any resources on the AnyFirewall™ Server. The AnyFirewall™ Server comprises two servers: STUN and TURN, which are specified separately.

AFEngine Object Instantiation

// For Windows, Linux, Mac, iOS
m_pAFEngine = new CAnyFirewallEngine;
// For Android
m_pAFEngine = new AnyFirewallEngine;

Library Instantiation

// For Windows
m_bAFEngineInit = m_pAFEngine->InitDll(AfxGetInstanceHandle(),
AF_MODE_AUTO, true);
// For Linux, Mac, iOS, Android
m_bAFEngineInit = m_pAFEngine->Init();
// Create a store to keep server settings
serverStoreID = m_pAFEngine->CreateServerStore(AF_MODE_MSOCS, true);
 To use AFE in Microsoft Lync mode, use AF_MODE_ MSOCS in place of AF_MODE_ AUTO. 


Initiate STUN and TURN ports

// Create strings describing the AnyFirewall™ Server’s addresses and ports for STUN and TURN
string sStunHosts = m_pAFEngine->CreateHost(
                          AF_HOST_PUBLIC,
                          “70.38.102.237”,
                          3478,
                          AF_PROTOCOL_UDP,
                          NULL
              );
sStunHosts += m_pAFEngine->CreateHost(
                          AF_HOST_PUBLIC,
                          “70.38.102.237”,
                          3478,
                          AF_PROTOCOL_TCP,
                          NULL
              );
string sTurnHosts = m_pAFEngine->CreateHost(
                          AF_HOST_PUBLIC,
                          “70.38.102.237”,
                          3478,
                          AF_PROTOCOL_UDP,
                          NULL
              );
sTurnHosts += m_pAFEngine->CreateHost(
                          AF_HOST_PUBLIC,
                          “70.38.102.238”,
                          443,
                          AF_PROTOCOL_TCP,
                          NULL
              );
// Specify the AnyFirewall Server and the authentication information
m_pAFEngine->SetSTUNServer(serverStoreID, sStunHosts);
m_pAFEngine->SetTURNServer(serverStoreID, sTurnHosts);
m_pAFEngine->SetTURNUsernamePassword(serverStoreID , sTURNUsername, sTURNPassword);
The method CreateHost creates a description of the host the AnyFirewall™ Server is running on. When connecting to a server with a public IP address (“70.38.102.237” in this example), the first parameter should be set to AF_HOST_PUBLIC. The fourth parameter specifies AF_PROTOCOL_UDP  or AF_PROTOCOL_TCP.
Note that the servers may also be specified using DNS SRV records.
// Specify the STUN server using DNS SRV records.
m_pAFEngine->SetSTUNServer(serverStoreID, “dns-srv _stun._tls.eyeball.com 0 tls”);

The function SetSTUNServer sets the STUN server for binding requests. The function SetTURNServer sets the TURN server for relaying data. In the above example, the last parameter of CreateHost function is specified as NULL. This means that AFE will use default STUN timing parameters for connecting to the specified servers. These parameters can be customized with struct AfConnectionParams. For more details, please see the reference for CreateHost function.

After the servers are set, DetectConnectivity should be called. The parameter to this function can be used to specify which checks should be performed during this phase.

struct AfFirewallDetectionParams fdp;
fdp.iDetectUdpConnectivity = 1;
fdp.iDetectTcpConnectivity = 1;
fdp.iDetectProxyConnectivity = 1;
fdp.iDetectUPnPConnectivity = 1;
fdp.iCheckTurnCredentials = 1;
fdp.iUPnPDeviceDiscoveryTimeout = 3000;
m_pAFEngine->DetectConnectivity(serverStoreID, &fdp);