IOTC Platform  Ver: 4.3.6.2-0-ge1f616e
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
P2PTunnelCommon.h File Reference
#include "TUTKGlobalAPIs.h"

Macros

#define TUNNEL_API   __declspec(dllimport)
 
#define TUNNEL_API_DEPRECATED
 
#define TUNNEL_MAX_PORT_MAPPING_SERVICE_NUMBER   256
 
#define MAX_AUTH_DATA_LEN   1000
 
#define MAX_SERVICE_ID_LEN   32
 
#define TUNNEL_ER_NoERROR   0
 
#define TUNNEL_ER_NOT_INITIALIZED   -30000
 
#define TUNNEL_ER_EXCEED_MAX_SERVICE   -30001
 
#define TUNNEL_ER_BIND_LOCAL_SERVICE   -30002
 
#define TUNNEL_ER_LISTEN_LOCAL_SERVICE   -30003
 
#define TUNNEL_ER_FAIL_CREATE_THREAD   -30004
 
#define TUNNEL_ER_ALREADY_CONNECTED   -30005
 
#define TUNNEL_ER_DISCONNECTED   -30006
 
#define TUNNEL_ER_ALREADY_INITIALIZED   -30007
 
#define TUNNEL_ER_AUTH_FAILED   -30008
 
#define TUNNEL_ER_EXCEED_MAX_LEN   -30009
 
#define TUNNEL_ER_INVALID_SID   -30010
 
#define TUNNEL_ER_UID_UNLICENSE   -30011
 
#define TUNNEL_ER_UID_NO_PERMISSION   -30012
 
#define TUNNEL_ER_UID_NOT_SUPPORT_RELAY   -30013
 
#define TUNNEL_ER_DEVICE_NOT_ONLINE   -30014
 
#define TUNNEL_ER_DEVICE_NOT_LISTENING   -30015
 
#define TUNNEL_ER_NETWORK_UNREACHABLE   -30016
 
#define TUNNEL_ER_FAILED_SETUP_CONNECTION   -30017
 
#define TUNNEL_ER_LOGIN_FAILED   -30018
 
#define TUNNEL_ER_EXCEED_MAX_SESSION   -30019
 
#define TUNNEL_ER_AGENT_NOT_SUPPORT   -30020
 
#define TUNNEL_ER_INVALID_ARG   -30021
 
#define TUNNEL_ER_OS_RESOURCE_LACK   -30022
 
#define TUNNEL_ER_AGENT_NOT_CONNECTING   -30023
 
#define TUNNEL_ER_NO_FREE_SESSION   -30024
 
#define TUNNEL_ER_CONNECTION_CANCELLED   -30025
 
#define TUNNEL_ER_OPERATION_IS_INVALID   -30026
 
#define TUNNEL_ER_HANDSHAKE_FAILED   -30027
 
#define TUNNEL_ER_REMOTE_NOT_SUPPORT_DTLS   -30028
 
#define TUNNEL_ER_LOCAL_NOT_SUPPORT_DTLS   -30029
 
#define TUNNEL_ER_TIMEOUT   -30030
 
#define TUNNEL_ER_SESSION_CLOSE_BY_REMOTE   -30031
 
#define TUNNEL_ER_REMOTE_TIMEOUT_DISCONNECT   -30032
 
#define TUNNEL_ER_REJECT   -30033
 
#define TUNNEL_ER_RETRY   -30034
 
#define TUNNEL_ER_INIT_OTHER_MODULE_FAIL   -30035
 
#define TUNNEL_ER_REMOTE_NOT_SUPPORT   -30036
 
#define TUNNEL_ER_LOCAL_EXIT   -30037
 
#define TUNNEL_ER_REMOTE_RDT_EXIT   -30038
 
#define TUNNEL_ER_REMOTE_RDT_ABORT   -30039
 
#define TUNNEL_ER_RDT_EXCEED_MAX_CHANNEL   -30040
 
#define TUNNEL_ER_CHANNEL_OCCUPIED   -30041
 
#define TUNNEL_ER_CREATE_DTLS_FAIL   -30042
 
#define TUNNEL_ER_INVALID_RDT_ID   -30043
 
#define TUNNEL_ER_RDT_DESTROYED   -30044
 
#define TUNNEL_ER_RDT_RCV_DATA_END   -30045
 
#define TUNNEL_ER_UNDEFINED   -31000
 

Typedefs

typedef void(__stdcall * tunnelStatusCB )(int32_t nErrorCode, int32_t nSessionID, void *pArg)
 

Enumerations

enum  P2PTunnelConnectionType { TUNNEL_CONNECT_AUTO = 0, TUNNEL_CONNECT_MANUAL = 1, TUNNEL_CONNECT_COUNT }
 

Functions

TUNNEL_API_DEPRECATED int32_t P2PTunnel_Version (void)
 Get the version of P2PTunnel module.
 
TUNNEL_API const char * P2PTunnel_Version_String (void)
 Get the version of P2PTunnel module.
 
TUNNEL_API void P2PTunnelAgent_Set_Log_Path (const char *path, int32_t nMaxSize)
 Set path of log file.
 
TUNNEL_API int32_t P2PTunnel_Set_Log_Attr (LogAttr logAttr)
 Set Attribute of log file.
 
TUNNEL_API int32_t P2PTunnelSetConnectionOption (P2PTunnelConnectionType type)
 Setup the connection mode of P2PTunnel.
 
TUNNEL_API int32_t P2PTunnel_LastIOTime (int32_t nSessionID)
 Get last IO time of SID.
 
TUNNEL_API int32_t P2PTunnel_SetBufSize (int32_t nSessionID, int32_t nSize)
 Set P2PTunnel buffer size.
 
TUNNEL_API void P2PTunnel_SetTcpRecvBufSize (uint32_t nSize)
 Set P2PTunnel tcp socket recv buffer size.
 

Detailed Description

This file describes common P2PTunnel module APIs of server and agent.

Attention
P2PTunnel module can't be used with IOTC and RDT module at the same process.

Macro Definition Documentation

#define MAX_AUTH_DATA_LEN   1000

The maximum size, in byte, of the authentication data used in P2PTunnelAgent_Connect()

#define MAX_SERVICE_ID_LEN   32

The maximum size, in byte, of Service ID used in P2PTunnelAgent_ServiceMapping()

#define TUNNEL_API   __declspec(dllimport)
#define TUNNEL_API_DEPRECATED
#define TUNNEL_ER_AGENT_NOT_CONNECTING   -30023

Tunnel Agent isn't connecting.

#define TUNNEL_ER_AGENT_NOT_SUPPORT   -30020

Tunnel agent can't call P2PTunnelServer_GetSessionInfo()

#define TUNNEL_ER_ALREADY_CONNECTED   -30005

Tunnel agent has already connected to a tunnel server, therefore, it failed connect to another tunnel server

#define TUNNEL_ER_ALREADY_INITIALIZED   -30007

The P2PTunnel module has been initialized in a tunnel server or a tunnel agent

#define TUNNEL_ER_AUTH_FAILED   -30008

Failed to connect to tunnel server because authentication data is wrong.

#define TUNNEL_ER_BIND_LOCAL_SERVICE   -30002

Failed to start port mapping when binding because local port had been used by the other service in agent side

#define TUNNEL_ER_CHANNEL_OCCUPIED   -30041

The specific IOTC session and channel ID is used now so can't use the same resource. You can choose other IOTC channel for RDT use or wait RDT_Abort() to release resource automatically.

#define TUNNEL_ER_CONNECTION_CANCELLED   -30025

Connection cancelled

#define TUNNEL_ER_CREATE_DTLS_FAIL   -30042

Fails to create safe channel

#define TUNNEL_ER_DEVICE_NOT_LISTENING   -30015

Tunner server is not listening for connections.

#define TUNNEL_ER_DEVICE_NOT_ONLINE   -30014

Tunnel server not login to IOTC server.

#define TUNNEL_ER_DISCONNECTED   -30006

The tunnel between tunnel agent and tunnel server has been disconnected. Used in tunnel status callback function for notifying tunnel connection status

#define TUNNEL_ER_EXCEED_MAX_LEN   -30009

Authentication data length exceed MAX_AUTH_DATA_LEN.

#define TUNNEL_ER_EXCEED_MAX_SERVICE   -30001

The number of P2PTunnel port mapping service has reached maximum. The maximum number of P2PTunnel port mapping service is determined by TUNNEL_MAX_PORT_MAPPING_SERVICE_NUMBER

#define TUNNEL_ER_EXCEED_MAX_SESSION   -30019

Notify tunnel server session connection alreay reached maximum through tunnelStatusCB, can't be connected anymore until anyone session release.

#define TUNNEL_ER_FAIL_CREATE_THREAD   -30004

P2PTunnel module fails to create threads. Please check if OS has ability to create threads for P2PTunnel module.

#define TUNNEL_ER_FAILED_SETUP_CONNECTION   -30017

Tunnel agent failed to connect to tunnel server maybe network unstable.

#define TUNNEL_ER_HANDSHAKE_FAILED   -30027

P2PTunnel handshake failed.

#define TUNNEL_ER_INIT_OTHER_MODULE_FAIL   -30035

init other module fail

#define TUNNEL_ER_INVALID_ARG   -30021

The arguments passed to a function is invalid.

#define TUNNEL_ER_INVALID_RDT_ID   -30043

The specified RDT channel ID is valid

#define TUNNEL_ER_INVALID_SID   -30010

The specified P2PTunnel session ID is not valid

#define TUNNEL_ER_LISTEN_LOCAL_SERVICE   -30003

Failed to start port mapping when listening because local port has been used by the other service in agent side

#define TUNNEL_ER_LOCAL_EXIT   -30037

Force stop connect proccess by other APIs

#define TUNNEL_ER_LOCAL_NOT_SUPPORT_DTLS   -30029

Remote P2PTunnel need connect with DTLS

#define TUNNEL_ER_LOGIN_FAILED   -30018

Tunnel server failed to login to IOTC Server but still can be connected by tunnel agent on LAN.

#define TUNNEL_ER_NETWORK_UNREACHABLE   -30016

Internet not available or firewall block.

#define TUNNEL_ER_NO_FREE_SESSION   -30024

Unable to get free session.

#define TUNNEL_ER_NoERROR   0

The function is performed successfully.

#define TUNNEL_ER_NOT_INITIALIZED   -30000

P2PTunnel module is not initialized yet. Please use P2PTunnelServerInitialize() or P2PTunnelAgentInitialize() for initialization.

#define TUNNEL_ER_OPERATION_IS_INVALID   -30026

The API operation is invalid

#define TUNNEL_ER_OS_RESOURCE_LACK   -30022

OS resource not enough to malloc memory or open socket.

#define TUNNEL_ER_RDT_DESTROYED   -30044

RDT channel has been destroyed. Probably caused by local or remote site calls RDT_Destroy(), or remote site has closed IOTC session.

#define TUNNEL_ER_RDT_EXCEED_MAX_CHANNEL   -30040

The number of RDT channels has reached maximum. Please use RDT_Set_Max_Channel_Number() to set up the max number of RDT channels. By default, the maximum channel number is MAX_DEFAULT_RDT_CHANNEL_NUMBER.

#define TUNNEL_ER_RDT_RCV_DATA_END   -30045

The remote site has finished sending data, then destroy the RDT channel. The local site will get this error code by RDT_Read() when there is no more data from this RDT channel.

#define TUNNEL_ER_REJECT   -30033

API or remote reject

#define TUNNEL_ER_REMOTE_NOT_SUPPORT   -30036

Remote P2PTunnel not support this feature

#define TUNNEL_ER_REMOTE_NOT_SUPPORT_DTLS   -30028

Remote P2PTunnel not support DTLS

#define TUNNEL_ER_REMOTE_RDT_ABORT   -30039

The remote site want to abort the RDT channel immediately and don't care data transmission. The local site will get this error code by RDT_Read(), RDT_Write(), RDT_Destroy() for handling this RDT channel to close.

#define TUNNEL_ER_REMOTE_RDT_EXIT   -30038

The remote site called RDT_Create_Exit() so the RDT channel exit creating.

#define TUNNEL_ER_REMOTE_TIMEOUT_DISCONNECT   -30032

This IOTC session is disconnected because remote site has no any response after a specified timeout expires.

#define TUNNEL_ER_RETRY   -30034

retry API

#define TUNNEL_ER_SESSION_CLOSE_BY_REMOTE   -30031

The remote site already closes the IOTC session. Please call IOTC_Session_Close() to release local IOTC session resource

#define TUNNEL_ER_TIMEOUT   -30030

API timeout

#define TUNNEL_ER_UID_NO_PERMISSION   -30012

The specified device does not support advance function (TCP relay and P2PTunnel module)

#define TUNNEL_ER_UID_NOT_SUPPORT_RELAY   -30013

This UID can't setup connection through relay.

#define TUNNEL_ER_UID_UNLICENSE   -30011

This UID is illegal.

#define TUNNEL_ER_UNDEFINED   -31000
#define TUNNEL_MAX_PORT_MAPPING_SERVICE_NUMBER   256

The maximum number of port mapping service in P2PTunnel module

Typedef Documentation

typedef void(__stdcall * tunnelStatusCB)(int32_t nErrorCode, int32_t nSessionID, void *pArg)

The prototype of getting tunnel status function, used by a tunnel server or tunnel agent to be notified if tunnel status is changed.

Parameters
nErrorCode[out]
nSessionID[in] Which session ID of the P2PTunnel session disconnected
pArg[out] Tunnel server or agent pass user data

Enumeration Type Documentation

Enumerator:
TUNNEL_CONNECT_AUTO 

Create tunnel connection by SDK inner conenction process.

TUNNEL_CONNECT_MANUAL 

Create tunnel connection with user specified IOTC session ID and channel ID.

TUNNEL_CONNECT_COUNT 

Function Documentation

TUNNEL_API int32_t P2PTunnel_LastIOTime ( int32_t  nSessionID)

Get last IO time of SID.

Get last IO time of SID even if the connection is closed.

Parameters
nSessionID[in] Session ID
Returns
POSIX time of last IO if return value > 0
0 if no connection ever established on this SID
Error code if return value < 0
TUNNEL_API int32_t P2PTunnel_Set_Log_Attr ( LogAttr  logAttr)

Set Attribute of log file.

Parameters
logAttr[in] See LogAttr
Returns
RDT_ER_NoERROR on success.
The value < 0
TUNNEL_API int32_t P2PTunnel_SetBufSize ( int32_t  nSessionID,
int32_t  nSize 
)

Set P2PTunnel buffer size.

Set P2PTunnel buffer size, larger buffer leads more maximum throughput

Parameters
nSessionID[in] Session ID
nSize[in] Buffer size in Bytes
Returns
0 if success
Error code if return value < 0
TUNNEL_API void P2PTunnel_SetTcpRecvBufSize ( uint32_t  nSize)

Set P2PTunnel tcp socket recv buffer size.

Set P2PTunnel tcp socket recv buffer size, larger buffer leads more maximum throughput

Parameters
nSize[in] Buffer size in Bytes
Attention
Must be called after initialization
TUNNEL_API_DEPRECATED int32_t P2PTunnel_Version ( void  )

Get the version of P2PTunnel module.

This function returns the version of P2PTunnel module.

Returns
The version of P2PTunnel module from high byte to low byte, for example, 0x01020304 means the version is 1.2.3.4
TUNNEL_API const char* P2PTunnel_Version_String ( void  )

Get the version of P2PTunnel module.

This function returns the version of P2PTunnel module.

TUNNEL_API void P2PTunnelAgent_Set_Log_Path ( const char *  path,
int32_t  nMaxSize 
)

Set path of log file.

Set the absolute path of log file

Parameters
path[in] The path of log file, NULL = disable Log
nMaxSize[in] The maximum size of log file in Bytes, 0 = unlimit
TUNNEL_API int32_t P2PTunnelSetConnectionOption ( P2PTunnelConnectionType  type)

Setup the connection mode of P2PTunnel.

Use TUNNEL_CONNECT_MANUAL mode if you need share IOTC session with other modules, like AV or RDT. Otherwize there is no need to call this API.

Returns
TUNNEL_ER_NoERROR if setup successfully
Error code if return value < 0
See Also
P2PTunnelServer_Listen(), P2PTunnelAgent_Attach_Connect_Ex()
Attention
Must be called before P2PTunnelServer_Listen and P2PTunnelAgent_Attach_Connect_Ex