mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-05 03:53:44 +02:00
Clean up some stuff, including a few spots where exceptions were not being handled correctly.
This commit is contained in:
parent
03b909603a
commit
ca93b4a1ac
15 changed files with 42 additions and 66 deletions
|
@ -150,25 +150,12 @@ public:
|
||||||
inline void appendTo(Buffer<C> &b) const
|
inline void appendTo(Buffer<C> &b) const
|
||||||
throw(std::out_of_range)
|
throw(std::out_of_range)
|
||||||
{
|
{
|
||||||
b.append((unsigned char)((_a >> 32) & 0xff));
|
unsigned char *p = (unsigned char *)b.appendField(ZT_ADDRESS_LENGTH);
|
||||||
b.append((unsigned char)((_a >> 24) & 0xff));
|
*(p++) = (unsigned char)((_a >> 32) & 0xff);
|
||||||
b.append((unsigned char)((_a >> 16) & 0xff));
|
*(p++) = (unsigned char)((_a >> 24) & 0xff);
|
||||||
b.append((unsigned char)((_a >> 8) & 0xff));
|
*(p++) = (unsigned char)((_a >> 16) & 0xff);
|
||||||
b.append((unsigned char)(_a & 0xff));
|
*(p++) = (unsigned char)((_a >> 8) & 0xff);
|
||||||
}
|
*p = (unsigned char)(_a & 0xff);
|
||||||
|
|
||||||
/**
|
|
||||||
* @return String containing address as 5 binary bytes
|
|
||||||
*/
|
|
||||||
inline std::string toBinaryString() const
|
|
||||||
{
|
|
||||||
std::string b;
|
|
||||||
b.push_back((char)((_a >> 32) & 0xff));
|
|
||||||
b.push_back((char)((_a >> 24) & 0xff));
|
|
||||||
b.push_back((char)((_a >> 16) & 0xff));
|
|
||||||
b.push_back((char)((_a >> 8) & 0xff));
|
|
||||||
b.push_back((char)(_a & 0xff));
|
|
||||||
return b;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -201,19 +188,12 @@ public:
|
||||||
inline bool wouldHaveMac(const MAC &mac) const
|
inline bool wouldHaveMac(const MAC &mac) const
|
||||||
throw()
|
throw()
|
||||||
{
|
{
|
||||||
if (mac.data[0] != ZT_MAC_FIRST_OCTET)
|
return ((mac.data[0] != ZT_MAC_FIRST_OCTET)||
|
||||||
return false;
|
(mac.data[1] != (unsigned char)((_a >> 32) & 0xff))||
|
||||||
if (mac.data[1] != (unsigned char)((_a >> 32) & 0xff))
|
(mac.data[2] != (unsigned char)((_a >> 24) & 0xff))||
|
||||||
return false;
|
(mac.data[3] != (unsigned char)((_a >> 16) & 0xff))||
|
||||||
if (mac.data[2] != (unsigned char)((_a >> 24) & 0xff))
|
(mac.data[4] != (unsigned char)((_a >> 8) & 0xff))||
|
||||||
return false;
|
(mac.data[5] != (unsigned char)(_a & 0xff)));
|
||||||
if (mac.data[3] != (unsigned char)((_a >> 16) & 0xff))
|
|
||||||
return false;
|
|
||||||
if (mac.data[4] != (unsigned char)((_a >> 8) & 0xff))
|
|
||||||
return false;
|
|
||||||
if (mac.data[5] != (unsigned char)(_a & 0xff))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -234,11 +214,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Set to null/zero
|
* Set to null/zero
|
||||||
*/
|
*/
|
||||||
inline void zero()
|
inline void zero() throw() { _a = 0; }
|
||||||
throw()
|
|
||||||
{
|
|
||||||
_a = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if this address is reserved
|
* Check if this address is reserved
|
||||||
|
|
|
@ -301,6 +301,25 @@ public:
|
||||||
append(b._b,b._l);
|
append(b._b,b._l);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increment size and return pointer to field of specified size
|
||||||
|
*
|
||||||
|
* The memory isn't actually written, so this is a shortcut for a multi-step
|
||||||
|
* process involving getting the current pointer and adding size.
|
||||||
|
*
|
||||||
|
* @param l Length of field to append
|
||||||
|
* @return Pointer to beginning of appended field of length 'l'
|
||||||
|
*/
|
||||||
|
inline char *appendField(unsigned int l)
|
||||||
|
throw(std::out_of_range)
|
||||||
|
{
|
||||||
|
if ((_l + l) > C)
|
||||||
|
throw std::out_of_range("Buffer: append beyond capacity");
|
||||||
|
char *r = _b + _l;
|
||||||
|
_l += l;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increment size by a given number of bytes
|
* Increment size by a given number of bytes
|
||||||
*
|
*
|
||||||
|
|
|
@ -43,7 +43,6 @@ namespace ZeroTier {
|
||||||
const Defaults ZT_DEFAULTS;
|
const Defaults ZT_DEFAULTS;
|
||||||
|
|
||||||
static inline std::map< Identity,std::vector<InetAddress> > _mkSupernodeMap()
|
static inline std::map< Identity,std::vector<InetAddress> > _mkSupernodeMap()
|
||||||
throw(std::runtime_error)
|
|
||||||
{
|
{
|
||||||
std::map< Identity,std::vector<InetAddress> > sn;
|
std::map< Identity,std::vector<InetAddress> > sn;
|
||||||
Identity id;
|
Identity id;
|
||||||
|
@ -99,8 +98,7 @@ static inline std::string _mkDefaultHomePath()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Defaults::Defaults()
|
Defaults::Defaults() :
|
||||||
throw(std::runtime_error) :
|
|
||||||
#ifdef ZT_TRACE_MULTICAST
|
#ifdef ZT_TRACE_MULTICAST
|
||||||
multicastTraceWatcher(ZT_TRACE_MULTICAST),
|
multicastTraceWatcher(ZT_TRACE_MULTICAST),
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -49,9 +49,7 @@ namespace ZeroTier {
|
||||||
class Defaults
|
class Defaults
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Defaults()
|
Defaults();
|
||||||
throw(std::runtime_error);
|
|
||||||
~Defaults() {}
|
|
||||||
|
|
||||||
#ifdef ZT_TRACE_MULTICAST
|
#ifdef ZT_TRACE_MULTICAST
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -94,7 +94,6 @@ bool Demarc::has(Port p) const
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Demarc::bindLocalUdp(unsigned int localPort)
|
bool Demarc::bindLocalUdp(unsigned int localPort)
|
||||||
throw()
|
|
||||||
{
|
{
|
||||||
Mutex::Lock _l(_ports_m);
|
Mutex::Lock _l(_ports_m);
|
||||||
|
|
||||||
|
|
|
@ -100,8 +100,7 @@ public:
|
||||||
* @param localPort Local IP port
|
* @param localPort Local IP port
|
||||||
* @return True if successfully bound, or if already bound
|
* @return True if successfully bound, or if already bound
|
||||||
*/
|
*/
|
||||||
bool bindLocalUdp(unsigned int localPort)
|
bool bindLocalUdp(unsigned int localPort);
|
||||||
throw();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pick a port to send to an address of a given type
|
* Pick a port to send to an address of a given type
|
||||||
|
|
|
@ -58,8 +58,7 @@
|
||||||
|
|
||||||
namespace ZeroTier {
|
namespace ZeroTier {
|
||||||
|
|
||||||
NodeConfig::NodeConfig(const RuntimeEnvironment *renv,const char *authToken,unsigned int controlPort)
|
NodeConfig::NodeConfig(const RuntimeEnvironment *renv,const char *authToken,unsigned int controlPort) :
|
||||||
throw(std::runtime_error) :
|
|
||||||
_r(renv),
|
_r(renv),
|
||||||
_controlSocket(true,controlPort,false,&_CBcontrolPacketHandler,this)
|
_controlSocket(true,controlPort,false,&_CBcontrolPacketHandler,this)
|
||||||
{
|
{
|
||||||
|
@ -266,7 +265,6 @@ std::vector<std::string> NodeConfig::execute(const char *command)
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector< Buffer<ZT_NODECONFIG_MAX_PACKET_SIZE> > NodeConfig::encodeControlMessage(const void *key,unsigned long conversationId,const std::vector<std::string> &payload)
|
std::vector< Buffer<ZT_NODECONFIG_MAX_PACKET_SIZE> > NodeConfig::encodeControlMessage(const void *key,unsigned long conversationId,const std::vector<std::string> &payload)
|
||||||
throw(std::out_of_range)
|
|
||||||
{
|
{
|
||||||
char poly1305tag[ZT_POLY1305_MAC_LEN];
|
char poly1305tag[ZT_POLY1305_MAC_LEN];
|
||||||
char iv[8];
|
char iv[8];
|
||||||
|
|
|
@ -63,8 +63,7 @@ public:
|
||||||
* @param controlPort Control port for local control packet I/O
|
* @param controlPort Control port for local control packet I/O
|
||||||
* @throws std::runtime_error Unable to bind to local control port
|
* @throws std::runtime_error Unable to bind to local control port
|
||||||
*/
|
*/
|
||||||
NodeConfig(const RuntimeEnvironment *renv,const char *authToken,unsigned int controlPort)
|
NodeConfig(const RuntimeEnvironment *renv,const char *authToken,unsigned int controlPort);
|
||||||
throw(std::runtime_error);
|
|
||||||
|
|
||||||
~NodeConfig();
|
~NodeConfig();
|
||||||
|
|
||||||
|
@ -143,8 +142,7 @@ public:
|
||||||
* @return One or more transport armored packets (if payload too big)
|
* @return One or more transport armored packets (if payload too big)
|
||||||
* @throws std::out_of_range An element of payload is too big
|
* @throws std::out_of_range An element of payload is too big
|
||||||
*/
|
*/
|
||||||
static std::vector< Buffer<ZT_NODECONFIG_MAX_PACKET_SIZE> > encodeControlMessage(const void *key,unsigned long conversationId,const std::vector<std::string> &payload)
|
static std::vector< Buffer<ZT_NODECONFIG_MAX_PACKET_SIZE> > encodeControlMessage(const void *key,unsigned long conversationId,const std::vector<std::string> &payload);
|
||||||
throw(std::out_of_range);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decode a packet from the control bus
|
* Decode a packet from the control bus
|
||||||
|
|
|
@ -45,7 +45,6 @@
|
||||||
namespace ZeroTier {
|
namespace ZeroTier {
|
||||||
|
|
||||||
bool PacketDecoder::tryDecode(const RuntimeEnvironment *_r)
|
bool PacketDecoder::tryDecode(const RuntimeEnvironment *_r)
|
||||||
throw(std::out_of_range,std::runtime_error)
|
|
||||||
{
|
{
|
||||||
if ((!encrypted())&&(verb() == Packet::VERB_HELLO)) {
|
if ((!encrypted())&&(verb() == Packet::VERB_HELLO)) {
|
||||||
// Unencrypted HELLOs are handled here since they are used to
|
// Unencrypted HELLOs are handled here since they are used to
|
||||||
|
|
|
@ -100,8 +100,7 @@ public:
|
||||||
* @throws std::out_of_range Range error processing packet (should be discarded)
|
* @throws std::out_of_range Range error processing packet (should be discarded)
|
||||||
* @throws std::runtime_error Other error processing packet (should be discarded)
|
* @throws std::runtime_error Other error processing packet (should be discarded)
|
||||||
*/
|
*/
|
||||||
bool tryDecode(const RuntimeEnvironment *_r)
|
bool tryDecode(const RuntimeEnvironment *_r);
|
||||||
throw(std::out_of_range,std::runtime_error);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Time of packet receipt / start of decode
|
* @return Time of packet receipt / start of decode
|
||||||
|
|
|
@ -74,7 +74,6 @@ SysEnv::~SysEnv()
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
|
|
||||||
uint64_t SysEnv::getNetworkConfigurationFingerprint()
|
uint64_t SysEnv::getNetworkConfigurationFingerprint()
|
||||||
throw()
|
|
||||||
{
|
{
|
||||||
int mib[6];
|
int mib[6];
|
||||||
size_t needed;
|
size_t needed;
|
||||||
|
@ -141,7 +140,6 @@ uint64_t SysEnv::getNetworkConfigurationFingerprint()
|
||||||
#if defined(__linux__) || defined(linux) || defined(__LINUX__) || defined(__linux)
|
#if defined(__linux__) || defined(linux) || defined(__LINUX__) || defined(__linux)
|
||||||
|
|
||||||
uint64_t SysEnv::getNetworkConfigurationFingerprint()
|
uint64_t SysEnv::getNetworkConfigurationFingerprint()
|
||||||
throw()
|
|
||||||
{
|
{
|
||||||
char buf[16384];
|
char buf[16384];
|
||||||
uint64_t fingerprint = 5381; // djb2 hash algorithm is used below
|
uint64_t fingerprint = 5381; // djb2 hash algorithm is used below
|
||||||
|
@ -218,7 +216,6 @@ uint64_t SysEnv::getNetworkConfigurationFingerprint()
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
|
|
||||||
uint64_t SysEnv::getNetworkConfigurationFingerprint()
|
uint64_t SysEnv::getNetworkConfigurationFingerprint()
|
||||||
throw()
|
|
||||||
{
|
{
|
||||||
// TODO: windows version
|
// TODO: windows version
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -48,8 +48,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* @return Fingerprint of currently running network environment
|
* @return Fingerprint of currently running network environment
|
||||||
*/
|
*/
|
||||||
uint64_t getNetworkConfigurationFingerprint()
|
uint64_t getNetworkConfigurationFingerprint();
|
||||||
throw();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const RuntimeEnvironment *_r;
|
const RuntimeEnvironment *_r;
|
||||||
|
|
|
@ -37,8 +37,7 @@ namespace ZeroTier {
|
||||||
#define ZT_KISSDB_KEY_SIZE ZT_ADDRESS_LENGTH
|
#define ZT_KISSDB_KEY_SIZE ZT_ADDRESS_LENGTH
|
||||||
#define ZT_KISSDB_VALUE_SIZE ZT_PEER_MAX_SERIALIZED_LENGTH
|
#define ZT_KISSDB_VALUE_SIZE ZT_PEER_MAX_SERIALIZED_LENGTH
|
||||||
|
|
||||||
Topology::Topology(const RuntimeEnvironment *renv,const char *dbpath)
|
Topology::Topology(const RuntimeEnvironment *renv,const char *dbpath) :
|
||||||
throw(std::runtime_error) :
|
|
||||||
_r(renv),
|
_r(renv),
|
||||||
_amSupernode(false)
|
_amSupernode(false)
|
||||||
{
|
{
|
||||||
|
|
|
@ -55,9 +55,7 @@ class RuntimeEnvironment;
|
||||||
class Topology
|
class Topology
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Topology(const RuntimeEnvironment *renv,const char *dbpath)
|
Topology(const RuntimeEnvironment *renv,const char *dbpath);
|
||||||
throw(std::runtime_error);
|
|
||||||
|
|
||||||
~Topology();
|
~Topology();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue