mirror of
https://github.com/outbackdingo/parodus.git
synced 2026-01-27 18:20:04 +00:00
Compare commits
42 Commits
1.1.1
...
event_hand
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8c99132287 | ||
|
|
680b0471ab | ||
|
|
4bd5223f08 | ||
|
|
17c7faff50 | ||
|
|
01120da9ac | ||
|
|
c7c6fb4926 | ||
|
|
f4b2c252ae | ||
|
|
8794ce2092 | ||
|
|
a61e97633b | ||
|
|
4d3d6ec99d | ||
|
|
e6ac264e47 | ||
|
|
70c9975ae9 | ||
|
|
9a2613c0da | ||
|
|
11a2b6f123 | ||
|
|
81d8f59bbd | ||
|
|
846b0588c2 | ||
|
|
ad44ff0221 | ||
|
|
513647ceef | ||
|
|
2ec3443b1d | ||
|
|
55e10aa051 | ||
|
|
879a585b66 | ||
|
|
ea3534678b | ||
|
|
6ebb62ead4 | ||
|
|
5ec16a7370 | ||
|
|
7b81cb4efd | ||
|
|
4c6a6a99e6 | ||
|
|
106e1bfeb3 | ||
|
|
4f01170670 | ||
|
|
f37d1911d6 | ||
|
|
3a436999fc | ||
|
|
016c80960c | ||
|
|
b286857a22 | ||
|
|
f998106aed | ||
|
|
2d209b2a0d | ||
|
|
3f471100db | ||
|
|
ddc04f9da0 | ||
|
|
a23615f3a5 | ||
|
|
b1caff4a1a | ||
|
|
11c9052d77 | ||
|
|
5ceb57a8c3 | ||
|
|
c4ebe239ac | ||
|
|
3fb0708b15 |
10
CHANGELOG.md
10
CHANGELOG.md
@@ -14,6 +14,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
||||
- requestNewAuthToken will clear the token if it fails.
|
||||
- request auth token on every retry, not just after 403
|
||||
- update to use nopoll v 1.0.2
|
||||
- Add pause/resume heartBeatTimer
|
||||
- parodus event handler to listen to interface_down and interface_up event
|
||||
- Pause connection retry during interface_down event
|
||||
- Add callback handler for ping status change event
|
||||
- Fixed nopoll_conn_unref crash
|
||||
- Update retry timestamp in connection-health-file
|
||||
- fix so that parodus can be killed, even if in a connection fail loop
|
||||
- provide signal handlers so we shut down properly when INCLUDE_BREAKPAD active
|
||||
- send status code and reason in websocket close message
|
||||
- dont try to install handler for signal 9
|
||||
|
||||
## [1.0.2] - 2019-02-08
|
||||
- Refactored connection.c and updated corresponding unit tests
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# parodus
|
||||
|
||||
[](https://travis-ci.org/Comcast/parodus)
|
||||
[](https://travis-ci.org/xmidt-org/parodus)
|
||||
[](http://codecov.io/github/Comcast/parodus?branch=master)
|
||||
[](https://scan.coverity.com/projects/comcast-parodus)
|
||||
[](https://github.com/Comcast/parodus/blob/master/LICENSE)
|
||||
|
||||
@@ -25,6 +25,11 @@
|
||||
#include "config.h"
|
||||
#include "connection.h"
|
||||
|
||||
bool interface_down_event = false;
|
||||
|
||||
pthread_mutex_t interface_down_mut=PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_cond_t interface_down_con=PTHREAD_COND_INITIALIZER;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -139,3 +144,47 @@ void timespec_diff(struct timespec *start, struct timespec *stop,
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------*/
|
||||
/* For interface_down_event Flag */
|
||||
/*------------------------------------------------------------------------------*/
|
||||
|
||||
// Get value of interface_down_event
|
||||
bool get_interface_down_event()
|
||||
{
|
||||
bool tmp = false;
|
||||
pthread_mutex_lock (&interface_down_mut);
|
||||
tmp = interface_down_event;
|
||||
pthread_mutex_unlock (&interface_down_mut);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
// Reset value of interface_down_event to false
|
||||
void reset_interface_down_event()
|
||||
{
|
||||
pthread_mutex_lock (&interface_down_mut);
|
||||
interface_down_event = false;
|
||||
pthread_cond_signal(&interface_down_con);
|
||||
pthread_mutex_unlock (&interface_down_mut);
|
||||
}
|
||||
|
||||
// set value of interface_down_event to true
|
||||
void set_interface_down_event()
|
||||
{
|
||||
pthread_mutex_lock (&interface_down_mut);
|
||||
interface_down_event = true;
|
||||
pthread_mutex_unlock (&interface_down_mut);
|
||||
}
|
||||
|
||||
pthread_cond_t *get_interface_down_con(void)
|
||||
{
|
||||
return &interface_down_con;
|
||||
}
|
||||
|
||||
pthread_mutex_t *get_interface_down_mut(void)
|
||||
{
|
||||
return &interface_down_mut;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Macros */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#define UNUSED(x) (void )(x)
|
||||
#define NANO_SOCKET_SEND_TIMEOUT_MS 2000
|
||||
#define NANO_SOCKET_RCV_TIMEOUT_MS 500
|
||||
@@ -107,6 +108,7 @@ typedef struct {
|
||||
|
||||
//--- Used in connection.c for backoff delay timer
|
||||
typedef struct {
|
||||
struct timespec ts;
|
||||
int count;
|
||||
int max_count;
|
||||
int delay;
|
||||
@@ -157,6 +159,25 @@ void addCRUDmsgToQueue(wrp_msg_t *crudMsg);
|
||||
void timespec_diff(struct timespec *start, struct timespec *stop,
|
||||
struct timespec *result);
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------*/
|
||||
/* For interface_down_event Flag */
|
||||
/*------------------------------------------------------------------------------*/
|
||||
|
||||
// Get value of interface_down_event
|
||||
bool get_interface_down_event();
|
||||
|
||||
// Reset value of interface_down_event to false
|
||||
void reset_interface_down_event();
|
||||
|
||||
// Set value of interface_down_event to true
|
||||
void set_interface_down_event();
|
||||
|
||||
pthread_cond_t *get_interface_down_con();
|
||||
|
||||
pthread_mutex_t *get_interface_down_mut();
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -148,6 +148,11 @@ void createSocketConnection(void (* initKeypress)())
|
||||
OnboardLog("Reconnect detected, setting Ping_Miss reason for Reconnect\n");
|
||||
set_global_reconnect_reason("Ping_Miss");
|
||||
set_global_reconnect_status(true);
|
||||
// Invoke the ping status change event callback as "missed" ping
|
||||
if(NULL != on_ping_status_change)
|
||||
{
|
||||
on_ping_status_change("missed");
|
||||
}
|
||||
set_close_retry();
|
||||
}
|
||||
else
|
||||
@@ -163,15 +168,18 @@ void createSocketConnection(void (* initKeypress)())
|
||||
if( false == seshat_registered ) {
|
||||
seshat_registered = __registerWithSeshat();
|
||||
}
|
||||
|
||||
|
||||
// If interface down event is set, wait till interface is up again.
|
||||
if (get_interface_down_event ())
|
||||
if (0 != wait_while_interface_down ())
|
||||
break;
|
||||
|
||||
if(get_close_retry())
|
||||
{
|
||||
ParodusInfo("close_retry is %d, hence closing the connection and retrying\n", get_close_retry());
|
||||
close_and_unref_connection(get_global_conn());
|
||||
set_global_conn(NULL);
|
||||
|
||||
get_parodus_cfg()->cloud_status = CLOUD_STATUS_OFFLINE;
|
||||
ParodusInfo("cloud_status set as %s after connection close\n", get_parodus_cfg()->cloud_status);
|
||||
if(get_parodus_cfg()->cloud_disconnect !=NULL)
|
||||
{
|
||||
ParodusPrint("get_parodus_cfg()->cloud_disconnect is %s\n", get_parodus_cfg()->cloud_disconnect);
|
||||
@@ -211,13 +219,18 @@ void createSocketConnection(void (* initKeypress)())
|
||||
|
||||
deleteAllClients ();
|
||||
|
||||
ParodusInfo ("reconnect reason at close %s\n", get_global_reconnect_reason());
|
||||
ParodusInfo ("shutdown reason at close %s\n", get_global_shutdown_reason());
|
||||
close_and_unref_connection(get_global_conn());
|
||||
nopoll_ctx_unref(ctx);
|
||||
nopoll_cleanup_library();
|
||||
curl_global_cleanup();
|
||||
}
|
||||
|
||||
void shutdownSocketConnection(void) {
|
||||
void shutdownSocketConnection(char *reason) {
|
||||
set_global_shutdown_reason (reason);
|
||||
g_shutdown = true;
|
||||
reset_interface_down_event ();
|
||||
terminate_backoff_delay ();
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ extern UpStreamMsg *UpStreamMsgQ;
|
||||
* and creates the intial connection and manages the connection wait, close mechanisms.
|
||||
*/
|
||||
void createSocketConnection(void (* initKeypress)());
|
||||
void shutdownSocketConnection(void);
|
||||
void shutdownSocketConnection(char *reason);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
160
src/connection.c
160
src/connection.c
@@ -38,11 +38,34 @@
|
||||
|
||||
#define HTTP_CUSTOM_HEADER_COUNT 5
|
||||
#define INITIAL_CJWT_RETRY -2
|
||||
#define UPDATE_HEALTH_FILE_INTERVAL_SECS 450
|
||||
|
||||
/* Close codes defined in RFC 6455, section 11.7. */
|
||||
enum {
|
||||
CloseNormalClosure = 1000,
|
||||
CloseGoingAway = 1001,
|
||||
CloseProtocolError = 1002,
|
||||
CloseUnsupportedData = 1003,
|
||||
CloseNoStatus = 1005,
|
||||
CloseAbnormalClosure = 1006,
|
||||
CloseInvalidFramePayloadData = 1007,
|
||||
ClosePolicyViolation = 1008,
|
||||
CloseMessageTooBig = 1009,
|
||||
CloseMandatoryExtension = 1010,
|
||||
CloseInternalServerErr = 1011,
|
||||
CloseServiceRestart = 1012,
|
||||
CloseTryAgainLater = 1013,
|
||||
CloseTLSHandshake = 1015
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
pthread_mutex_t backoff_delay_mut=PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_cond_t backoff_delay_con=PTHREAD_COND_INITIALIZER;
|
||||
|
||||
static char *shutdown_reason = SHUTDOWN_REASON_PARODUS_STOP; /* goes in the close message */
|
||||
static char *reconnect_reason = "webpa_process_starts";
|
||||
static int cloud_disconnect_max_time = 5;
|
||||
static noPollConn *g_conn = NULL;
|
||||
@@ -65,6 +88,16 @@ void set_global_conn(noPollConn *conn)
|
||||
g_conn = conn;
|
||||
}
|
||||
|
||||
char *get_global_shutdown_reason()
|
||||
{
|
||||
return shutdown_reason;
|
||||
}
|
||||
|
||||
void set_global_shutdown_reason(char *reason)
|
||||
{
|
||||
shutdown_reason = reason;
|
||||
}
|
||||
|
||||
char *get_global_reconnect_reason()
|
||||
{
|
||||
return reconnect_reason;
|
||||
@@ -199,6 +232,14 @@ void init_backoff_timer (backoff_timer_t *timer, int max_count)
|
||||
timer->count = 1;
|
||||
timer->max_count = max_count;
|
||||
timer->delay = 1;
|
||||
clock_gettime (CLOCK_REALTIME, &timer->ts);
|
||||
}
|
||||
|
||||
void terminate_backoff_delay (void)
|
||||
{
|
||||
pthread_mutex_lock (&backoff_delay_mut);
|
||||
pthread_cond_signal(&backoff_delay_con);
|
||||
pthread_mutex_unlock (&backoff_delay_mut);
|
||||
}
|
||||
|
||||
int update_backoff_delay (backoff_timer_t *timer)
|
||||
@@ -211,11 +252,50 @@ int update_backoff_delay (backoff_timer_t *timer)
|
||||
return timer->delay;
|
||||
}
|
||||
|
||||
static void backoff_delay (backoff_timer_t *timer)
|
||||
#define BACKOFF_ERR -1
|
||||
#define BACKOFF_SHUTDOWN 1
|
||||
#define BACKOFF_DELAY_TAKEN 0
|
||||
|
||||
void start_conn_in_progress (void);
|
||||
|
||||
/* backoff_delay
|
||||
*
|
||||
* delays for the number of seconds specified in parameter timer
|
||||
* g_shutdown can break out of the delay.
|
||||
*
|
||||
* returns -1 pthread_cond_timedwait error
|
||||
* 1 shutdown
|
||||
* 0 delay taken
|
||||
*/
|
||||
static int backoff_delay (backoff_timer_t *timer)
|
||||
{
|
||||
struct timespec ts;
|
||||
int rtn;
|
||||
|
||||
// periodically update the health file.
|
||||
clock_gettime (CLOCK_REALTIME, &ts);
|
||||
if ((ts.tv_sec - timer->ts.tv_sec) >= UPDATE_HEALTH_FILE_INTERVAL_SECS) {
|
||||
start_conn_in_progress ();
|
||||
timer->ts.tv_sec += UPDATE_HEALTH_FILE_INTERVAL_SECS;
|
||||
}
|
||||
|
||||
update_backoff_delay (timer);
|
||||
ParodusInfo("Waiting with backoffRetryTime %d seconds\n", timer->delay);
|
||||
sleep (timer->delay);
|
||||
ts.tv_sec += timer->delay;
|
||||
|
||||
pthread_mutex_lock (&backoff_delay_mut);
|
||||
// The condition variable will only be set if we shut down.
|
||||
rtn = pthread_cond_timedwait (&backoff_delay_con, &backoff_delay_mut, &ts);
|
||||
pthread_mutex_unlock (&backoff_delay_mut);
|
||||
|
||||
if (g_shutdown)
|
||||
return BACKOFF_SHUTDOWN;
|
||||
if ((rtn != 0) && (rtn != ETIMEDOUT)) {
|
||||
ParodusError ("pthread_cond_timedwait error (%d) in backoff_delay.\n", rtn);
|
||||
return BACKOFF_ERR;
|
||||
}
|
||||
|
||||
return BACKOFF_DELAY_TAKEN;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
@@ -391,7 +471,7 @@ int nopoll_connect (create_connection_ctx_t *ctx, int is_ipv6)
|
||||
}
|
||||
if ((NULL == connection) && (!is_ipv6)) {
|
||||
if((checkHostIp(server->server_addr) == -2)) {
|
||||
if (check_timer_expired (&ctx->connect_timer, 15*60*1000)) {
|
||||
if (check_timer_expired (&ctx->connect_timer, 15*60*1000) && !get_interface_down_event()) {
|
||||
ParodusError("WebPA unable to connect due to DNS resolving to 10.0.0.1 for over 15 minutes; crashing service.\n");
|
||||
OnboardLog("WebPA unable to connect due to DNS resolving to 10.0.0.1 for over 15 minutes; crashing service.\n");
|
||||
OnboardLog("Reconnect detected, setting Dns_Res_webpa_reconnect reason for Reconnect\n");
|
||||
@@ -417,7 +497,7 @@ int nopoll_connect (create_connection_ctx_t *ctx, int is_ipv6)
|
||||
|
||||
int wait_connection_ready (create_connection_ctx_t *ctx)
|
||||
{
|
||||
int wait_status;
|
||||
int wait_status = 0;
|
||||
char *redirectURL = NULL;
|
||||
|
||||
if(nopoll_conn_wait_for_status_until_connection_ready(get_global_conn(), 10,
|
||||
@@ -520,7 +600,7 @@ int keep_trying_to_connect (create_connection_ctx_t *ctx,
|
||||
{
|
||||
int rtn;
|
||||
|
||||
while (true)
|
||||
while (!g_shutdown)
|
||||
{
|
||||
set_extra_headers (ctx);
|
||||
|
||||
@@ -530,13 +610,54 @@ int keep_trying_to_connect (create_connection_ctx_t *ctx,
|
||||
|
||||
if (rtn == CONN_WAIT_ACTION_RETRY) // if redirected or build_headers
|
||||
continue;
|
||||
backoff_delay (backoff_timer); // 3,7,15,31 ..
|
||||
|
||||
// If interface down event is set, stop retry
|
||||
// and wait till interface is up again.
|
||||
if(get_interface_down_event()) {
|
||||
if (0 != wait_while_interface_down())
|
||||
return false;
|
||||
start_conn_in_progress();
|
||||
ParodusInfo("Interface is back up, re-initializing the convey header\n");
|
||||
// Reset the reconnect reason by initializing the convey header again
|
||||
((header_info_t *)(&ctx->header_info))->conveyHeader = getWebpaConveyHeader();
|
||||
ParodusInfo("Received reconnect_reason as:%s\n", reconnect_reason);
|
||||
} else {
|
||||
if (backoff_delay (backoff_timer) // 3,7,15,31 ..
|
||||
!= BACKOFF_DELAY_TAKEN) // shutdown or cond wait error
|
||||
return false;
|
||||
}
|
||||
|
||||
if (rtn == CONN_WAIT_RETRY_DNS)
|
||||
return false; //find_server again
|
||||
// else retry
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int wait_while_interface_down()
|
||||
|
||||
{
|
||||
int rtn;
|
||||
|
||||
ParodusError("Interface is down, hence waiting until its up\n");
|
||||
close_and_unref_connection (get_global_conn());
|
||||
set_global_conn(NULL);
|
||||
|
||||
while (get_interface_down_event ()) {
|
||||
|
||||
pthread_mutex_lock(get_interface_down_mut());
|
||||
rtn = pthread_cond_wait(get_interface_down_con(), get_interface_down_mut());
|
||||
pthread_mutex_unlock (get_interface_down_mut());
|
||||
|
||||
if (rtn != 0)
|
||||
ParodusError("Error on pthread_cond_wait (%d) in wait_while_interface_down\n", rtn);
|
||||
|
||||
if ((rtn != 0) || g_shutdown)
|
||||
return -1;
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
@@ -579,6 +700,7 @@ int createNopollConnection(noPollCtx *ctx)
|
||||
set_current_server (&conn_ctx);
|
||||
if (keep_trying_to_connect (&conn_ctx, &backoff_timer))
|
||||
break;
|
||||
|
||||
// retry dns query
|
||||
}
|
||||
|
||||
@@ -596,6 +718,12 @@ int createNopollConnection(noPollCtx *ctx)
|
||||
get_parodus_cfg()->cloud_status = CLOUD_STATUS_ONLINE;
|
||||
ParodusInfo("cloud_status set as %s after successful connection\n", get_parodus_cfg()->cloud_status);
|
||||
|
||||
// Invoke the ping status change event callback as "received" ping
|
||||
if(NULL != on_ping_status_change)
|
||||
{
|
||||
on_ping_status_change("received");
|
||||
}
|
||||
|
||||
if((get_parodus_cfg()->boot_time != 0) && init) {
|
||||
getCurrentTime(connectTimePtr);
|
||||
ParodusInfo("connect_time-diff-boot_time=%d\n", connectTimePtr->tv_sec - get_parodus_cfg()->boot_time);
|
||||
@@ -668,10 +796,16 @@ static noPollConnOpts * createConnOpts (char * extra_headers, bool secure)
|
||||
void close_and_unref_connection(noPollConn *conn)
|
||||
{
|
||||
if (conn) {
|
||||
nopoll_conn_close(conn);
|
||||
if (0 < nopoll_conn_ref_count (conn)) {
|
||||
nopoll_conn_unref(conn);
|
||||
}
|
||||
const char *reason = get_global_shutdown_reason();
|
||||
int reason_len = 0;
|
||||
int status = CloseNoStatus;
|
||||
if (NULL != reason) {
|
||||
reason_len = (int) strlen (reason);
|
||||
status = CloseNormalClosure;
|
||||
}
|
||||
nopoll_conn_close_ext(conn, status, reason, reason_len);
|
||||
get_parodus_cfg()->cloud_status = CLOUD_STATUS_OFFLINE;
|
||||
ParodusInfo("cloud_status set as %s after connection close\n", get_parodus_cfg()->cloud_status);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -710,3 +844,9 @@ void stop_conn_in_progress (void)
|
||||
write_conn_in_prog_file ("STOP");
|
||||
}
|
||||
|
||||
|
||||
void registerParodusOnPingStatusChangeHandler(parodusOnPingStatusChangeHandler callback_func)
|
||||
{
|
||||
on_ping_status_change = callback_func;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,17 @@ extern "C" {
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
#define SHUTDOWN_REASON_PARODUS_STOP "parodus_stopping"
|
||||
#define SHUTDOWN_REASON_SYSTEM_RESTART "system_restarting"
|
||||
|
||||
/**
|
||||
* parodusOnPingStatusChangeHandler - Function pointer
|
||||
* Used to define callback function to do additional processing
|
||||
* when websocket Ping status change event
|
||||
* i.e. ping_miss or ping receive after miss
|
||||
*/
|
||||
typedef void (*parodusOnPingStatusChangeHandler) (char * status);
|
||||
parodusOnPingStatusChangeHandler on_ping_status_change;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Function Prototypes */
|
||||
@@ -49,6 +59,9 @@ void close_and_unref_connection(noPollConn *);
|
||||
noPollConn *get_global_conn(void);
|
||||
void set_global_conn(noPollConn *);
|
||||
|
||||
char *get_global_shutdown_reason();
|
||||
void set_global_shutdown_reason(char *reason);
|
||||
|
||||
char *get_global_reconnect_reason();
|
||||
void set_global_reconnect_reason(char *reason);
|
||||
|
||||
@@ -64,6 +77,14 @@ void set_cloud_disconnect_time(int disconnTime);
|
||||
void start_conn_in_progress (void);
|
||||
void stop_conn_in_progress (void);
|
||||
|
||||
// To Register parodusOnPingStatusChangeHandler Callback function
|
||||
void registerParodusOnPingStatusChangeHandler(parodusOnPingStatusChangeHandler on_ping_status_change);
|
||||
|
||||
// To stop connection and wait duing interface down state
|
||||
int wait_while_interface_down (void);
|
||||
|
||||
void terminate_backoff_delay (void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -22,8 +22,10 @@
|
||||
*/
|
||||
|
||||
#include "heartBeat.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
volatile unsigned int heartBeatTimer = 0;
|
||||
volatile bool paused = false;
|
||||
|
||||
pthread_mutex_t heartBeat_mut=PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
@@ -49,8 +51,27 @@ void reset_heartBeatTimer()
|
||||
void increment_heartBeatTimer(unsigned int inc_time_ms)
|
||||
{
|
||||
pthread_mutex_lock (&heartBeat_mut);
|
||||
heartBeatTimer += inc_time_ms;
|
||||
if (!paused)
|
||||
heartBeatTimer += inc_time_ms;
|
||||
pthread_mutex_unlock (&heartBeat_mut);
|
||||
}
|
||||
|
||||
// Pause heartBeatTimer, i.e. stop incrementing
|
||||
void pause_heartBeatTimer()
|
||||
{
|
||||
pthread_mutex_lock (&heartBeat_mut);
|
||||
heartBeatTimer = 0;
|
||||
paused = true;
|
||||
pthread_mutex_unlock (&heartBeat_mut);
|
||||
}
|
||||
|
||||
// Resume heartBeatTimer, i.e. resume incrementing
|
||||
void resume_heartBeatTimer()
|
||||
{
|
||||
pthread_mutex_lock (&heartBeat_mut);
|
||||
paused = false;
|
||||
pthread_mutex_unlock (&heartBeat_mut);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -39,6 +39,12 @@ void reset_heartBeatTimer();
|
||||
// Increment value of heartBeatTimer to desired value
|
||||
void increment_heartBeatTimer(unsigned int inc_time_ms);
|
||||
|
||||
// Pause heartBeatTimer, i.e. stop incrementing
|
||||
void pause_heartBeatTimer();
|
||||
|
||||
// Resume heartBeatTimer, i.e. resume incrementing
|
||||
void resume_heartBeatTimer();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
54
src/main.c
54
src/main.c
@@ -19,14 +19,14 @@
|
||||
#include "stdlib.h"
|
||||
#include "config.h"
|
||||
#include "auth_token.h"
|
||||
#include "connection.h"
|
||||
#include "conn_interface.h"
|
||||
#include "parodus_log.h"
|
||||
#include <curl/curl.h>
|
||||
#ifdef INCLUDE_BREAKPAD
|
||||
#include "breakpad_wrapper.h"
|
||||
#else
|
||||
#include "signal.h"
|
||||
#endif
|
||||
#include "signal.h"
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Macros */
|
||||
@@ -36,7 +36,7 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Data Structures */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* none */
|
||||
typedef void Sigfunc(int);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
@@ -46,30 +46,53 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Function Prototypes */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
#ifndef INCLUDE_BREAKPAD
|
||||
static void sig_handler(int sig);
|
||||
|
||||
Sigfunc *
|
||||
signal (int signo, Sigfunc *func)
|
||||
{
|
||||
struct sigaction act, oact;
|
||||
|
||||
act.sa_handler = func;
|
||||
sigemptyset (&act.sa_mask);
|
||||
act.sa_flags = 0;
|
||||
if (signo == SIGALRM) {
|
||||
#ifdef SA_INTERRUPT
|
||||
act.sa_flags |= SA_INTERRUPT; /* SunOS 4.x */
|
||||
#endif
|
||||
} else {
|
||||
#ifdef SA_RESTART
|
||||
act.sa_flags |= SA_RESTART; /* SVR4, 4.4BSD */
|
||||
#endif
|
||||
}
|
||||
if (sigaction (signo, &act, &oact) < 0) {
|
||||
ParodusError ("Signal Handler for signal %d not installed!\n", signo);
|
||||
return (SIG_ERR);
|
||||
}
|
||||
return (oact.sa_handler);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int main( int argc, char **argv)
|
||||
{
|
||||
#ifdef INCLUDE_BREAKPAD
|
||||
breakpad_ExceptionHandler();
|
||||
#else
|
||||
set_global_shutdown_reason (SHUTDOWN_REASON_PARODUS_STOP);
|
||||
signal(SIGTERM, sig_handler);
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGUSR1, sig_handler);
|
||||
signal(SIGUSR2, sig_handler);
|
||||
signal(SIGQUIT, sig_handler);
|
||||
signal(SIGHUP, sig_handler);
|
||||
signal(SIGALRM, sig_handler);
|
||||
#ifdef INCLUDE_BREAKPAD
|
||||
/* breakpad handles the signals SIGSEGV, SIGBUS, SIGFPE, and SIGILL */
|
||||
breakpad_ExceptionHandler();
|
||||
#else
|
||||
signal(SIGSEGV, sig_handler);
|
||||
signal(SIGBUS, sig_handler);
|
||||
signal(SIGKILL, sig_handler);
|
||||
signal(SIGFPE, sig_handler);
|
||||
signal(SIGILL, sig_handler);
|
||||
signal(SIGQUIT, sig_handler);
|
||||
signal(SIGHUP, sig_handler);
|
||||
signal(SIGALRM, sig_handler);
|
||||
#endif
|
||||
ParodusCfg *cfg;
|
||||
|
||||
@@ -97,7 +120,6 @@ const char *rdk_logger_module_fetch(void)
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Internal functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
#ifndef INCLUDE_BREAKPAD
|
||||
static void sig_handler(int sig)
|
||||
{
|
||||
|
||||
@@ -105,12 +127,13 @@ static void sig_handler(int sig)
|
||||
{
|
||||
signal(SIGINT, sig_handler); /* reset it to this function */
|
||||
ParodusInfo("SIGINT received!\n");
|
||||
shutdownSocketConnection();
|
||||
shutdownSocketConnection(SHUTDOWN_REASON_PARODUS_STOP);
|
||||
}
|
||||
else if ( sig == SIGUSR1 )
|
||||
{
|
||||
signal(SIGUSR1, sig_handler); /* reset it to this function */
|
||||
ParodusInfo("SIGUSR1 received!\n");
|
||||
shutdownSocketConnection(SHUTDOWN_REASON_SYSTEM_RESTART);
|
||||
}
|
||||
else if ( sig == SIGUSR2 )
|
||||
{
|
||||
@@ -134,8 +157,7 @@ static void sig_handler(int sig)
|
||||
else
|
||||
{
|
||||
ParodusInfo("Signal %d received!\n", sig);
|
||||
shutdownSocketConnection();
|
||||
shutdownSocketConnection(SHUTDOWN_REASON_PARODUS_STOP);
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -177,8 +177,15 @@ void listenerOnCloseMessage (noPollCtx * ctx, noPollConn * conn, noPollPtr user_
|
||||
OnboardLog("Reconnect detected, setting Reconnect reason as Unknown\n");
|
||||
set_global_reconnect_reason("Unknown");
|
||||
}
|
||||
|
||||
if(!get_interface_down_event())
|
||||
{
|
||||
ParodusInfo("Setting the close and retry connection\n");
|
||||
set_close_retry();
|
||||
}
|
||||
else
|
||||
ParodusInfo("Not Setting the close and retry connection as interface is down\n");
|
||||
|
||||
set_close_retry();
|
||||
ParodusPrint("listenerOnCloseMessage(): mutex unlock in producer thread\n");
|
||||
}
|
||||
|
||||
|
||||
@@ -74,26 +74,34 @@ void sendMessage(noPollConn *conn, void *msg, size_t len)
|
||||
{
|
||||
ParodusError("Failed to send msg upstream as connection is not OK\n");
|
||||
OnboardLog("Failed to send msg upstream as connection is not OK\n");
|
||||
if (connErr == 0)
|
||||
{
|
||||
getCurrentTime(connStuck_startPtr);
|
||||
ParodusInfo("Conn got stuck, initialized the first timer\n");
|
||||
connErr = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
getCurrentTime(connStuck_endPtr);
|
||||
timeDiff = timeValDiff(connStuck_startPtr, connStuck_endPtr);
|
||||
ParodusPrint("checking timeout difference:%ld\n", timeDiff);
|
||||
|
||||
if( timeDiff >= (10*60*1000))
|
||||
if(get_interface_down_event())
|
||||
{
|
||||
ParodusError("Unable to connect to server since interface is down\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (connErr == 0)
|
||||
{
|
||||
ParodusError("conn got stuck for over 10 minutes; crashing service.\n");
|
||||
OnboardLog("conn got stuck for over 10 minutes; crashing service.\n");
|
||||
kill(getpid(),SIGTERM);
|
||||
getCurrentTime(connStuck_startPtr);
|
||||
ParodusInfo("Conn got stuck, initialized the first timer\n");
|
||||
connErr = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
getCurrentTime(connStuck_endPtr);
|
||||
timeDiff = timeValDiff(connStuck_startPtr, connStuck_endPtr);
|
||||
ParodusPrint("checking timeout difference:%ld\n", timeDiff);
|
||||
|
||||
}
|
||||
if( timeDiff >= (10*60*1000))
|
||||
{
|
||||
ParodusError("conn got stuck for over 10 minutes; crashing service.\n");
|
||||
OnboardLog("conn got stuck for over 10 minutes; crashing service.\n");
|
||||
kill(getpid(),SIGTERM);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static char *reconnect_reason = "webpa_process_starts";
|
||||
UpStreamMsg *UpStreamMsgQ;
|
||||
ParodusMsg *ParodusMsgQ;
|
||||
pthread_mutex_t g_mutex=PTHREAD_MUTEX_INITIALIZER;
|
||||
@@ -75,6 +76,21 @@ noPollMutexUnlock mutex_unlock
|
||||
function_called();
|
||||
}
|
||||
|
||||
char *get_global_reconnect_reason()
|
||||
{
|
||||
return reconnect_reason;
|
||||
}
|
||||
|
||||
char *get_global_shutdown_reason()
|
||||
{
|
||||
return SHUTDOWN_REASON_PARODUS_STOP;
|
||||
}
|
||||
|
||||
void set_global_shutdown_reason(char *reason)
|
||||
{
|
||||
UNUSED(reason);
|
||||
}
|
||||
|
||||
void start_conn_in_progress (void)
|
||||
{
|
||||
}
|
||||
@@ -83,6 +99,24 @@ void stop_conn_in_progress (void)
|
||||
{
|
||||
}
|
||||
|
||||
void reset_interface_down_event (void)
|
||||
{
|
||||
}
|
||||
|
||||
bool get_interface_down_event (void)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int wait_while_interface_down (void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void terminate_backoff_delay (void)
|
||||
{
|
||||
}
|
||||
|
||||
void packMetaData()
|
||||
{
|
||||
function_called();
|
||||
@@ -309,7 +343,6 @@ void test_createSocketConnection1()
|
||||
expect_function_call(nopoll_ctx_unref);
|
||||
expect_function_call(nopoll_cleanup_library);
|
||||
createSocketConnection(NULL);
|
||||
assert_string_equal(get_parodus_cfg()->cloud_status, CLOUD_STATUS_OFFLINE);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <assert.h>
|
||||
#include <CUnit/Basic.h>
|
||||
#include <nopoll.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "../src/ParodusInternal.h"
|
||||
#include "../src/connection.h"
|
||||
@@ -60,7 +61,10 @@ extern int keep_trying_to_connect (create_connection_ctx_t *ctx,
|
||||
|
||||
bool close_retry;
|
||||
bool LastReasonStatus;
|
||||
pthread_mutex_t close_mut;
|
||||
bool interface_down_event = false;
|
||||
pthread_mutex_t close_mut;
|
||||
pthread_mutex_t interface_down_mut=PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_cond_t interface_down_con=PTHREAD_COND_INITIALIZER;
|
||||
|
||||
// Mock values
|
||||
bool g_shutdown = false;
|
||||
@@ -80,6 +84,35 @@ char* getWebpaConveyHeader()
|
||||
return (char*) "WebPA-1.6 (TG1682)";
|
||||
}
|
||||
|
||||
|
||||
void set_interface_down_event()
|
||||
{
|
||||
interface_down_event = true;
|
||||
}
|
||||
|
||||
void reset_interface_down_event()
|
||||
{
|
||||
pthread_mutex_lock (&interface_down_mut);
|
||||
interface_down_event = false;
|
||||
pthread_cond_signal(&interface_down_con);
|
||||
pthread_mutex_unlock (&interface_down_mut);
|
||||
}
|
||||
|
||||
bool get_interface_down_event()
|
||||
{
|
||||
return interface_down_event;
|
||||
}
|
||||
|
||||
pthread_cond_t *get_interface_down_con(void)
|
||||
{
|
||||
return &interface_down_con;
|
||||
}
|
||||
|
||||
pthread_mutex_t *get_interface_down_mut(void)
|
||||
{
|
||||
return &interface_down_mut;
|
||||
}
|
||||
|
||||
noPollConn * nopoll_conn_new_opts (noPollCtx * ctx, noPollConnOpts * opts, const char * host_ip, const char * host_port, const char * host_name,const char * get_url,const char * protocols, const char * origin)
|
||||
{
|
||||
UNUSED(host_port); UNUSED(host_name); UNUSED(get_url); UNUSED(protocols);
|
||||
@@ -148,11 +181,9 @@ void nopoll_conn_close (noPollConn *conn)
|
||||
UNUSED(conn);
|
||||
}
|
||||
|
||||
int nopoll_conn_ref_count (noPollConn *conn)
|
||||
void nopoll_conn_close_ext (noPollConn *conn, int status, const char *reason, int reason_size)
|
||||
{
|
||||
UNUSED(conn);
|
||||
function_called ();
|
||||
return (nopoll_bool) mock();
|
||||
UNUSED(conn); UNUSED(status); UNUSED(reason); UNUSED(reason_size);
|
||||
}
|
||||
|
||||
int checkHostIp(char * serverIP)
|
||||
@@ -200,6 +231,7 @@ int allow_insecure_conn (char **server_addr, unsigned int *port)
|
||||
/* Tests */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
void test_get_global_conn()
|
||||
{
|
||||
assert_null(get_global_conn());
|
||||
@@ -695,8 +727,6 @@ void test_connect_and_wait ()
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_false);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
will_return (nopoll_conn_ref_count, 0);
|
||||
expect_function_call (nopoll_conn_ref_count);
|
||||
assert_int_equal (connect_and_wait (&ctx), CONN_WAIT_RETRY_DNS);
|
||||
|
||||
Cfg.flags = 0;
|
||||
@@ -706,8 +736,6 @@ void test_connect_and_wait ()
|
||||
expect_function_call (nopoll_conn_new_opts);
|
||||
will_return (nopoll_conn_is_ok, nopoll_false);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_ref_count, 0);
|
||||
expect_function_call (nopoll_conn_ref_count);
|
||||
assert_int_equal (connect_and_wait (&ctx), CONN_WAIT_RETRY_DNS);
|
||||
|
||||
will_return (nopoll_conn_new_opts, &connection1);
|
||||
@@ -745,8 +773,6 @@ void test_connect_and_wait ()
|
||||
expect_function_call (nopoll_conn_tls_new6);
|
||||
will_return (nopoll_conn_is_ok, nopoll_false);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_ref_count, 0);
|
||||
expect_function_call (nopoll_conn_ref_count);
|
||||
will_return (nopoll_conn_tls_new, NULL);
|
||||
expect_function_call (nopoll_conn_tls_new);
|
||||
will_return (checkHostIp, 0);
|
||||
@@ -757,8 +783,6 @@ void test_connect_and_wait ()
|
||||
expect_function_call (nopoll_conn_tls_new6);
|
||||
will_return (nopoll_conn_is_ok, nopoll_false);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_ref_count, 0);
|
||||
expect_function_call (nopoll_conn_ref_count);
|
||||
will_return (nopoll_conn_tls_new, &connection1);
|
||||
expect_function_call (nopoll_conn_tls_new);
|
||||
will_return (nopoll_conn_is_ok, nopoll_true);
|
||||
@@ -778,8 +802,6 @@ void test_connect_and_wait ()
|
||||
mock_redirect = "mydns.mycom.net";
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_false);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
will_return (nopoll_conn_ref_count, 0);
|
||||
expect_function_call (nopoll_conn_ref_count);
|
||||
assert_int_equal (connect_and_wait (&ctx), CONN_WAIT_RETRY_DNS);
|
||||
|
||||
will_return (nopoll_conn_tls_new, &connection1);
|
||||
@@ -790,8 +812,6 @@ void test_connect_and_wait ()
|
||||
mock_redirect = "https://mydns.mycom.net";
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_false);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
will_return (nopoll_conn_ref_count, 0);
|
||||
expect_function_call (nopoll_conn_ref_count);
|
||||
assert_int_equal (connect_and_wait (&ctx), CONN_WAIT_ACTION_RETRY);
|
||||
}
|
||||
|
||||
@@ -843,8 +863,6 @@ void test_keep_trying ()
|
||||
mock_redirect = "https://mydns.mycom.net";
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_false);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
will_return (nopoll_conn_ref_count, 0);
|
||||
expect_function_call (nopoll_conn_ref_count);
|
||||
will_return (nopoll_conn_tls_new, &connection1);
|
||||
expect_function_call (nopoll_conn_tls_new);
|
||||
will_return (nopoll_conn_is_ok, nopoll_true);
|
||||
@@ -863,16 +881,12 @@ void test_keep_trying ()
|
||||
mock_redirect = "https://mydns.mycom.net";
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_false);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
will_return (nopoll_conn_ref_count, 0);
|
||||
expect_function_call (nopoll_conn_ref_count);
|
||||
will_return (nopoll_conn_tls_new, &connection1);
|
||||
expect_function_call (nopoll_conn_tls_new);
|
||||
will_return (nopoll_conn_is_ok, nopoll_true);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_false);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
will_return (nopoll_conn_ref_count, 0);
|
||||
expect_function_call (nopoll_conn_ref_count);
|
||||
init_backoff_timer (&backoff_timer, 5);
|
||||
rtn = keep_trying_to_connect (&ctx, &backoff_timer);
|
||||
assert_int_equal (rtn, false);
|
||||
@@ -895,8 +909,6 @@ void test_keep_trying ()
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_false);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
will_return (nopoll_conn_ref_count, 0);
|
||||
expect_function_call (nopoll_conn_ref_count);
|
||||
init_backoff_timer (&backoff_timer, 5);
|
||||
rtn = keep_trying_to_connect (&ctx, &backoff_timer);
|
||||
assert_int_equal (rtn, false);
|
||||
@@ -946,8 +958,6 @@ void test_create_nopoll_connection()
|
||||
expect_function_call (nopoll_conn_tls_new6);
|
||||
will_return (nopoll_conn_is_ok, nopoll_false);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_ref_count, 0);
|
||||
expect_function_call (nopoll_conn_ref_count);
|
||||
will_return (nopoll_conn_tls_new, &connection1);
|
||||
expect_function_call (nopoll_conn_tls_new);
|
||||
will_return (nopoll_conn_is_ok, nopoll_true);
|
||||
@@ -961,8 +971,6 @@ void test_create_nopoll_connection()
|
||||
expect_function_call (nopoll_conn_tls_new6);
|
||||
will_return (nopoll_conn_is_ok, nopoll_false);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_ref_count, 0);
|
||||
expect_function_call (nopoll_conn_ref_count);
|
||||
will_return (nopoll_conn_tls_new, &connection1);
|
||||
expect_function_call (nopoll_conn_tls_new);
|
||||
will_return (nopoll_conn_is_ok, nopoll_true);
|
||||
@@ -971,15 +979,11 @@ void test_create_nopoll_connection()
|
||||
mock_redirect = "https://mydns.mycom.net";
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_false);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
will_return (nopoll_conn_ref_count, 0);
|
||||
expect_function_call (nopoll_conn_ref_count);
|
||||
|
||||
will_return (nopoll_conn_tls_new6, &connection1);
|
||||
expect_function_call (nopoll_conn_tls_new6);
|
||||
will_return (nopoll_conn_is_ok, nopoll_false);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_ref_count, 0);
|
||||
expect_function_call (nopoll_conn_ref_count);
|
||||
will_return (nopoll_conn_tls_new, &connection1);
|
||||
expect_function_call (nopoll_conn_tls_new);
|
||||
will_return (nopoll_conn_is_ok, nopoll_true);
|
||||
@@ -1023,8 +1027,6 @@ void test_create_nopoll_connection()
|
||||
expect_function_call (nopoll_conn_tls_new6);
|
||||
will_return (nopoll_conn_is_ok, nopoll_false);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_ref_count, 0);
|
||||
expect_function_call (nopoll_conn_ref_count);
|
||||
mock_wait_status = 0;
|
||||
will_return (nopoll_conn_tls_new, &connection1);
|
||||
expect_function_call (nopoll_conn_tls_new);
|
||||
@@ -1038,6 +1040,149 @@ void test_create_nopoll_connection()
|
||||
|
||||
}
|
||||
|
||||
void test_get_interface_down_event()
|
||||
{
|
||||
assert_false(get_interface_down_event());
|
||||
set_interface_down_event();
|
||||
}
|
||||
|
||||
void *a()
|
||||
{
|
||||
sleep(15);
|
||||
reset_interface_down_event();
|
||||
pthread_exit(0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void test_interface_down_retry()
|
||||
{
|
||||
int rtn;
|
||||
ParodusCfg cfg;
|
||||
noPollCtx test_nopoll_ctx;
|
||||
pthread_t thread_a;
|
||||
|
||||
pthread_create(&thread_a, NULL, a, NULL);
|
||||
|
||||
memset(&cfg,0,sizeof(cfg));
|
||||
cfg.flags = 0;
|
||||
parStrncpy (cfg.webpa_url, "mydns.mycom.net:8080", sizeof(cfg.webpa_url));
|
||||
cfg.boot_time = 25;
|
||||
parStrncpy (cfg.hw_last_reboot_reason, "Test reason", sizeof(cfg.hw_last_reboot_reason));
|
||||
cfg.webpa_backoff_max = 30;
|
||||
parStrncpy (cfg.webpa_auth_token, "Auth---", sizeof (cfg.webpa_auth_token));
|
||||
parStrncpy(cfg.hw_model, "TG1682", sizeof(cfg.hw_model));
|
||||
parStrncpy(cfg.hw_manufacturer , "ARRISGroup,Inc.", sizeof(cfg.hw_manufacturer));
|
||||
parStrncpy(cfg.hw_mac , "123567892366", sizeof(cfg.hw_mac));
|
||||
parStrncpy(cfg.fw_name , "2.364s2", sizeof(cfg.fw_name));
|
||||
parStrncpy(cfg.webpa_protocol , "WebPA-1.6", sizeof(cfg.webpa_protocol));
|
||||
set_parodus_cfg(&cfg);
|
||||
rtn = createNopollConnection (&test_nopoll_ctx);
|
||||
assert_int_equal (rtn, nopoll_false);
|
||||
|
||||
parStrncpy (cfg.webpa_url, "http://mydns.mycom.net:8080", sizeof(cfg.webpa_url));
|
||||
set_parodus_cfg(&cfg);
|
||||
|
||||
mock_wait_status = 0;
|
||||
|
||||
will_return (nopoll_conn_new_opts, &connection1);
|
||||
expect_function_call (nopoll_conn_new_opts);
|
||||
will_return (nopoll_conn_is_ok, nopoll_true);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
rtn = createNopollConnection (&test_nopoll_ctx);
|
||||
assert_int_equal (rtn, nopoll_true);
|
||||
|
||||
parStrncpy (cfg.webpa_url, "https://mydns.mycom.net:8080", sizeof(cfg.webpa_url));
|
||||
cfg.flags = 0;
|
||||
set_parodus_cfg(&cfg);
|
||||
|
||||
will_return (nopoll_conn_tls_new6, &connection1);
|
||||
expect_function_call (nopoll_conn_tls_new6);
|
||||
will_return (nopoll_conn_is_ok, nopoll_false);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_tls_new, &connection1);
|
||||
expect_function_call (nopoll_conn_tls_new);
|
||||
will_return (nopoll_conn_is_ok, nopoll_true);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
rtn = createNopollConnection (&test_nopoll_ctx);
|
||||
assert_int_equal (rtn, nopoll_true);
|
||||
|
||||
will_return (nopoll_conn_tls_new6, &connection1);
|
||||
expect_function_call (nopoll_conn_tls_new6);
|
||||
will_return (nopoll_conn_is_ok, nopoll_false);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_tls_new, &connection1);
|
||||
expect_function_call (nopoll_conn_tls_new);
|
||||
will_return (nopoll_conn_is_ok, nopoll_true);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
mock_wait_status = 302;
|
||||
mock_redirect = "https://mydns.mycom.net";
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_false);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
|
||||
will_return (nopoll_conn_tls_new6, &connection1);
|
||||
expect_function_call (nopoll_conn_tls_new6);
|
||||
will_return (nopoll_conn_is_ok, nopoll_false);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_tls_new, &connection1);
|
||||
expect_function_call (nopoll_conn_tls_new);
|
||||
will_return (nopoll_conn_is_ok, nopoll_true);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
mock_wait_status = 0;
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
rtn = createNopollConnection (&test_nopoll_ctx);
|
||||
assert_int_equal (rtn, nopoll_true);
|
||||
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
cfg.acquire_jwt = 1;
|
||||
cfg.flags = FLAGS_IPV4_ONLY;
|
||||
set_parodus_cfg(&cfg);
|
||||
|
||||
will_return (allow_insecure_conn, -1);
|
||||
expect_function_call (allow_insecure_conn);
|
||||
will_return (nopoll_conn_tls_new, NULL);
|
||||
expect_function_call (nopoll_conn_tls_new);
|
||||
will_return (checkHostIp, 0);
|
||||
expect_function_call (checkHostIp);
|
||||
mock_server_addr = "mydns.myjwtcom.net";
|
||||
mock_port = 80;
|
||||
will_return (allow_insecure_conn, 0);
|
||||
expect_function_call (allow_insecure_conn);
|
||||
will_return (nopoll_conn_tls_new, &connection1);
|
||||
expect_function_call (nopoll_conn_tls_new);
|
||||
will_return (nopoll_conn_is_ok, nopoll_true);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
rtn = createNopollConnection (&test_nopoll_ctx);
|
||||
assert_int_equal (rtn, nopoll_true);
|
||||
|
||||
cfg.flags = 0;
|
||||
set_parodus_cfg(&cfg);
|
||||
|
||||
will_return (allow_insecure_conn, -1);
|
||||
expect_function_call (allow_insecure_conn);
|
||||
will_return (nopoll_conn_tls_new6, &connection1);
|
||||
expect_function_call (nopoll_conn_tls_new6);
|
||||
will_return (nopoll_conn_is_ok, nopoll_false);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
mock_wait_status = 0;
|
||||
will_return (nopoll_conn_tls_new, &connection1);
|
||||
expect_function_call (nopoll_conn_tls_new);
|
||||
will_return (nopoll_conn_is_ok, nopoll_true);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
rtn = createNopollConnection (&test_nopoll_ctx);
|
||||
assert_int_equal (rtn, nopoll_true);
|
||||
#endif
|
||||
pthread_join(thread_a, NULL);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
@@ -1065,7 +1210,9 @@ int main(void)
|
||||
cmocka_unit_test(test_wait_connection_ready),
|
||||
cmocka_unit_test(test_connect_and_wait),
|
||||
cmocka_unit_test(test_keep_trying),
|
||||
cmocka_unit_test(test_create_nopoll_connection)
|
||||
cmocka_unit_test(test_create_nopoll_connection),
|
||||
cmocka_unit_test(test_get_interface_down_event),
|
||||
cmocka_unit_test(test_interface_down_retry)
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <nopoll_private.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "../src/ParodusInternal.h"
|
||||
#include "../src/nopoll_handlers.h"
|
||||
#include "../src/parodus_log.h"
|
||||
|
||||
@@ -29,8 +30,11 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
volatile unsigned int heartBeatTimer;
|
||||
bool LastReasonStatus;
|
||||
bool interface_down_event = false;
|
||||
int closeReason = 0;
|
||||
pthread_mutex_t close_mut;
|
||||
pthread_mutex_t close_mut;
|
||||
pthread_mutex_t interface_down_mut=PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_cond_t interface_down_con=PTHREAD_COND_INITIALIZER;
|
||||
bool close_retry;
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Mocks */
|
||||
@@ -46,6 +50,24 @@ bool get_global_reconnect_status()
|
||||
return LastReasonStatus;
|
||||
}
|
||||
|
||||
void set_interface_down_event()
|
||||
{
|
||||
interface_down_event = true;
|
||||
}
|
||||
|
||||
void reset_interface_down_event()
|
||||
{
|
||||
pthread_mutex_lock (&interface_down_mut);
|
||||
interface_down_event = false;
|
||||
pthread_cond_signal(&interface_down_con);
|
||||
pthread_mutex_unlock (&interface_down_mut);
|
||||
}
|
||||
|
||||
bool get_interface_down_event()
|
||||
{
|
||||
return interface_down_event;
|
||||
}
|
||||
|
||||
void set_global_reconnect_status(bool status)
|
||||
{
|
||||
(void) status ;
|
||||
@@ -179,6 +201,30 @@ void test_listenerOnPingMessage()
|
||||
listenerOnPingMessage(NULL, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
void test_getInterfaceDownEvent()
|
||||
{
|
||||
set_interface_down_event();
|
||||
CU_ASSERT_TRUE(get_interface_down_event());
|
||||
}
|
||||
|
||||
void test_interfaceDownEvent()
|
||||
{
|
||||
char str[] = "SSL_Socket_Close";
|
||||
set_global_reconnect_status(true);
|
||||
set_interface_down_event();
|
||||
listenerOnCloseMessage(NULL, NULL, (noPollPtr) str);
|
||||
|
||||
}
|
||||
|
||||
void test_noInterfaceDownEvent()
|
||||
{
|
||||
char str[] = "SSL_Socket_Close";
|
||||
set_global_reconnect_status(true);
|
||||
reset_interface_down_event();
|
||||
listenerOnCloseMessage(NULL, NULL, (noPollPtr) str);
|
||||
}
|
||||
|
||||
|
||||
void add_suites( CU_pSuite *suite )
|
||||
{
|
||||
ParodusInfo("--------Start of Test Cases Execution ---------\n");
|
||||
@@ -186,6 +232,9 @@ void add_suites( CU_pSuite *suite )
|
||||
CU_add_test( *suite, "Test 1", test_listenerOnMessage_queue );
|
||||
CU_add_test( *suite, "Test 2", test_listenerOnCloseMessage );
|
||||
CU_add_test( *suite, "Test 3", test_listenerOnPingMessage );
|
||||
CU_add_test( *suite, "Test 4", test_getInterfaceDownEvent );
|
||||
CU_add_test( *suite, "Test 5", test_interfaceDownEvent );
|
||||
CU_add_test( *suite, "Test 6", test_noInterfaceDownEvent );
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
@@ -48,6 +48,11 @@ bool get_global_reconnect_status()
|
||||
return LastReasonStatus;
|
||||
}
|
||||
|
||||
bool get_interface_down_event()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void set_global_reconnect_status(bool status)
|
||||
{
|
||||
(void) status ;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <setjmp.h>
|
||||
#include <cmocka.h>
|
||||
#include <nopoll.h>
|
||||
@@ -116,6 +117,11 @@ int kill(pid_t pid, int sig)
|
||||
return (int) mock();
|
||||
}
|
||||
|
||||
bool get_interface_down_event()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Tests */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
Reference in New Issue
Block a user