diff options
| author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-07-06 14:08:13 -0700 |
|---|---|---|
| committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-07-06 14:08:13 -0700 |
| commit | 93bb934d4e77fd1436ebe81336d396fa769aa59b (patch) | |
| tree | 37bdf28002a09429c02995e6dc2701fa1c021abe /node/RemotePath.hpp | |
| parent | feddd946f9d3ac6a643968582610eb4ffaebb69d (diff) | |
| download | infinitytier-93bb934d4e77fd1436ebe81336d396fa769aa59b.tar.gz infinitytier-93bb934d4e77fd1436ebe81336d396fa769aa59b.zip | |
Some cleanup, docs, and Path -> Path > RemotePath refactor.
Diffstat (limited to 'node/RemotePath.hpp')
| -rw-r--r-- | node/RemotePath.hpp | 97 |
1 files changed, 23 insertions, 74 deletions
diff --git a/node/RemotePath.hpp b/node/RemotePath.hpp index 393b7225..47c8916d 100644 --- a/node/RemotePath.hpp +++ b/node/RemotePath.hpp @@ -25,72 +25,56 @@ * LLC. Start here: http://www.zerotier.com/ */ -#ifndef ZT_PATH_HPP -#define ZT_PATH_HPP +#ifndef ZT_REMOTEPATH_HPP +#define ZT_REMOTEPATH_HPP #include <stdint.h> #include <string.h> #include <stdexcept> -#include <string> #include <algorithm> -#include "Constants.hpp" +#include "Path.hpp" #include "Node.hpp" -#include "InetAddress.hpp" -#include "Utils.hpp" #include "AntiRecursion.hpp" #include "RuntimeEnvironment.hpp" namespace ZeroTier { /** - * WAN address and protocol for reaching a peer + * Path to a remote peer * - * This structure is volatile and memcpy-able, and depends on - * InetAddress being similarly safe. + * This extends Path to include status information about path activity. */ -class Path +class RemotePath : public Path { public: - Path() : - _addr(), + RemotePath() : + Path(), _lastSend(0), - _lastReceived(0), - _fixed(false) {} + _lastReceived(0) {} - Path(const Path &p) throw() { memcpy(this,&p,sizeof(Path)); } - - Path(const InetAddress &addr,bool fixed) : - _addr(addr), + RemotePath(const InetAddress &addr,bool fixed) : + Path(addr,0,TRUST_NORMAL,false,fixed), _lastSend(0), - _lastReceived(0), - _fixed(fixed) {} + _lastReceived(0) {} - inline void init(const InetAddress &addr,bool fixed) - { - _addr = addr; - _lastSend = 0; - _lastReceived = 0; - _fixed = fixed; - } + inline uint64_t lastSend() const throw() { return _lastSend; } + inline uint64_t lastReceived() const throw() { return _lastReceived; } - inline Path &operator=(const Path &p) + /** + * @param f New value of parent 'fixed' field + */ + inline void setFixed(const bool f) + throw() { - if (this != &p) - memcpy(this,&p,sizeof(Path)); - return *this; + _fixed = f; } - inline const InetAddress &address() const throw() { return _addr; } - - inline uint64_t lastSend() const throw() { return _lastSend; } - inline uint64_t lastReceived() const throw() { return _lastReceived; } - /** - * Called when a packet is sent to this path + * Called when a packet is sent to this remote path * - * This is called automatically by Path::send(). + * This is called automatically by RemotePath::send(). * * @param t Time of send */ @@ -101,7 +85,7 @@ public: } /** - * Called when a packet is received from this path + * Called when a packet is received from this remote path * * @param t Time of receive */ @@ -112,16 +96,6 @@ public: } /** - * @return Is this a fixed path? - */ - inline bool fixed() const throw() { return _fixed; } - - /** - * @param f New value of fixed path flag - */ - inline void setFixed(bool f) throw() { _fixed = f; } - - /** * @param now Current time * @return True if this path is fixed or has received data in last ACTIVITY_TIMEOUT ms */ @@ -150,34 +124,9 @@ public: return false; } - /** - * @param now Current time - * @return Human-readable address and other information about this path - */ - inline std::string toString(uint64_t now) const - { - char tmp[1024]; - Utils::snprintf(tmp,sizeof(tmp),"%s(%s)", - _addr.toString().c_str(), - ((_fixed) ? "fixed" : (active(now) ? "active" : "inactive")) - ); - return std::string(tmp); - } - - inline operator bool() const throw() { return (_addr); } - - inline bool operator==(const Path &p) const throw() { return (_addr == p._addr); } - inline bool operator!=(const Path &p) const throw() { return (_addr != p._addr); } - inline bool operator<(const Path &p) const throw() { return (_addr < p._addr); } - inline bool operator>(const Path &p) const throw() { return (_addr > p._addr); } - inline bool operator<=(const Path &p) const throw() { return (_addr <= p._addr); } - inline bool operator>=(const Path &p) const throw() { return (_addr >= p._addr); } - private: - InetAddress _addr; uint64_t _lastSend; uint64_t _lastReceived; - bool _fixed; }; } // namespace ZeroTier |
