From ee0f56355bd7b1d2798a750fb02a975b526dd9cf Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Fri, 3 Apr 2015 13:14:37 -0700 Subject: Send path simplification. --- node/Path.hpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'node/Path.hpp') diff --git a/node/Path.hpp b/node/Path.hpp index df68339e..1adb8f99 100644 --- a/node/Path.hpp +++ b/node/Path.hpp @@ -36,8 +36,11 @@ #include #include "Constants.hpp" +#include "Node.hpp" #include "InetAddress.hpp" #include "Utils.hpp" +#include "AntiRecursion.hpp" +#include "RuntimeEnvironment.hpp" namespace ZeroTier { @@ -91,6 +94,8 @@ public: /** * Called when a packet is sent to this path * + * This is called automatically by Path::send(). + * * @param t Time of send */ inline void sent(uint64_t t) throw() { _lastSend = t; } @@ -128,7 +133,7 @@ public: */ inline int desperation(uint64_t now) const { - if ((_lastSend > _lastReceived)&&(_fixed)) + if ((_fixed)&&(_lastSend > _lastReceived)) return std::max(_lastReceiveDesperation,(int)((_lastSend - _lastReceived) / ZT_DESPERATION_INCREMENT)); return _lastReceiveDesperation; } @@ -143,6 +148,25 @@ public: return ( (_fixed) || ((now - _lastReceived) < ZT_PEER_PATH_ACTIVITY_TIMEOUT) ); } + /** + * Send a packet via this path + * + * @param RR Runtime environment + * @param data Packet data + * @param len Packet length + * @param now Current time + * @return True if transport reported success + */ + inline bool send(const RuntimeEnvironment *RR,const void *data,unsigned int len,uint64_t now) + { + if (RR->node->putPacket(_addr,data,len,desperation(now))) { + sent(now); + RR->antiRec->logOutgoingZT(data,len); + return true; + } + return false; + } + /** * @param now Current time * @return Human-readable address and other information about this path -- cgit v1.2.3