mirror of
https://github.com/ZeroTier/ZeroTierOne
synced 2025-08-14 02:27:38 -07: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
|
||||
throw(std::out_of_range)
|
||||
{
|
||||
b.append((unsigned char)((_a >> 32) & 0xff));
|
||||
b.append((unsigned char)((_a >> 24) & 0xff));
|
||||
b.append((unsigned char)((_a >> 16) & 0xff));
|
||||
b.append((unsigned char)((_a >> 8) & 0xff));
|
||||
b.append((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;
|
||||
unsigned char *p = (unsigned char *)b.appendField(ZT_ADDRESS_LENGTH);
|
||||
*(p++) = (unsigned char)((_a >> 32) & 0xff);
|
||||
*(p++) = (unsigned char)((_a >> 24) & 0xff);
|
||||
*(p++) = (unsigned char)((_a >> 16) & 0xff);
|
||||
*(p++) = (unsigned char)((_a >> 8) & 0xff);
|
||||
*p = (unsigned char)(_a & 0xff);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -201,19 +188,12 @@ public:
|
|||
inline bool wouldHaveMac(const MAC &mac) const
|
||||
throw()
|
||||
{
|
||||
if (mac.data[0] != ZT_MAC_FIRST_OCTET)
|
||||
return false;
|
||||
if (mac.data[1] != (unsigned char)((_a >> 32) & 0xff))
|
||||
return false;
|
||||
if (mac.data[2] != (unsigned char)((_a >> 24) & 0xff))
|
||||
return false;
|
||||
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;
|
||||
return ((mac.data[0] != ZT_MAC_FIRST_OCTET)||
|
||||
(mac.data[1] != (unsigned char)((_a >> 32) & 0xff))||
|
||||
(mac.data[2] != (unsigned char)((_a >> 24) & 0xff))||
|
||||
(mac.data[3] != (unsigned char)((_a >> 16) & 0xff))||
|
||||
(mac.data[4] != (unsigned char)((_a >> 8) & 0xff))||
|
||||
(mac.data[5] != (unsigned char)(_a & 0xff)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -234,11 +214,7 @@ public:
|
|||
/**
|
||||
* Set to null/zero
|
||||
*/
|
||||
inline void zero()
|
||||
throw()
|
||||
{
|
||||
_a = 0;
|
||||
}
|
||||
inline void zero() throw() { _a = 0; }
|
||||
|
||||
/**
|
||||
* Check if this address is reserved
|
||||
|
|
|
@ -301,6 +301,25 @@ public:
|
|||
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
|
||||
*
|
||||
|
|
|
@ -43,7 +43,6 @@ namespace ZeroTier {
|
|||
const Defaults ZT_DEFAULTS;
|
||||
|
||||
static inline std::map< Identity,std::vector<InetAddress> > _mkSupernodeMap()
|
||||
throw(std::runtime_error)
|
||||
{
|
||||
std::map< Identity,std::vector<InetAddress> > sn;
|
||||
Identity id;
|
||||
|
@ -99,8 +98,7 @@ static inline std::string _mkDefaultHomePath()
|
|||
#endif
|
||||
}
|
||||
|
||||
Defaults::Defaults()
|
||||
throw(std::runtime_error) :
|
||||
Defaults::Defaults() :
|
||||
#ifdef ZT_TRACE_MULTICAST
|
||||
multicastTraceWatcher(ZT_TRACE_MULTICAST),
|
||||
#endif
|
||||
|
|
|
@ -49,9 +49,7 @@ namespace ZeroTier {
|
|||
class Defaults
|
||||
{
|
||||
public:
|
||||
Defaults()
|
||||
throw(std::runtime_error);
|
||||
~Defaults() {}
|
||||
Defaults();
|
||||
|
||||
#ifdef ZT_TRACE_MULTICAST
|
||||
/**
|
||||
|
|
|
@ -94,7 +94,6 @@ bool Demarc::has(Port p) const
|
|||
}
|
||||
|
||||
bool Demarc::bindLocalUdp(unsigned int localPort)
|
||||
throw()
|
||||
{
|
||||
Mutex::Lock _l(_ports_m);
|
||||
|
||||
|
|
|
@ -100,8 +100,7 @@ public:
|
|||
* @param localPort Local IP port
|
||||
* @return True if successfully bound, or if already bound
|
||||
*/
|
||||
bool bindLocalUdp(unsigned int localPort)
|
||||
throw();
|
||||
bool bindLocalUdp(unsigned int localPort);
|
||||
|
||||
/**
|
||||
* Pick a port to send to an address of a given type
|
||||
|
|
|
@ -58,8 +58,7 @@
|
|||
|
||||
namespace ZeroTier {
|
||||
|
||||
NodeConfig::NodeConfig(const RuntimeEnvironment *renv,const char *authToken,unsigned int controlPort)
|
||||
throw(std::runtime_error) :
|
||||
NodeConfig::NodeConfig(const RuntimeEnvironment *renv,const char *authToken,unsigned int controlPort) :
|
||||
_r(renv),
|
||||
_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)
|
||||
throw(std::out_of_range)
|
||||
{
|
||||
char poly1305tag[ZT_POLY1305_MAC_LEN];
|
||||
char iv[8];
|
||||
|
|
|
@ -63,8 +63,7 @@ public:
|
|||
* @param controlPort Control port for local control packet I/O
|
||||
* @throws std::runtime_error Unable to bind to local control port
|
||||
*/
|
||||
NodeConfig(const RuntimeEnvironment *renv,const char *authToken,unsigned int controlPort)
|
||||
throw(std::runtime_error);
|
||||
NodeConfig(const RuntimeEnvironment *renv,const char *authToken,unsigned int controlPort);
|
||||
|
||||
~NodeConfig();
|
||||
|
||||
|
@ -143,8 +142,7 @@ public:
|
|||
* @return One or more transport armored packets (if payload 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)
|
||||
throw(std::out_of_range);
|
||||
static std::vector< Buffer<ZT_NODECONFIG_MAX_PACKET_SIZE> > encodeControlMessage(const void *key,unsigned long conversationId,const std::vector<std::string> &payload);
|
||||
|
||||
/**
|
||||
* Decode a packet from the control bus
|
||||
|
|
|
@ -45,7 +45,6 @@
|
|||
namespace ZeroTier {
|
||||
|
||||
bool PacketDecoder::tryDecode(const RuntimeEnvironment *_r)
|
||||
throw(std::out_of_range,std::runtime_error)
|
||||
{
|
||||
if ((!encrypted())&&(verb() == Packet::VERB_HELLO)) {
|
||||
// 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::runtime_error Other error processing packet (should be discarded)
|
||||
*/
|
||||
bool tryDecode(const RuntimeEnvironment *_r)
|
||||
throw(std::out_of_range,std::runtime_error);
|
||||
bool tryDecode(const RuntimeEnvironment *_r);
|
||||
|
||||
/**
|
||||
* @return Time of packet receipt / start of decode
|
||||
|
|
123
node/Range.hpp
123
node/Range.hpp
|
@ -1,123 +0,0 @@
|
|||
/*
|
||||
* ZeroTier One - Global Peer to Peer Ethernet
|
||||
* Copyright (C) 2012-2013 ZeroTier Networks LLC
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* --
|
||||
*
|
||||
* ZeroTier may be used and distributed under the terms of the GPLv3, which
|
||||
* are available at: http://www.gnu.org/licenses/gpl-3.0.html
|
||||
*
|
||||
* If you would like to embed ZeroTier into a commercial application or
|
||||
* redistribute it in a modified binary form, please contact ZeroTier Networks
|
||||
* LLC. Start here: http://www.zerotier.com/
|
||||
*/
|
||||
|
||||
#ifndef _ZT_RANGE_HPP
|
||||
#define _ZT_RANGE_HPP
|
||||
|
||||
namespace ZeroTier {
|
||||
|
||||
/**
|
||||
* A range of numeric values
|
||||
*
|
||||
* @tparam T Type, can be any numeric value (int, float, double, etc.)
|
||||
*/
|
||||
template<typename T>
|
||||
class Range
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Construct an empty range
|
||||
*/
|
||||
Range()
|
||||
throw() :
|
||||
start(0),
|
||||
end(0)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param s Starting value (inclusive)
|
||||
* @param e Ending value (exclusive)
|
||||
*/
|
||||
Range(T s,T e)
|
||||
throw() :
|
||||
start(s),
|
||||
end(e)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a range containing from n to n+1 (thus only n for integers)
|
||||
*
|
||||
* @param n Number to contain
|
||||
*/
|
||||
Range(T n)
|
||||
throw() :
|
||||
start(n),
|
||||
end(n+1)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return end - start
|
||||
*/
|
||||
inline T magnitude() const
|
||||
throw()
|
||||
{
|
||||
return (end - start);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return True if range contains something (magnitude is nonzero)
|
||||
*/
|
||||
inline operator bool() const
|
||||
throw()
|
||||
{
|
||||
return (end > start);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param v Value to test
|
||||
* @return True if value is between start (inclusive) and end (exclusive)
|
||||
*/
|
||||
inline bool operator()(const T &v) const
|
||||
throw()
|
||||
{
|
||||
return ((v >= start)&&(v < end));
|
||||
}
|
||||
|
||||
inline bool operator==(const Range &r) const throw() { return ((start == r.start)&&(end == r.end)); }
|
||||
inline bool operator!=(const Range &r) const throw() { return (!(*this == r)); }
|
||||
inline bool operator<(const Range &r) const throw() { return ((start < r.start) ? true : ((start == r.start) ? (end < r.end) : false)); }
|
||||
inline bool operator>(const Range &r) const throw() { return (r < *this); }
|
||||
inline bool operator<=(const Range &r) const throw() { return !(r < *this); }
|
||||
inline bool operator>=(const Range &r) const throw() { return !(*this < r); }
|
||||
|
||||
/**
|
||||
* Start of range (may be modified directly)
|
||||
*/
|
||||
T start;
|
||||
|
||||
/**
|
||||
* End of range (may be modified directly)
|
||||
*/
|
||||
T end;
|
||||
};
|
||||
|
||||
} // namespace ZeroTier
|
||||
|
||||
#endif
|
|
@ -74,7 +74,6 @@ SysEnv::~SysEnv()
|
|||
#ifdef __APPLE__
|
||||
|
||||
uint64_t SysEnv::getNetworkConfigurationFingerprint()
|
||||
throw()
|
||||
{
|
||||
int mib[6];
|
||||
size_t needed;
|
||||
|
@ -141,7 +140,6 @@ uint64_t SysEnv::getNetworkConfigurationFingerprint()
|
|||
#if defined(__linux__) || defined(linux) || defined(__LINUX__) || defined(__linux)
|
||||
|
||||
uint64_t SysEnv::getNetworkConfigurationFingerprint()
|
||||
throw()
|
||||
{
|
||||
char buf[16384];
|
||||
uint64_t fingerprint = 5381; // djb2 hash algorithm is used below
|
||||
|
@ -218,7 +216,6 @@ uint64_t SysEnv::getNetworkConfigurationFingerprint()
|
|||
#ifdef __WINDOWS__
|
||||
|
||||
uint64_t SysEnv::getNetworkConfigurationFingerprint()
|
||||
throw()
|
||||
{
|
||||
// TODO: windows version
|
||||
return 1;
|
||||
|
|
|
@ -48,8 +48,7 @@ public:
|
|||
/**
|
||||
* @return Fingerprint of currently running network environment
|
||||
*/
|
||||
uint64_t getNetworkConfigurationFingerprint()
|
||||
throw();
|
||||
uint64_t getNetworkConfigurationFingerprint();
|
||||
|
||||
private:
|
||||
const RuntimeEnvironment *_r;
|
||||
|
|
|
@ -37,8 +37,7 @@ namespace ZeroTier {
|
|||
#define ZT_KISSDB_KEY_SIZE ZT_ADDRESS_LENGTH
|
||||
#define ZT_KISSDB_VALUE_SIZE ZT_PEER_MAX_SERIALIZED_LENGTH
|
||||
|
||||
Topology::Topology(const RuntimeEnvironment *renv,const char *dbpath)
|
||||
throw(std::runtime_error) :
|
||||
Topology::Topology(const RuntimeEnvironment *renv,const char *dbpath) :
|
||||
_r(renv),
|
||||
_amSupernode(false)
|
||||
{
|
||||
|
|
|
@ -55,9 +55,7 @@ class RuntimeEnvironment;
|
|||
class Topology
|
||||
{
|
||||
public:
|
||||
Topology(const RuntimeEnvironment *renv,const char *dbpath)
|
||||
throw(std::runtime_error);
|
||||
|
||||
Topology(const RuntimeEnvironment *renv,const char *dbpath);
|
||||
~Topology();
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue