Updated tests

This commit is contained in:
Joseph Henry
2017-05-30 13:17:39 -07:00
parent 673d1b9a09
commit 5ab563ce4c
13 changed files with 321 additions and 121 deletions

View File

@@ -198,6 +198,13 @@ namespace ZeroTier {
_multicastGroups.swap(newGroups);
}
void SocketTap::setMtu(unsigned int mtu)
{
if (_mtu != mtu) {
_mtu = mtu;
}
}
void SocketTap::threadMain()
throw()
{

View File

@@ -118,6 +118,11 @@ namespace ZeroTier {
*/
void scanMulticastGroups(std::vector<MulticastGroup> &added,std::vector<MulticastGroup> &removed);
/*
*
*/
void setMtu(unsigned int mtu);
/*
*
*/

View File

@@ -101,6 +101,16 @@ void zts_start(const char *path)
pthread_create(&service_thread, NULL, zts_start_service, (void *)(path));
}
void zts_simple_start(const char *path, const char *nwid)
{
zts_start(path);
while(!zts_running())
usleep(ZT_API_CHECK_INTERVAL * 1000);
zts_join(nwid);
while(!zts_has_address(nwid))
usleep(ZT_API_CHECK_INTERVAL * 1000);
}
void zts_stop() {
if(zt1Service) {
zt1Service->terminate();
@@ -337,7 +347,7 @@ int zts_socket(ZT_SOCKET_SIG) {
else {
ZeroTier::_multiplexer_lock.lock();
//DEBUG_INFO("unmap=%d, fdmap=%d", ZeroTier::unmap.size(), ZeroTier::fdmap.size());
DEBUG_INFO("timers = %d, max = %d", pico_ntimers(), PICO_MAX_TIMERS);
//DEBUG_INFO("timers = %d, max = %d", pico_ntimers(), PICO_MAX_TIMERS);
if(pico_ntimers() >= PICO_MAX_TIMERS) {
DEBUG_ERROR("cannot provision additional socket due to limitation of PICO_MAX_TIMERS. current = %d", pico_ntimers());
errno = EMFILE;
@@ -413,7 +423,7 @@ Darwin:
[ ] [ECONNRESET] Remote host reset the connection request.
*/
int zts_connect(ZT_CONNECT_SIG) {
DEBUG_INFO("fd = %d", fd);
//DEBUG_INFO("fd = %d", fd);
int err = 0;
if(fd < 0) {
errno = EBADF;
@@ -490,7 +500,6 @@ int zts_connect(ZT_CONNECT_SIG) {
// non-blocking
if(err == 0 && !blocking) {
DEBUG_INFO("NONBLOCKING!");
errno = EINPROGRESS;
err = -1;
}
@@ -498,7 +507,6 @@ int zts_connect(ZT_CONNECT_SIG) {
{
// FIXME: Double check that accept/connect queues in multithreaded apps don't get mixed up
if(err == 0 && blocking) {
DEBUG_INFO("BLOCKING!");
bool complete = false;
while(true)
{
@@ -627,7 +635,7 @@ int zts_listen(ZT_LISTEN_SIG) {
ZeroTier::_multiplexer_lock.lock();
std::pair<ZeroTier::Connection*, ZeroTier::SocketTap*> *p = ZeroTier::fdmap[fd];
if(!p) {
DEBUG_ERROR("unable to locate connection pair (did you zbind()?");
DEBUG_ERROR("unable to locate connection pair. did you bind?");
return -1;
}
ZeroTier::Connection *conn = p->first;
@@ -752,7 +760,7 @@ EPERM Firewall rules forbid connection.
*/
int zts_setsockopt(ZT_SETSOCKOPT_SIG)
{
DEBUG_INFO("fd = %d", fd);
//DEBUG_INFO("fd = %d", fd);
int err = 0;
if(fd < 0) {
errno = EBADF;
@@ -776,7 +784,7 @@ int zts_setsockopt(ZT_SETSOCKOPT_SIG)
*/
int zts_getsockopt(ZT_GETSOCKOPT_SIG)
{
DEBUG_INFO("fd = %d", fd);
//DEBUG_INFO("fd = %d", fd);
int err = 0;
if(fd < 0) {
errno = EBADF;
@@ -919,7 +927,7 @@ int zts_close(ZT_CLOSE_SIG)
int zts_fcntl(ZT_FCNTL_SIG)
{
DEBUG_INFO("fd = %d", fd);
//DEBUG_INFO("fd = %d", fd);
int err;
if(fd < 0) {
errno = EBADF;
@@ -1242,7 +1250,7 @@ namespace ZeroTier {
#endif
/****************************************************************************/
/* SDK Socket API Helper functions --- DONT CALL THESE DIRECTLY */
/* SDK Socket API Helper functions --- DON'T CALL THESE DIRECTLY */
/****************************************************************************/
int zts_nsockets()
@@ -1253,6 +1261,12 @@ int zts_nsockets()
return num;
}
int zts_maxsockets()
{
// TODO: This is only an approximation
return PICO_MAX_TIMERS - 10;
}
// Starts a ZeroTier service in the background
void *zts_start_service(void *thread_id) {

View File

@@ -353,7 +353,7 @@ namespace ZeroTier {
int pico_eth_send(struct pico_device *dev, void *buf, int len)
{
DEBUG_INFO();
//DEBUG_INFO();
SocketTap *tap = (SocketTap*)(dev->tap);
if(!tap) {
DEBUG_ERROR("invalid dev->tap");
@@ -367,7 +367,7 @@ namespace ZeroTier {
dest_mac.setTo(ethhdr->daddr, 6);
tap->_handler(tap->_arg,NULL,tap->_nwid,src_mac,dest_mac,
Utils::ntoh((uint16_t)ethhdr->proto),0, ((char*)buf) + sizeof(struct pico_eth_hdr),len - sizeof(struct pico_eth_hdr));
DEBUG_INFO("len = %d", len);
//DEBUG_INFO("len = %d", len);
return len;
}
@@ -453,9 +453,9 @@ namespace ZeroTier {
char ipv4_str[INET_ADDRSTRLEN];
inet_ntop(AF_INET, (const void *)&in4->sin_addr.s_addr, ipv4_str, INET_ADDRSTRLEN);
pico_string_to_ipv4(ipv4_str, &(zaddr.addr));
DEBUG_ATTN("addr=%s:%d", ipv4_str, Utils::ntoh( in4->sin_port ));
//DEBUG_ATTN("addr=%s:%d", ipv4_str, Utils::ntoh( in4->sin_port ));
err = pico_socket_connect(conn->picosock, &zaddr, in4->sin_port);
DEBUG_INFO("connect_err = %d", err);
//DEBUG_INFO("connect_err = %d", err);
#elif defined(SDK_IPV6)
struct pico_ip6 zaddr;
@@ -463,7 +463,7 @@ namespace ZeroTier {
char ipv6_str[INET6_ADDRSTRLEN];
inet_ntop(AF_INET6, &(in6->sin6_addr), ipv6_str, INET6_ADDRSTRLEN);
pico_string_to_ipv6(ipv6_str, zaddr.addr);
DEBUG_ATTN("addr=%s:%d", ipv6_str, Utils::ntoh(in6->sin6_port));
//DEBUG_ATTN("addr=%s:%d", ipv6_str, Utils::ntoh(in6->sin6_port));
err = pico_socket_connect(conn->picosock, &zaddr, in6->sin6_port);
#endif
@@ -687,7 +687,7 @@ namespace ZeroTier {
int picoTCP::pico_Close(Connection *conn)
{
DEBUG_INFO();
//DEBUG_INFO();
if(!conn || !conn->picosock)
return ZT_ERR_GENERAL_FAILURE;
int err;