Browse Source

Clean up some stuff, including a few spots where exceptions were not being handled correctly.

Adam Ierymenko 11 years ago
parent
commit
ca93b4a1ac

+ 0 - 0
node/Range.hpp → attic/Range.hpp


+ 13 - 37
node/Address.hpp

@@ -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

+ 19 - 0
node/Buffer.hpp

@@ -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
 	 * 

+ 1 - 3
node/Defaults.cpp

@@ -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

+ 1 - 3
node/Defaults.hpp

@@ -49,9 +49,7 @@ namespace ZeroTier {
 class Defaults
 {
 public:
-	Defaults()
-		throw(std::runtime_error);
-	~Defaults() {}
+	Defaults();
 
 #ifdef ZT_TRACE_MULTICAST
 	/**

+ 0 - 1
node/Demarc.cpp

@@ -94,7 +94,6 @@ bool Demarc::has(Port p) const
 }
 
 bool Demarc::bindLocalUdp(unsigned int localPort)
-	throw()
 {
 	Mutex::Lock _l(_ports_m);
 

+ 1 - 2
node/Demarc.hpp

@@ -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

+ 1 - 3
node/NodeConfig.cpp

@@ -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];

+ 2 - 4
node/NodeConfig.hpp

@@ -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

+ 0 - 1
node/PacketDecoder.cpp

@@ -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

+ 1 - 2
node/PacketDecoder.hpp

@@ -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

+ 0 - 3
node/SysEnv.cpp

@@ -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;

+ 1 - 2
node/SysEnv.hpp

@@ -48,8 +48,7 @@ public:
 	/**
 	 * @return Fingerprint of currently running network environment
 	 */
-	uint64_t getNetworkConfigurationFingerprint()
-		throw();
+	uint64_t getNetworkConfigurationFingerprint();
 
 private:
 	const RuntimeEnvironment *_r;

+ 1 - 2
node/Topology.cpp

@@ -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)
 {

+ 1 - 3
node/Topology.hpp

@@ -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();
 
 	/**