summaryrefslogtreecommitdiff
path: root/testnet
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2014-10-29 13:57:37 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2014-10-29 13:57:37 -0700
commit95f421024a3b3c94a71c5328e23bf5456e7f14ba (patch)
treeb5d908204e87944823a436eaec000b75be609717 /testnet
parentf65b48d447e414e3cdc1e6787cf92a795a11956b (diff)
downloadinfinitytier-95f421024a3b3c94a71c5328e23bf5456e7f14ba.tar.gz
infinitytier-95f421024a3b3c94a71c5328e23bf5456e7f14ba.zip
Code cleanup, and fix some unsafe pointer handling in Network.
Diffstat (limited to 'testnet')
-rw-r--r--testnet/TestEthernetTap.cpp2
-rw-r--r--testnet/TestEthernetTap.hpp8
-rw-r--r--testnet/TestEthernetTapFactory.cpp39
-rw-r--r--testnet/TestEthernetTapFactory.hpp23
4 files changed, 28 insertions, 44 deletions
diff --git a/testnet/TestEthernetTap.cpp b/testnet/TestEthernetTap.cpp
index afd26da6..f4b5f014 100644
--- a/testnet/TestEthernetTap.cpp
+++ b/testnet/TestEthernetTap.cpp
@@ -43,7 +43,6 @@
namespace ZeroTier {
TestEthernetTap::TestEthernetTap(
- TestEthernetTapFactory *parent,
const MAC &mac,
unsigned int mtu,
unsigned int metric,
@@ -54,7 +53,6 @@ TestEthernetTap::TestEthernetTap(
void *arg) :
EthernetTap("TestEthernetTap",mac,mtu,metric),
_nwid(nwid),
- _parent(parent),
_handler(handler),
_arg(arg),
_enabled(true)
diff --git a/testnet/TestEthernetTap.hpp b/testnet/TestEthernetTap.hpp
index cfe8807c..745baf5d 100644
--- a/testnet/TestEthernetTap.hpp
+++ b/testnet/TestEthernetTap.hpp
@@ -36,8 +36,6 @@
#include "../node/Constants.hpp"
#include "../node/EthernetTap.hpp"
-#include "../node/AtomicCounter.hpp"
-#include "../node/SharedPtr.hpp"
#include "../node/Thread.hpp"
#include "../node/Mutex.hpp"
@@ -57,8 +55,6 @@ class TestEthernetTapFactory;
*/
class TestEthernetTap : public EthernetTap
{
- friend class SharedPtr<TestEthernetTap>;
-
public:
struct TestFrame
{
@@ -82,7 +78,6 @@ public:
};
TestEthernetTap(
- TestEthernetTapFactory *parent,
const MAC &mac,
unsigned int mtu,
unsigned int metric,
@@ -113,7 +108,6 @@ public:
private:
uint64_t _nwid;
- TestEthernetTapFactory *_parent;
void (*_handler)(void *,const MAC &,const MAC &,unsigned int,const Buffer<4096> &);
void *_arg;
@@ -123,8 +117,6 @@ private:
MTQ<TestFrame> _pq;
MTQ<TestFrame> _gq;
-
- AtomicCounter __refCount;
};
} // namespace ZeroTier
diff --git a/testnet/TestEthernetTapFactory.cpp b/testnet/TestEthernetTapFactory.cpp
index 105341ec..e26e67e2 100644
--- a/testnet/TestEthernetTapFactory.cpp
+++ b/testnet/TestEthernetTapFactory.cpp
@@ -36,6 +36,11 @@ TestEthernetTapFactory::TestEthernetTapFactory()
TestEthernetTapFactory::~TestEthernetTapFactory()
{
+ Mutex::Lock _l1(_taps_m);
+ Mutex::Lock _l2(_tapsByMac_m);
+ Mutex::Lock _l3(_tapsByNwid_m);
+ for(std::set<EthernetTap *>::iterator t(_taps.begin());t!=_taps.end();++t)
+ delete *t;
}
EthernetTap *TestEthernetTapFactory::open(
@@ -48,33 +53,27 @@ EthernetTap *TestEthernetTapFactory::open(
void (*handler)(void *,const MAC &,const MAC &,unsigned int,const Buffer<4096> &),
void *arg)
{
- SharedPtr<TestEthernetTap> tap(new TestEthernetTap(this,mac,mtu,metric,nwid,desiredDevice,friendlyName,handler,arg));
- {
- Mutex::Lock _l(_taps_m);
- _taps.insert(tap);
- }
- {
- Mutex::Lock _l(_tapsByMac_m);
- _tapsByMac[mac] = tap;
- }
- {
- Mutex::Lock _l(_tapsByNwid_m);
- _tapsByNwid[nwid] = tap;
- }
- return tap.ptr();
+ TestEthernetTap *tap = new TestEthernetTap(mac,mtu,metric,nwid,desiredDevice,friendlyName,handler,arg);
+ Mutex::Lock _l1(_taps_m);
+ Mutex::Lock _l2(_tapsByMac_m);
+ Mutex::Lock _l3(_tapsByNwid_m);
+ _taps.insert(tap);
+ _tapsByMac[mac] = tap;
+ _tapsByNwid[nwid] = tap;
+ return tap;
}
void TestEthernetTapFactory::close(EthernetTap *tap,bool destroyPersistentDevices)
{
- if (!tap)
- return;
- SharedPtr<TestEthernetTap> tapp((TestEthernetTap *)tap);
Mutex::Lock _l1(_taps_m);
Mutex::Lock _l2(_tapsByMac_m);
Mutex::Lock _l3(_tapsByNwid_m);
- _taps.erase(tapp);
- _tapsByMac.erase(tapp->mac());
- _tapsByNwid.erase(tapp->nwid());
+ if (!tap)
+ return;
+ _taps.erase(tap);
+ _tapsByMac.erase(tap->mac());
+ _tapsByNwid.erase(((TestEthernetTap *)tap)->nwid());
+ delete tap;
}
} // namespace ZeroTier
diff --git a/testnet/TestEthernetTapFactory.hpp b/testnet/TestEthernetTapFactory.hpp
index bc5742af..558e2eb6 100644
--- a/testnet/TestEthernetTapFactory.hpp
+++ b/testnet/TestEthernetTapFactory.hpp
@@ -32,11 +32,9 @@
#include <string>
#include <set>
-#include "../node/SharedPtr.hpp"
#include "../node/EthernetTapFactory.hpp"
#include "../node/Mutex.hpp"
#include "../node/MAC.hpp"
-#include "../node/CMWC4096.hpp"
#include "TestEthernetTap.hpp"
namespace ZeroTier {
@@ -59,36 +57,33 @@ public:
virtual void close(EthernetTap *tap,bool destroyPersistentDevices);
- inline SharedPtr<TestEthernetTap> getByMac(const MAC &mac) const
+ inline TestEthernetTap *getByMac(const MAC &mac) const
{
Mutex::Lock _l(_tapsByMac_m);
- std::map< MAC,SharedPtr<TestEthernetTap> >::const_iterator t(_tapsByMac.find(mac));
+ std::map< MAC,TestEthernetTap * >::const_iterator t(_tapsByMac.find(mac));
if (t == _tapsByMac.end())
- return SharedPtr<TestEthernetTap>();
+ return (TestEthernetTap *)0;
return t->second;
}
- inline SharedPtr<TestEthernetTap> getByNwid(uint64_t nwid) const
+ inline TestEthernetTap *getByNwid(uint64_t nwid) const
{
Mutex::Lock _l(_tapsByNwid_m);
- std::map< uint64_t,SharedPtr<TestEthernetTap> >::const_iterator t(_tapsByNwid.find(nwid));
+ std::map< uint64_t,TestEthernetTap * >::const_iterator t(_tapsByNwid.find(nwid));
if (t == _tapsByNwid.end())
- return SharedPtr<TestEthernetTap>();
+ return (TestEthernetTap *)0;
return t->second;
}
private:
- std::set< SharedPtr<TestEthernetTap> > _taps;
+ std::set< EthernetTap * > _taps;
Mutex _taps_m;
- std::map< MAC,SharedPtr<TestEthernetTap> > _tapsByMac;
+ std::map< MAC,TestEthernetTap * > _tapsByMac;
Mutex _tapsByMac_m;
- std::map< uint64_t,SharedPtr<TestEthernetTap> > _tapsByNwid;
+ std::map< uint64_t,TestEthernetTap * > _tapsByNwid;
Mutex _tapsByNwid_m;
-
- CMWC4096 _prng;
- Mutex _prng_m;
};
} // namespace ZeroTier