More reorg, work in progress.

This commit is contained in:
Adam Ierymenko 2020-06-05 13:04:37 -07:00
parent d3cf7b2202
commit 3c11c13af4
No known key found for this signature in database
GPG key ID: C8877CF2D7A5D7F3
153 changed files with 255 additions and 2587 deletions

View file

@ -16,9 +16,9 @@
//#define ZT_CONTROLLER_USE_LIBPQ //#define ZT_CONTROLLER_USE_LIBPQ
#include "../node/Constants.hpp" #include "../core/Constants.hpp"
#include "../node/Identity.hpp" #include "../core/Identity.hpp"
#include "../node/InetAddress.hpp" #include "../core/InetAddress.hpp"
#include "../osdep/OSUtils.hpp" #include "../osdep/OSUtils.hpp"
#include "../osdep/BlockingQueue.hpp" #include "../osdep/BlockingQueue.hpp"

View file

@ -21,12 +21,12 @@
#include <thread> #include <thread>
#include <memory> #include <memory>
#include "../node/Constants.hpp" #include "../core/Constants.hpp"
#include "../node/Node.hpp" #include "../core/Node.hpp"
#include "../node/CertificateOfMembership.hpp" #include "../core/CertificateOfMembership.hpp"
#include "../node/NetworkConfig.hpp" #include "../core/NetworkConfig.hpp"
#include "../node/Dictionary.hpp" #include "../core/Dictionary.hpp"
#include "../node/MAC.hpp" #include "../core/MAC.hpp"
#include "EmbeddedNetworkController.hpp" #include "EmbeddedNetworkController.hpp"
#include "LFDB.hpp" #include "LFDB.hpp"

View file

@ -25,11 +25,11 @@
#include <unordered_map> #include <unordered_map>
#include <atomic> #include <atomic>
#include "../node/Constants.hpp" #include "../core/Constants.hpp"
#include "../node/NetworkController.hpp" #include "../core/NetworkController.hpp"
#include "../node/Utils.hpp" #include "../core/Utils.hpp"
#include "../node/Address.hpp" #include "../core/Address.hpp"
#include "../node/InetAddress.hpp" #include "../core/InetAddress.hpp"
#include "../osdep/OSUtils.hpp" #include "../osdep/OSUtils.hpp"
#include "../osdep/Thread.hpp" #include "../osdep/Thread.hpp"

View file

@ -15,7 +15,7 @@
#ifdef ZT_CONTROLLER_USE_LIBPQ #ifdef ZT_CONTROLLER_USE_LIBPQ
#include "../node/Constants.hpp" #include "../core/Constants.hpp"
#include "EmbeddedNetworkController.hpp" #include "EmbeddedNetworkController.hpp"
#include "RabbitMQ.hpp" #include "RabbitMQ.hpp"
#include "../version.h" #include "../version.h"

View file

@ -29,7 +29,7 @@ struct MQConfig {
#ifdef ZT_CONTROLLER_USE_LIBPQ #ifdef ZT_CONTROLLER_USE_LIBPQ
#include "../node/Mutex.hpp" #include "../core/Mutex.hpp"
#include <amqp.h> #include <amqp.h>
#include <amqp_tcp_socket.h> #include <amqp_tcp_socket.h>

View file

@ -14,7 +14,7 @@
#ifndef ZT_CONSTANTS_HPP #ifndef ZT_CONSTANTS_HPP
#define ZT_CONSTANTS_HPP #define ZT_CONSTANTS_HPP
#include "../include/ZeroTierCore.h" #include "ZeroTierCore.h"
#include "OS.hpp" #include "OS.hpp"
#if __has_include("version.h") #if __has_include("version.h")

View file

@ -1,154 +1,154 @@
/* /*
* Copyright (c)2013-2020 ZeroTier, Inc. * Copyright (c)2013-2020 ZeroTier, Inc.
* *
* Use of this software is governed by the Business Source License included * Use of this software is governed by the Business Source License included
* in the LICENSE.TXT file in the project's root directory. * in the LICENSE.TXT file in the project's root directory.
* *
* Change Date: 2024-01-01 * Change Date: 2024-01-01
* *
* On the date above, in accordance with the Business Source License, use * On the date above, in accordance with the Business Source License, use
* of this software will be governed by version 2.0 of the Apache License. * of this software will be governed by version 2.0 of the Apache License.
*/ */
/****/ /****/
#ifndef ZT_MUTEX_HPP #ifndef ZT_MUTEX_HPP
#define ZT_MUTEX_HPP #define ZT_MUTEX_HPP
#include "Constants.hpp" #include "Constants.hpp"
#include <cstdint> #include <cstdint>
#include <cstdlib> #include <cstdlib>
#ifndef __WINDOWS__ #ifndef __WINDOWS__
#include <pthread.h> #include <pthread.h>
#endif #endif
namespace ZeroTier { namespace ZeroTier {
class Mutex class Mutex
{ {
public: public:
ZT_INLINE Mutex() noexcept { pthread_mutex_init(&_mh,nullptr); } // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init) ZT_INLINE Mutex() noexcept { pthread_mutex_init(&_mh,nullptr); } // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
ZT_INLINE ~Mutex() noexcept { pthread_mutex_destroy(&_mh); } ZT_INLINE ~Mutex() noexcept { pthread_mutex_destroy(&_mh); }
ZT_INLINE void lock() const noexcept { pthread_mutex_lock(&((const_cast <Mutex *> (this))->_mh)); } ZT_INLINE void lock() const noexcept { pthread_mutex_lock(&((const_cast <Mutex *> (this))->_mh)); }
ZT_INLINE void unlock() const noexcept { pthread_mutex_unlock(&((const_cast <Mutex *> (this))->_mh)); } ZT_INLINE void unlock() const noexcept { pthread_mutex_unlock(&((const_cast <Mutex *> (this))->_mh)); }
class Lock class Lock
{ {
public: public:
explicit ZT_INLINE Lock(Mutex &m) noexcept : _m(&m) { m.lock(); } // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init) explicit ZT_INLINE Lock(Mutex &m) noexcept : _m(&m) { m.lock(); } // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
explicit ZT_INLINE Lock(const Mutex &m) noexcept : _m(const_cast<Mutex *>(&m)) { _m->lock(); } // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init) explicit ZT_INLINE Lock(const Mutex &m) noexcept : _m(const_cast<Mutex *>(&m)) { _m->lock(); } // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
ZT_INLINE ~Lock() { _m->unlock(); } ZT_INLINE ~Lock() { _m->unlock(); }
private: private:
Mutex *const _m; Mutex *const _m;
}; };
private: private:
ZT_INLINE Mutex(const Mutex &) noexcept {} // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init) ZT_INLINE Mutex(const Mutex &) noexcept {} // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
ZT_INLINE const Mutex &operator=(const Mutex &) noexcept { return *this; } ZT_INLINE const Mutex &operator=(const Mutex &) noexcept { return *this; }
pthread_mutex_t _mh; pthread_mutex_t _mh;
}; };
class RWMutex class RWMutex
{ {
public: public:
ZT_INLINE RWMutex() noexcept { pthread_rwlock_init(&_mh,nullptr); } // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init) ZT_INLINE RWMutex() noexcept { pthread_rwlock_init(&_mh,nullptr); } // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
ZT_INLINE ~RWMutex() noexcept { pthread_rwlock_destroy(&_mh); } ZT_INLINE ~RWMutex() noexcept { pthread_rwlock_destroy(&_mh); }
ZT_INLINE void lock() const noexcept { pthread_rwlock_wrlock(&((const_cast <RWMutex *> (this))->_mh)); } ZT_INLINE void lock() const noexcept { pthread_rwlock_wrlock(&((const_cast <RWMutex *> (this))->_mh)); }
ZT_INLINE void rlock() const noexcept { pthread_rwlock_rdlock(&((const_cast <RWMutex *> (this))->_mh)); } ZT_INLINE void rlock() const noexcept { pthread_rwlock_rdlock(&((const_cast <RWMutex *> (this))->_mh)); }
ZT_INLINE void unlock() const noexcept { pthread_rwlock_unlock(&((const_cast <RWMutex *> (this))->_mh)); } ZT_INLINE void unlock() const noexcept { pthread_rwlock_unlock(&((const_cast <RWMutex *> (this))->_mh)); }
ZT_INLINE void runlock() const noexcept { pthread_rwlock_unlock(&((const_cast <RWMutex *> (this))->_mh)); } ZT_INLINE void runlock() const noexcept { pthread_rwlock_unlock(&((const_cast <RWMutex *> (this))->_mh)); }
/** /**
* RAAI locker that acquires only the read lock (shared read) * RAAI locker that acquires only the read lock (shared read)
*/ */
class RLock class RLock
{ {
public: public:
explicit ZT_INLINE RLock(RWMutex &m) noexcept : _m(&m) { m.rlock(); } // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init) explicit ZT_INLINE RLock(RWMutex &m) noexcept : _m(&m) { m.rlock(); } // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
explicit ZT_INLINE RLock(const RWMutex &m) noexcept : _m(const_cast<RWMutex *>(&m)) { _m->rlock(); } // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init) explicit ZT_INLINE RLock(const RWMutex &m) noexcept : _m(const_cast<RWMutex *>(&m)) { _m->rlock(); } // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
ZT_INLINE ~RLock() { _m->runlock(); } ZT_INLINE ~RLock() { _m->runlock(); }
private: private:
RWMutex *const _m; RWMutex *const _m;
}; };
/** /**
* RAAI locker that acquires the write lock (exclusive write, no readers) * RAAI locker that acquires the write lock (exclusive write, no readers)
*/ */
class Lock class Lock
{ {
public: public:
explicit ZT_INLINE Lock(RWMutex &m) noexcept : _m(&m) { m.lock(); } // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init) explicit ZT_INLINE Lock(RWMutex &m) noexcept : _m(&m) { m.lock(); } // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
explicit ZT_INLINE Lock(const RWMutex &m) noexcept : _m(const_cast<RWMutex *>(&m)) { _m->lock(); } // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init) explicit ZT_INLINE Lock(const RWMutex &m) noexcept : _m(const_cast<RWMutex *>(&m)) { _m->lock(); } // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
ZT_INLINE ~Lock() { _m->unlock(); } ZT_INLINE ~Lock() { _m->unlock(); }
private: private:
RWMutex *const _m; RWMutex *const _m;
}; };
/** /**
* RAAI locker that acquires the read lock first and can switch modes * RAAI locker that acquires the read lock first and can switch modes
* *
* Use writing() to acquire the write lock if not already acquired. Use reading() to * Use writing() to acquire the write lock if not already acquired. Use reading() to
* let go of the write lock and go back to only holding the read lock. * let go of the write lock and go back to only holding the read lock.
*/ */
class RMaybeWLock class RMaybeWLock
{ {
public: public:
explicit ZT_INLINE RMaybeWLock(RWMutex &m) noexcept : _m(&m),_w(false) { m.rlock(); } // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init) explicit ZT_INLINE RMaybeWLock(RWMutex &m) noexcept : _m(&m),_w(false) { m.rlock(); } // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
explicit ZT_INLINE RMaybeWLock(const RWMutex &m) noexcept : _m(const_cast<RWMutex *>(&m)),_w(false) { _m->rlock(); } // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init) explicit ZT_INLINE RMaybeWLock(const RWMutex &m) noexcept : _m(const_cast<RWMutex *>(&m)),_w(false) { _m->rlock(); } // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
ZT_INLINE void writing() noexcept { if (!_w) { _w = true; _m->runlock(); _m->lock(); } } ZT_INLINE void writing() noexcept { if (!_w) { _w = true; _m->runlock(); _m->lock(); } }
ZT_INLINE void reading() noexcept { if (_w) { _w = false; _m->unlock(); _m->rlock(); } } ZT_INLINE void reading() noexcept { if (_w) { _w = false; _m->unlock(); _m->rlock(); } }
ZT_INLINE ~RMaybeWLock() { if (_w) _m->unlock(); else _m->runlock(); } ZT_INLINE ~RMaybeWLock() { if (_w) _m->unlock(); else _m->runlock(); }
private: private:
RWMutex *const _m; RWMutex *const _m;
bool _w; bool _w;
}; };
private: private:
ZT_INLINE RWMutex(const RWMutex &) noexcept {} // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init) ZT_INLINE RWMutex(const RWMutex &) noexcept {} // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
ZT_INLINE const RWMutex &operator=(const RWMutex &) noexcept { return *this; } ZT_INLINE const RWMutex &operator=(const RWMutex &) noexcept { return *this; }
pthread_rwlock_t _mh; pthread_rwlock_t _mh;
}; };
} // namespace ZeroTier } // namespace ZeroTier
#if 0 #if 0
#include <Windows.h> #include <Windows.h>
namespace ZeroTier { namespace ZeroTier {
class Mutex class Mutex
{ {
public: public:
ZT_INLINE Mutex() { InitializeCriticalSection(&_cs); } ZT_INLINE Mutex() { InitializeCriticalSection(&_cs); }
ZT_INLINE ~Mutex() { DeleteCriticalSection(&_cs); } ZT_INLINE ~Mutex() { DeleteCriticalSection(&_cs); }
ZT_INLINE void lock() { EnterCriticalSection(&_cs); } ZT_INLINE void lock() { EnterCriticalSection(&_cs); }
ZT_INLINE void unlock() { LeaveCriticalSection(&_cs); } ZT_INLINE void unlock() { LeaveCriticalSection(&_cs); }
ZT_INLINE void lock() const { (const_cast <Mutex *> (this))->lock(); } ZT_INLINE void lock() const { (const_cast <Mutex *> (this))->lock(); }
ZT_INLINE void unlock() const { (const_cast <Mutex *> (this))->unlock(); } ZT_INLINE void unlock() const { (const_cast <Mutex *> (this))->unlock(); }
class Lock class Lock
{ {
public: public:
ZT_INLINE Lock(Mutex &m) : _m(&m) { m.lock(); } ZT_INLINE Lock(Mutex &m) : _m(&m) { m.lock(); }
ZT_INLINE Lock(const Mutex &m) : _m(const_cast<Mutex *>(&m)) { _m->lock(); } ZT_INLINE Lock(const Mutex &m) : _m(const_cast<Mutex *>(&m)) { _m->lock(); }
ZT_INLINE ~Lock() { _m->unlock(); } ZT_INLINE ~Lock() { _m->unlock(); }
private: private:
Mutex *const _m; Mutex *const _m;
}; };
private: private:
ZT_INLINE Mutex(const Mutex &) {} ZT_INLINE Mutex(const Mutex &) {}
ZT_INLINE const Mutex &operator=(const Mutex &) { return *this; } ZT_INLINE const Mutex &operator=(const Mutex &) { return *this; }
CRITICAL_SECTION _cs; CRITICAL_SECTION _cs;
}; };
} // namespace ZeroTier } // namespace ZeroTier
#endif #endif
#endif #endif

Some files were not shown because too many files have changed in this diff Show more