mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-06 20:43:44 +02:00
More small stuff.
This commit is contained in:
parent
a19bc1e826
commit
866a20e85b
4 changed files with 44 additions and 30 deletions
|
@ -248,9 +248,7 @@ public:
|
|||
* @param md Event data or NULL if none
|
||||
*/
|
||||
ZT_INLINE void postEvent(void *tPtr, ZT_Event ev, const void *md = nullptr) noexcept
|
||||
{
|
||||
m_cb.eventCallback(reinterpret_cast<ZT_Node *>(this), m_uPtr, tPtr, ev, md);
|
||||
}
|
||||
{ m_cb.eventCallback(reinterpret_cast<ZT_Node *>(this), m_uPtr, tPtr, ev, md); }
|
||||
|
||||
/**
|
||||
* Post network port configuration via external callback
|
||||
|
@ -262,9 +260,7 @@ public:
|
|||
* @param nc Network config info
|
||||
*/
|
||||
ZT_INLINE void configureVirtualNetworkPort(void *tPtr, uint64_t nwid, void **nuptr, ZT_VirtualNetworkConfigOperation op, const ZT_VirtualNetworkConfig *nc) noexcept
|
||||
{
|
||||
m_cb.virtualNetworkConfigFunction(reinterpret_cast<ZT_Node *>(this), m_uPtr, tPtr, nwid, nuptr, op, nc);
|
||||
}
|
||||
{ m_cb.virtualNetworkConfigFunction(reinterpret_cast<ZT_Node *>(this), m_uPtr, tPtr, nwid, nuptr, op, nc); }
|
||||
|
||||
/**
|
||||
* @return True if node appears online
|
||||
|
|
|
@ -24,16 +24,24 @@ namespace ZeroTier {
|
|||
*
|
||||
* This is used in the core to avoid requiring C++11 and because auto_ptr is weird.
|
||||
*/
|
||||
template<typename T>
|
||||
template< typename T >
|
||||
class ScopedPtr : public TriviallyCopyable
|
||||
{
|
||||
public:
|
||||
explicit ZT_INLINE ScopedPtr(T *const p) noexcept : m_ptr(p) {}
|
||||
ZT_INLINE ~ScopedPtr() { delete m_ptr; }
|
||||
explicit ZT_INLINE ScopedPtr(T *const p) noexcept: m_ptr(p)
|
||||
{}
|
||||
|
||||
ZT_INLINE T *operator->() const noexcept { return m_ptr; }
|
||||
ZT_INLINE T &operator*() const noexcept { return *m_ptr; }
|
||||
ZT_INLINE T *ptr() const noexcept { return m_ptr; }
|
||||
ZT_INLINE ~ScopedPtr()
|
||||
{ delete m_ptr; }
|
||||
|
||||
ZT_INLINE T *operator->() const noexcept
|
||||
{ return m_ptr; }
|
||||
|
||||
ZT_INLINE T &operator*() const noexcept
|
||||
{ return *m_ptr; }
|
||||
|
||||
ZT_INLINE T *ptr() const noexcept
|
||||
{ return m_ptr; }
|
||||
|
||||
ZT_INLINE void swap(const ScopedPtr &p) noexcept
|
||||
{
|
||||
|
@ -42,17 +50,30 @@ public:
|
|||
p.m_ptr = tmp;
|
||||
}
|
||||
|
||||
explicit ZT_INLINE operator bool() const noexcept { return (m_ptr != (T *)0); }
|
||||
explicit ZT_INLINE operator bool() const noexcept
|
||||
{ return (m_ptr != (T *)0); }
|
||||
|
||||
ZT_INLINE bool operator==(const ScopedPtr &p) const noexcept { return (m_ptr == p.m_ptr); }
|
||||
ZT_INLINE bool operator!=(const ScopedPtr &p) const noexcept { return (m_ptr != p.m_ptr); }
|
||||
ZT_INLINE bool operator==(T *const p) const noexcept { return (m_ptr == p); }
|
||||
ZT_INLINE bool operator!=(T *const p) const noexcept { return (m_ptr != p); }
|
||||
ZT_INLINE bool operator==(const ScopedPtr &p) const noexcept
|
||||
{ return (m_ptr == p.m_ptr); }
|
||||
|
||||
ZT_INLINE bool operator!=(const ScopedPtr &p) const noexcept
|
||||
{ return (m_ptr != p.m_ptr); }
|
||||
|
||||
ZT_INLINE bool operator==(T *const p) const noexcept
|
||||
{ return (m_ptr == p); }
|
||||
|
||||
ZT_INLINE bool operator!=(T *const p) const noexcept
|
||||
{ return (m_ptr != p); }
|
||||
|
||||
private:
|
||||
ZT_INLINE ScopedPtr() noexcept {}
|
||||
ZT_INLINE ScopedPtr(const ScopedPtr &p) noexcept : m_ptr(nullptr) {}
|
||||
ZT_INLINE ScopedPtr &operator=(const ScopedPtr &p) noexcept { return *this; }
|
||||
ZT_INLINE ScopedPtr() noexcept
|
||||
{}
|
||||
|
||||
ZT_INLINE ScopedPtr(const ScopedPtr &p) noexcept: m_ptr(nullptr)
|
||||
{}
|
||||
|
||||
ZT_INLINE ScopedPtr &operator=(const ScopedPtr &p) noexcept
|
||||
{ return *this; }
|
||||
|
||||
T *const m_ptr;
|
||||
};
|
||||
|
@ -60,8 +81,9 @@ private:
|
|||
} // namespace ZeroTier
|
||||
|
||||
namespace std {
|
||||
template<typename T>
|
||||
ZT_INLINE void swap(ZeroTier::ScopedPtr<T> &a,ZeroTier::ScopedPtr<T> &b) noexcept { a.swap(b); }
|
||||
template< typename T >
|
||||
ZT_INLINE void swap(ZeroTier::ScopedPtr< T > &a, ZeroTier::ScopedPtr< T > &b) noexcept
|
||||
{ a.swap(b); }
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -108,13 +108,13 @@ private:
|
|||
struct p_PhySurfaceEntry
|
||||
{
|
||||
InetAddress mySurface;
|
||||
uint64_t ts;
|
||||
int64_t ts;
|
||||
bool trusted;
|
||||
|
||||
ZT_INLINE p_PhySurfaceEntry() noexcept: mySurface(), ts(0), trusted(false)
|
||||
{}
|
||||
|
||||
ZT_INLINE p_PhySurfaceEntry(const InetAddress &a, const uint64_t t) noexcept: mySurface(a), ts(t), trusted(false)
|
||||
ZT_INLINE p_PhySurfaceEntry(const InetAddress &a, const int64_t t) noexcept: mySurface(a), ts(t), trusted(false)
|
||||
{}
|
||||
};
|
||||
|
||||
|
|
|
@ -86,17 +86,13 @@ public:
|
|||
* @return Next unique IV for next message
|
||||
*/
|
||||
ZT_INLINE uint64_t nextMessage(const Address sender, const Address receiver) noexcept
|
||||
{
|
||||
return m_nonce.fetch_add(1) ^ (((uint64_t)(sender > receiver)) << 63U);
|
||||
}
|
||||
{ return m_nonce.fetch_add(1) ^ (((uint64_t)(sender > receiver)) << 63U); }
|
||||
|
||||
/**
|
||||
* @return Number of times nextMessage() has been called since object creation
|
||||
*/
|
||||
ZT_INLINE uint64_t odometer() const noexcept
|
||||
{
|
||||
return m_nonce.load() - m_initialNonce;
|
||||
}
|
||||
{ return m_nonce.load() - m_initialNonce; }
|
||||
|
||||
private:
|
||||
const uint64_t m_initialNonce;
|
||||
|
|
Loading…
Add table
Reference in a new issue