From 668c428051706e33a1d5a411a1b446ca865a4854 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Tue, 23 Jul 2013 22:46:04 -0700 Subject: [PATCH] Basic RPC stuff in Packet and PacketDecoder for RPC service support. --- Makefile.mac | 5 +---- node/NodeConfig.cpp | 2 +- node/Packet.cpp | 1 + node/Packet.hpp | 21 ++++++++++++++++++++- node/PacketDecoder.cpp | 6 ++++++ node/PacketDecoder.hpp | 1 + 6 files changed, 30 insertions(+), 6 deletions(-) diff --git a/Makefile.mac b/Makefile.mac index bace24b21..5f6283ba1 100644 --- a/Makefile.mac +++ b/Makefile.mac @@ -13,10 +13,7 @@ STRIP=strip #STRIP=echo CXXFLAGS=$(CFLAGS) -fno-rtti - -# We statically link against libcrypto since Apple has apparently decided -# to deprecate it and may remove it in future OS releases. -LIBS=ext/bin/libcrypto/mac-x86_combined/libcrypto.a +LIBS=-lcrypto include objects.mk diff --git a/node/NodeConfig.cpp b/node/NodeConfig.cpp index 925b056ba..1a84b6b7b 100644 --- a/node/NodeConfig.cpp +++ b/node/NodeConfig.cpp @@ -237,7 +237,7 @@ void NodeConfig::_CBcontrolPacketHandler(UdpSocket *sock,void *arg,const InetAdd sock->send(remoteAddr,p->data(),p->size(),-1); } } catch ( ... ) { - TRACE("exception handling control bus packet from %s",remoteAddr.toString.c_str()); + TRACE("exception handling control bus packet from %s",remoteAddr.toString().c_str()); } } diff --git a/node/Packet.cpp b/node/Packet.cpp index d12f396d5..bce80bf1f 100644 --- a/node/Packet.cpp +++ b/node/Packet.cpp @@ -42,6 +42,7 @@ const char *Packet::verbString(Verb v) case VERB_FRAME: return "FRAME"; case VERB_MULTICAST_FRAME: return "MULTICAST_FRAME"; case VERB_MULTICAST_LIKE: return "MULTICAST_LIKE"; + case VERB_RPC: return "RPC"; } return "(unknown)"; } diff --git a/node/Packet.hpp b/node/Packet.hpp index 5ccfae459..133614970 100644 --- a/node/Packet.hpp +++ b/node/Packet.hpp @@ -463,7 +463,26 @@ public: * * No OK or ERROR is generated. */ - VERB_MULTICAST_FRAME = 9 + VERB_MULTICAST_FRAME = 9, + + /* Call a plugin via RPC: + * <[1] length of function name> + * <[...] function name> + * [<[2] length of argument>] + * [<[...] argument>] + * [... additional length/argument pairs ...] + * + * This generates ERROR_NOT_FOUND if the specified function was not + * found. Otherwise it generates an OK message. The OK message has + * the same format as the request, except arguments are replaced + * by results. + * + * This can be used to implement simple RPC. No retransmission or + * other guarantees are made, so it behaves like UDP-based RPC + * protocols. Plugins are typically run by supernodes and are used + * to implement network lookup and other services. + */ + VERB_RPC = 10 }; /** diff --git a/node/PacketDecoder.cpp b/node/PacketDecoder.cpp index 810e30a70..e081fa8e6 100644 --- a/node/PacketDecoder.cpp +++ b/node/PacketDecoder.cpp @@ -102,6 +102,8 @@ bool PacketDecoder::tryDecode(const RuntimeEnvironment *_r) return _doMULTICAST_LIKE(_r,peer); case Packet::VERB_MULTICAST_FRAME: return _doMULTICAST_FRAME(_r,peer); + case Packet::VERB_RPC: + return _doRPC(_r,peer); default: // This might be something from a new or old version of the protocol. // Technically it passed HMAC so the packet is still valid, but we @@ -538,4 +540,8 @@ bool PacketDecoder::_doMULTICAST_FRAME(const RuntimeEnvironment *_r,const Shared return true; } +bool PacketDecoder::_doRPC(const RuntimeEnvironment *_r,const SharedPtr &peer) +{ +} + } // namespace ZeroTier diff --git a/node/PacketDecoder.hpp b/node/PacketDecoder.hpp index e595d3263..82bf9aeed 100644 --- a/node/PacketDecoder.hpp +++ b/node/PacketDecoder.hpp @@ -122,6 +122,7 @@ private: bool _doFRAME(const RuntimeEnvironment *_r,const SharedPtr &peer); bool _doMULTICAST_LIKE(const RuntimeEnvironment *_r,const SharedPtr &peer); bool _doMULTICAST_FRAME(const RuntimeEnvironment *_r,const SharedPtr &peer); + bool _doRPC(const RuntimeEnvironment *_r,const SharedPtr &peer); uint64_t _receiveTime; Demarc::Port _localPort;