Added exception handling for virtual socket add/del functions
This commit is contained in:
@@ -105,9 +105,19 @@ struct zts_ifreq {
|
||||
// For LWIP configuration see: include/lwipopts.h
|
||||
|
||||
#if defined(STACK_LWIP)
|
||||
/*
|
||||
Specifies the polling interval and the callback function that should
|
||||
be called to poll the application. The interval is specified in
|
||||
number of TCP coarse grained timer shots, which typically occurs
|
||||
twice a second. An interval of 10 means that the application would
|
||||
be polled every 5 seconds. */
|
||||
#define LWIP_APPLICATION_POLL_FREQ 2
|
||||
#define LWIP_TCP_TIMER_INTERVAL 50
|
||||
#define LWIP_STATUS_TMR_INTERVAL 500 // How often we check VirtualSocket statuses (in ms)
|
||||
|
||||
#define LWIP_TCP_TIMER_INTERVAL 25
|
||||
|
||||
// How often we check VirtualSocket statuses (in ms)
|
||||
#define LWIP_STATUS_TMR_INTERVAL 500
|
||||
|
||||
// #define LWIP_CHKSUM <your_checksum_routine>, See: RFC1071 for inspiration
|
||||
#endif
|
||||
|
||||
@@ -591,26 +601,26 @@ ZeroTier::VirtualSocket *get_virtual_socket(int fd);
|
||||
/*
|
||||
* Removes a VirtualSocket
|
||||
*/
|
||||
void del_virtual_socket(int fd);
|
||||
int del_virtual_socket(int fd);
|
||||
|
||||
/*
|
||||
* Adds a virtualSocket
|
||||
*/
|
||||
void add_unassigned_virtual_socket(int fd, ZeroTier::VirtualSocket *vs);
|
||||
int add_unassigned_virtual_socket(int fd, ZeroTier::VirtualSocket *vs);
|
||||
/*
|
||||
* Removes unassigned VirtualSocket
|
||||
*/
|
||||
void del_unassigned_virtual_socket(int fd);
|
||||
int del_unassigned_virtual_socket(int fd);
|
||||
|
||||
/*
|
||||
* Adds an assigned VirtualSocket
|
||||
*/
|
||||
void add_assigned_virtual_socket(ZeroTier::VirtualTap *tap, ZeroTier::VirtualSocket *vs, int fd);
|
||||
int add_assigned_virtual_socket(ZeroTier::VirtualTap *tap, ZeroTier::VirtualSocket *vs, int fd);
|
||||
|
||||
/*
|
||||
* Removes an assigned VirtualSocket
|
||||
*/
|
||||
void del_assigned_virtual_socket(ZeroTier::VirtualTap *tap, ZeroTier::VirtualSocket *vs, int fd);
|
||||
int del_assigned_virtual_socket(ZeroTier::VirtualTap *tap, ZeroTier::VirtualSocket *vs, int fd);
|
||||
|
||||
/*
|
||||
* Gets a pair of associated virtual objects (VirtualSocket bound to a VirtualTap)
|
||||
|
||||
@@ -140,7 +140,16 @@ void zts_simple_start(const char *path, const char *nwid)
|
||||
while(!zts_running()) {
|
||||
nanosleep((const struct timespec[]){{0, (ZT_API_CHECK_INTERVAL * 1000000)}}, NULL);
|
||||
}
|
||||
while(1) {
|
||||
try {
|
||||
zts_join(nwid);
|
||||
break;
|
||||
}
|
||||
catch( ... ) {
|
||||
DEBUG_ERROR("there was a problem joining the virtual network");
|
||||
handle_general_failure();
|
||||
}
|
||||
}
|
||||
while(!zts_has_address(nwid)) {
|
||||
nanosleep((const struct timespec[]){{0, (ZT_API_CHECK_INTERVAL * 1000000)}}, NULL);
|
||||
}
|
||||
@@ -2153,9 +2162,11 @@ ZeroTier::VirtualSocket *get_virtual_socket(int fd)
|
||||
return vs;
|
||||
}
|
||||
|
||||
void del_virtual_socket(int fd)
|
||||
int del_virtual_socket(int fd)
|
||||
{
|
||||
int err = 0;
|
||||
ZeroTier::_multiplexer_lock.lock();
|
||||
try {
|
||||
std::map<int, ZeroTier::VirtualSocket*>::iterator un_iter = ZeroTier::unmap.find(fd);
|
||||
if(un_iter != ZeroTier::unmap.end()) {
|
||||
ZeroTier::unmap.erase(un_iter);
|
||||
@@ -2164,12 +2175,21 @@ void del_virtual_socket(int fd)
|
||||
if(fd_iter != ZeroTier::fdmap.end()) {
|
||||
ZeroTier::fdmap.erase(fd_iter);
|
||||
}
|
||||
}
|
||||
catch( ... ) {
|
||||
DEBUG_ERROR("unable to remove virtual socket");
|
||||
handle_general_failure();
|
||||
err = -1;
|
||||
}
|
||||
ZeroTier::_multiplexer_lock.unlock();
|
||||
return err;
|
||||
}
|
||||
|
||||
void add_unassigned_virtual_socket(int fd, ZeroTier::VirtualSocket *vs)
|
||||
int add_unassigned_virtual_socket(int fd, ZeroTier::VirtualSocket *vs)
|
||||
{
|
||||
int err = 0;
|
||||
ZeroTier::_multiplexer_lock.lock();
|
||||
try {
|
||||
std::map<int, ZeroTier::VirtualSocket*>::iterator un_iter = ZeroTier::unmap.find(fd);
|
||||
if(un_iter == ZeroTier::unmap.end()) {
|
||||
ZeroTier::unmap[fd] = vs;
|
||||
@@ -2178,22 +2198,40 @@ void add_unassigned_virtual_socket(int fd, ZeroTier::VirtualSocket *vs)
|
||||
DEBUG_ERROR("fd=%d already contained in <fd:vs> map", fd);
|
||||
handle_general_failure();
|
||||
}
|
||||
}
|
||||
catch( ... ) {
|
||||
DEBUG_ERROR("unable to add virtual socket");
|
||||
handle_general_failure();
|
||||
err = -1;
|
||||
}
|
||||
ZeroTier::_multiplexer_lock.unlock();
|
||||
return err;
|
||||
}
|
||||
|
||||
void del_unassigned_virtual_socket(int fd)
|
||||
int del_unassigned_virtual_socket(int fd)
|
||||
{
|
||||
int err = 0;
|
||||
ZeroTier::_multiplexer_lock.lock();
|
||||
try {
|
||||
std::map<int, ZeroTier::VirtualSocket*>::iterator un_iter = ZeroTier::unmap.find(fd);
|
||||
if(un_iter != ZeroTier::unmap.end()) {
|
||||
ZeroTier::unmap.erase(un_iter);
|
||||
}
|
||||
}
|
||||
catch( ... ) {
|
||||
DEBUG_ERROR("unable to remove virtual socket");
|
||||
handle_general_failure();
|
||||
err = -1;
|
||||
}
|
||||
ZeroTier::_multiplexer_lock.unlock();
|
||||
return err;
|
||||
}
|
||||
|
||||
void add_assigned_virtual_socket(ZeroTier::VirtualTap *tap, ZeroTier::VirtualSocket *vs, int fd)
|
||||
int add_assigned_virtual_socket(ZeroTier::VirtualTap *tap, ZeroTier::VirtualSocket *vs, int fd)
|
||||
{
|
||||
int err = 0;
|
||||
ZeroTier::_multiplexer_lock.lock();
|
||||
try {
|
||||
std::map<int, std::pair<ZeroTier::VirtualSocket*,ZeroTier::VirtualTap*>*>::iterator fd_iter = ZeroTier::fdmap.find(fd);
|
||||
if(fd_iter == ZeroTier::fdmap.end()) {
|
||||
ZeroTier::fdmap[fd] = new std::pair<ZeroTier::VirtualSocket*,ZeroTier::VirtualTap*>(vs, tap);
|
||||
@@ -2202,17 +2240,33 @@ void add_assigned_virtual_socket(ZeroTier::VirtualTap *tap, ZeroTier::VirtualSoc
|
||||
DEBUG_ERROR("fd=%d already contained in <fd,<vs,vt>> map", fd);
|
||||
handle_general_failure();
|
||||
}
|
||||
}
|
||||
catch( ... ) {
|
||||
DEBUG_ERROR("unable to add virtual socket");
|
||||
handle_general_failure();
|
||||
err = -1;
|
||||
}
|
||||
ZeroTier::_multiplexer_lock.unlock();
|
||||
return err;
|
||||
}
|
||||
|
||||
void del_assigned_virtual_socket(ZeroTier::VirtualTap *tap, ZeroTier::VirtualSocket *vs, int fd)
|
||||
int del_assigned_virtual_socket(ZeroTier::VirtualTap *tap, ZeroTier::VirtualSocket *vs, int fd)
|
||||
{
|
||||
int err = 0;
|
||||
ZeroTier::_multiplexer_lock.lock();
|
||||
try {
|
||||
std::map<int, std::pair<ZeroTier::VirtualSocket*,ZeroTier::VirtualTap*>*>::iterator fd_iter = ZeroTier::fdmap.find(fd);
|
||||
if(fd_iter != ZeroTier::fdmap.end()) {
|
||||
ZeroTier::fdmap.erase(fd_iter);
|
||||
}
|
||||
}
|
||||
catch( ... ) {
|
||||
DEBUG_ERROR("unable to remove virtual socket");
|
||||
handle_general_failure();
|
||||
err = -1;
|
||||
}
|
||||
ZeroTier::_multiplexer_lock.unlock();
|
||||
return err;
|
||||
}
|
||||
|
||||
std::pair<ZeroTier::VirtualSocket*, ZeroTier::VirtualTap*> *get_assigned_virtual_pair(int fd)
|
||||
|
||||
Reference in New Issue
Block a user