2015-10-14 21:12:12 +00:00
|
|
|
/*
|
|
|
|
* ZeroTier One - Network Virtualization Everywhere
|
2016-01-12 22:04:55 +00:00
|
|
|
* Copyright (C) 2011-2016 ZeroTier, Inc. https://www.zerotier.com/
|
2015-10-14 21:12:12 +00:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ZT_CLUSTER_HPP
|
|
|
|
#define ZT_CLUSTER_HPP
|
|
|
|
|
|
|
|
#ifdef ZT_ENABLE_CLUSTER
|
|
|
|
|
2015-11-08 21:57:02 +00:00
|
|
|
#include <map>
|
2015-10-14 21:12:12 +00:00
|
|
|
|
|
|
|
#include "Constants.hpp"
|
2015-10-20 22:27:53 +00:00
|
|
|
#include "../include/ZeroTierOne.h"
|
2015-10-14 21:12:12 +00:00
|
|
|
#include "Address.hpp"
|
|
|
|
#include "InetAddress.hpp"
|
|
|
|
#include "SHA512.hpp"
|
|
|
|
#include "Utils.hpp"
|
|
|
|
#include "Buffer.hpp"
|
|
|
|
#include "Mutex.hpp"
|
2015-10-20 22:27:53 +00:00
|
|
|
#include "SharedPtr.hpp"
|
2015-10-20 23:24:21 +00:00
|
|
|
#include "Hashtable.hpp"
|
2015-11-09 17:14:26 +00:00
|
|
|
#include "Packet.hpp"
|
2015-11-10 17:05:01 +00:00
|
|
|
#include "SharedPtr.hpp"
|
2015-10-14 21:12:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Timeout for cluster members being considered "alive"
|
2015-10-29 17:10:09 +00:00
|
|
|
*
|
|
|
|
* A cluster member is considered dead and will no longer have peers
|
|
|
|
* redirected to it if we have not heard a heartbeat in this long.
|
2015-10-14 21:12:12 +00:00
|
|
|
*/
|
2015-11-09 22:25:28 +00:00
|
|
|
#define ZT_CLUSTER_TIMEOUT 5000
|
2015-10-14 21:12:12 +00:00
|
|
|
|
|
|
|
/**
|
2015-10-20 22:27:53 +00:00
|
|
|
* Desired period between doPeriodicTasks() in milliseconds
|
2015-10-16 19:10:57 +00:00
|
|
|
*/
|
2016-02-08 17:57:46 +00:00
|
|
|
#define ZT_CLUSTER_PERIODIC_TASK_PERIOD 20
|
2015-10-16 19:10:57 +00:00
|
|
|
|
2015-11-02 23:15:20 +00:00
|
|
|
/**
|
|
|
|
* How often to flush outgoing message queues (maximum interval)
|
|
|
|
*/
|
2016-02-08 17:57:46 +00:00
|
|
|
#define ZT_CLUSTER_FLUSH_PERIOD ZT_CLUSTER_PERIODIC_TASK_PERIOD
|
2015-11-02 23:15:20 +00:00
|
|
|
|
2015-11-08 21:57:02 +00:00
|
|
|
/**
|
|
|
|
* Maximum number of queued outgoing packets per sender address
|
|
|
|
*/
|
2016-02-08 17:57:46 +00:00
|
|
|
#define ZT_CLUSTER_MAX_QUEUE_PER_SENDER 16
|
2015-11-08 21:57:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Expiration time for send queue entries
|
|
|
|
*/
|
2016-02-08 17:57:46 +00:00
|
|
|
#define ZT_CLUSTER_QUEUE_EXPIRATION 3000
|
2015-11-08 21:57:02 +00:00
|
|
|
|
2015-11-11 01:37:38 +00:00
|
|
|
/**
|
|
|
|
* Chunk size for allocating queue entries
|
|
|
|
*
|
|
|
|
* Queue entries are allocated in chunks of this many and are added to a pool.
|
|
|
|
* ZT_CLUSTER_MAX_QUEUE_GLOBAL must be evenly divisible by this.
|
|
|
|
*/
|
|
|
|
#define ZT_CLUSTER_QUEUE_CHUNK_SIZE 32
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maximum number of chunks to ever allocate
|
|
|
|
*
|
|
|
|
* This is a global sanity limit to prevent resource exhaustion attacks. It
|
|
|
|
* works out to about 600mb of RAM. You'll never see this on a normal edge
|
|
|
|
* node. We're unlikely to see this on a root server unless someone is DOSing
|
|
|
|
* us. In that case cluster relaying will be affected but other functions
|
|
|
|
* should continue to operate normally.
|
|
|
|
*/
|
|
|
|
#define ZT_CLUSTER_MAX_QUEUE_CHUNKS 8194
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Max data per queue entry
|
|
|
|
*/
|
2016-02-08 17:57:46 +00:00
|
|
|
#define ZT_CLUSTER_SEND_QUEUE_DATA_MAX 1500
|
2015-11-11 01:37:38 +00:00
|
|
|
|
2017-02-01 20:00:25 +00:00
|
|
|
/**
|
|
|
|
* We won't send WANT_PEER to other members more than every (ms) per recipient
|
|
|
|
*/
|
|
|
|
#define ZT_CLUSTER_WANT_PEER_EVERY 1000
|
|
|
|
|
2015-10-14 21:12:12 +00:00
|
|
|
namespace ZeroTier {
|
|
|
|
|
|
|
|
class RuntimeEnvironment;
|
|
|
|
class MulticastGroup;
|
2015-10-20 22:27:53 +00:00
|
|
|
class Peer;
|
|
|
|
class Identity;
|
2015-10-14 21:12:12 +00:00
|
|
|
|
2015-11-10 17:05:01 +00:00
|
|
|
// Internal class implemented inside Cluster.cpp
|
|
|
|
class _ClusterSendQueue;
|
|
|
|
|
2015-10-14 21:12:12 +00:00
|
|
|
/**
|
|
|
|
* Multi-homing cluster state replication and packet relaying
|
|
|
|
*
|
|
|
|
* Multi-homing means more than one node sharing the same ZeroTier identity.
|
|
|
|
* There is nothing in the protocol to prevent this, but to make it work well
|
|
|
|
* requires the devices sharing an identity to cooperate and share some
|
|
|
|
* information.
|
|
|
|
*
|
|
|
|
* There are three use cases we want to fulfill:
|
|
|
|
*
|
|
|
|
* (1) Multi-homing of root servers with handoff for efficient routing,
|
|
|
|
* HA, and load balancing across many commodity nodes.
|
|
|
|
* (2) Multi-homing of network controllers for the same reason.
|
|
|
|
* (3) Multi-homing of nodes on virtual networks, such as domain servers
|
|
|
|
* and other important endpoints.
|
|
|
|
*
|
|
|
|
* These use cases are in order of escalating difficulty. The initial
|
|
|
|
* version of Cluster is aimed at satisfying the first, though you are
|
|
|
|
* free to try #2 and #3.
|
|
|
|
*/
|
|
|
|
class Cluster
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* State message types
|
|
|
|
*/
|
|
|
|
enum StateMessageType
|
|
|
|
{
|
2015-11-08 21:57:02 +00:00
|
|
|
CLUSTER_MESSAGE_NOP = 0,
|
2015-10-14 21:12:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This cluster member is alive:
|
|
|
|
* <[2] version minor>
|
|
|
|
* <[2] version major>
|
|
|
|
* <[2] version revision>
|
|
|
|
* <[1] protocol version>
|
|
|
|
* <[4] X location (signed 32-bit)>
|
|
|
|
* <[4] Y location (signed 32-bit)>
|
|
|
|
* <[4] Z location (signed 32-bit)>
|
|
|
|
* <[8] local clock at this member>
|
|
|
|
* <[8] load average>
|
2015-11-07 00:12:41 +00:00
|
|
|
* <[8] number of peers>
|
2015-10-14 21:12:12 +00:00
|
|
|
* <[8] flags (currently unused, must be zero)>
|
|
|
|
* <[1] number of preferred ZeroTier endpoints>
|
|
|
|
* <[...] InetAddress(es) of preferred ZeroTier endpoint(s)>
|
2015-11-08 21:57:02 +00:00
|
|
|
*
|
|
|
|
* Cluster members constantly broadcast an alive heartbeat and will only
|
|
|
|
* receive peer redirects if they've done so within the timeout.
|
2015-10-14 21:12:12 +00:00
|
|
|
*/
|
2015-11-08 21:57:02 +00:00
|
|
|
CLUSTER_MESSAGE_ALIVE = 1,
|
2015-10-14 21:12:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Cluster member has this peer:
|
2015-11-08 21:57:02 +00:00
|
|
|
* <[...] serialized identity of peer>
|
|
|
|
*
|
|
|
|
* This is typically sent in response to WANT_PEER but can also be pushed
|
|
|
|
* to prepopulate if this makes sense.
|
2015-10-14 21:12:12 +00:00
|
|
|
*/
|
2015-11-08 21:57:02 +00:00
|
|
|
CLUSTER_MESSAGE_HAVE_PEER = 2,
|
2015-10-14 21:12:12 +00:00
|
|
|
|
2015-11-07 00:12:41 +00:00
|
|
|
/**
|
|
|
|
* Cluster member wants this peer:
|
|
|
|
* <[5] ZeroTier address of peer>
|
2015-11-08 21:57:02 +00:00
|
|
|
*
|
|
|
|
* Members that have a direct link to this peer will respond with
|
|
|
|
* HAVE_PEER.
|
2015-11-07 00:12:41 +00:00
|
|
|
*/
|
2015-11-08 21:57:02 +00:00
|
|
|
CLUSTER_MESSAGE_WANT_PEER = 3,
|
2015-10-14 21:12:12 +00:00
|
|
|
|
|
|
|
/**
|
2015-11-08 21:57:02 +00:00
|
|
|
* A remote packet that we should also possibly respond to:
|
|
|
|
* <[2] 16-bit length of remote packet>
|
|
|
|
* <[...] remote packet payload>
|
|
|
|
*
|
|
|
|
* Cluster members may relay requests by relaying the request packet.
|
|
|
|
* These may include requests such as WHOIS and MULTICAST_GATHER. The
|
|
|
|
* packet must be already decrypted, decompressed, and authenticated.
|
|
|
|
*
|
|
|
|
* This can only be used for small request packets as per the cluster
|
|
|
|
* message size limit, but since these are the only ones in question
|
|
|
|
* this is fine.
|
|
|
|
*
|
|
|
|
* If a response is generated it is sent via PROXY_SEND.
|
2015-10-14 21:12:12 +00:00
|
|
|
*/
|
2015-11-08 21:57:02 +00:00
|
|
|
CLUSTER_MESSAGE_REMOTE_PACKET = 4,
|
2015-10-14 21:12:12 +00:00
|
|
|
|
|
|
|
/**
|
2015-10-27 21:04:12 +00:00
|
|
|
* Request that VERB_RENDEZVOUS be sent to a peer that we have:
|
|
|
|
* <[5] ZeroTier address of peer on recipient's side>
|
|
|
|
* <[5] ZeroTier address of peer on sender's side>
|
|
|
|
* <[1] 8-bit number of sender's peer's active path addresses>
|
|
|
|
* <[...] series of serialized InetAddresses of sender's peer's paths>
|
|
|
|
*
|
|
|
|
* This requests that we perform NAT-t introduction between a peer that
|
|
|
|
* we have and one on the sender's side. The sender furnishes contact
|
|
|
|
* info for its peer, and we send VERB_RENDEZVOUS to both sides: to ours
|
|
|
|
* directly and with PROXY_SEND to theirs.
|
2015-10-14 21:12:12 +00:00
|
|
|
*/
|
2015-11-08 21:57:02 +00:00
|
|
|
CLUSTER_MESSAGE_PROXY_UNITE = 5,
|
2015-10-14 21:12:12 +00:00
|
|
|
|
|
|
|
/**
|
2015-10-23 20:03:34 +00:00
|
|
|
* Request that a cluster member send a packet to a locally-known peer:
|
2015-10-14 21:12:12 +00:00
|
|
|
* <[5] ZeroTier address of recipient>
|
|
|
|
* <[1] packet verb>
|
|
|
|
* <[2] length of packet payload>
|
|
|
|
* <[...] packet payload>
|
|
|
|
*
|
|
|
|
* This differs from RELAY in that it requests the receiving cluster
|
|
|
|
* member to actually compose a ZeroTier Packet from itself to the
|
|
|
|
* provided recipient. RELAY simply says "please forward this blob."
|
|
|
|
* RELAY is used to implement peer-to-peer relaying with RENDEZVOUS,
|
|
|
|
* while PROXY_SEND is used to implement proxy sending (which right
|
|
|
|
* now is only used to send RENDEZVOUS).
|
|
|
|
*/
|
2015-11-08 21:57:02 +00:00
|
|
|
CLUSTER_MESSAGE_PROXY_SEND = 6,
|
2015-10-27 17:37:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Replicate a network config for a network we belong to:
|
2017-01-30 23:40:22 +00:00
|
|
|
* <[...] network config chunk>
|
2015-10-27 17:37:39 +00:00
|
|
|
*
|
|
|
|
* This is used by clusters to avoid every member having to query
|
|
|
|
* for the same netconf for networks all members belong to.
|
|
|
|
*
|
2017-01-30 23:40:22 +00:00
|
|
|
* The first field of a network config chunk is the network ID,
|
|
|
|
* so this can be checked to look up the network on receipt.
|
2015-10-27 17:37:39 +00:00
|
|
|
*/
|
2015-11-08 21:57:02 +00:00
|
|
|
CLUSTER_MESSAGE_NETWORK_CONFIG = 7
|
2015-10-14 21:12:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct a new cluster
|
|
|
|
*/
|
|
|
|
Cluster(
|
|
|
|
const RuntimeEnvironment *renv,
|
|
|
|
uint16_t id,
|
2015-10-20 22:27:53 +00:00
|
|
|
const std::vector<InetAddress> &zeroTierPhysicalEndpoints,
|
2015-10-14 21:12:12 +00:00
|
|
|
int32_t x,
|
|
|
|
int32_t y,
|
|
|
|
int32_t z,
|
2015-10-20 22:27:53 +00:00
|
|
|
void (*sendFunction)(void *,unsigned int,const void *,unsigned int),
|
|
|
|
void *sendFunctionArg,
|
|
|
|
int (*addressToLocationFunction)(void *,const struct sockaddr_storage *,int *,int *,int *),
|
|
|
|
void *addressToLocationFunctionArg);
|
2015-10-14 21:12:12 +00:00
|
|
|
|
|
|
|
~Cluster();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return This cluster member's ID
|
|
|
|
*/
|
|
|
|
inline uint16_t id() const throw() { return _id; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle an incoming intra-cluster message
|
|
|
|
*
|
|
|
|
* @param data Message data
|
|
|
|
* @param len Message length (max: ZT_CLUSTER_MAX_MESSAGE_LENGTH)
|
|
|
|
*/
|
|
|
|
void handleIncomingStateMessage(const void *msg,unsigned int len);
|
|
|
|
|
2015-11-10 02:01:23 +00:00
|
|
|
/**
|
|
|
|
* Broadcast that we have a given peer
|
|
|
|
*
|
|
|
|
* This should be done when new peers are first contacted.
|
|
|
|
*
|
|
|
|
* @param id Identity of peer
|
|
|
|
*/
|
|
|
|
void broadcastHavePeer(const Identity &id);
|
|
|
|
|
2017-01-30 23:40:22 +00:00
|
|
|
/**
|
|
|
|
* Broadcast a network config chunk to other members of cluster
|
|
|
|
*
|
|
|
|
* @param chunk Chunk data
|
|
|
|
* @param len Length of chunk
|
|
|
|
*/
|
|
|
|
void broadcastNetworkConfigChunk(const void *chunk,unsigned int len);
|
|
|
|
|
2015-10-21 00:22:53 +00:00
|
|
|
/**
|
2017-02-01 20:00:25 +00:00
|
|
|
* If the cluster has this peer, prepare the packet to send via cluster
|
|
|
|
*
|
|
|
|
* Note that outp is only armored (or modified at all) if the return value is a member ID.
|
|
|
|
*
|
|
|
|
* @param toPeerAddress Value of outp.destination(), simply to save additional lookup
|
2017-02-01 21:20:51 +00:00
|
|
|
* @param ts Result: set to time of last HAVE_PEER from the cluster
|
|
|
|
* @param peerSecret Result: Buffer to fill with peer secret on valid return value, must be at least ZT_PEER_SECRET_KEY_LENGTH bytes
|
2017-02-01 20:00:25 +00:00
|
|
|
* @return -1 if cluster does not know this peer, or a member ID to pass to sendViaCluster()
|
|
|
|
*/
|
2017-02-01 21:52:53 +00:00
|
|
|
int checkSendViaCluster(const Address &toPeerAddress,uint64_t &mostRecentTs,void *peerSecret);
|
2017-02-01 20:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Send data via cluster front plane (packet head or fragment)
|
|
|
|
*
|
|
|
|
* @param haveMemberId Member ID that has this peer as returned by prepSendviaCluster()
|
|
|
|
* @param toPeerAddress Destination peer address
|
|
|
|
* @param data Packet or packet fragment data
|
|
|
|
* @param len Length of packet or fragment
|
|
|
|
* @return True if packet was sent (and outp was modified via armoring)
|
|
|
|
*/
|
|
|
|
bool sendViaCluster(int haveMemberId,const Address &toPeerAddress,const void *data,unsigned int len);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Relay a packet via the cluster
|
2015-10-21 00:22:53 +00:00
|
|
|
*
|
2015-11-08 21:57:02 +00:00
|
|
|
* This is used in the outgoing packet and relaying logic in Switch to
|
|
|
|
* relay packets to other cluster members. It isn't PROXY_SEND-- that is
|
|
|
|
* used internally in Cluster to send responses to peer queries.
|
|
|
|
*
|
2015-10-21 00:22:53 +00:00
|
|
|
* @param fromPeerAddress Source peer address (if known, should be NULL for fragments)
|
|
|
|
* @param toPeerAddress Destination peer address
|
|
|
|
* @param data Packet or packet fragment data
|
|
|
|
* @param len Length of packet or fragment
|
2015-10-27 21:04:12 +00:00
|
|
|
* @param unite If true, also request proxy unite across cluster
|
2015-10-14 21:12:12 +00:00
|
|
|
*/
|
2017-02-01 20:00:25 +00:00
|
|
|
void relayViaCluster(const Address &fromPeerAddress,const Address &toPeerAddress,const void *data,unsigned int len,bool unite);
|
2015-10-14 21:12:12 +00:00
|
|
|
|
|
|
|
/**
|
2015-11-08 21:57:02 +00:00
|
|
|
* Send a distributed query to other cluster members
|
2015-10-14 21:12:12 +00:00
|
|
|
*
|
2015-11-08 21:57:02 +00:00
|
|
|
* Some queries such as WHOIS or MULTICAST_GATHER need a response from other
|
|
|
|
* cluster members. Replies (if any) will be sent back to the peer via
|
|
|
|
* PROXY_SEND across the cluster.
|
2015-10-14 21:12:12 +00:00
|
|
|
*
|
2015-11-08 21:57:02 +00:00
|
|
|
* @param pkt Packet to distribute
|
2015-10-14 21:12:12 +00:00
|
|
|
*/
|
2015-11-08 21:57:02 +00:00
|
|
|
void sendDistributedQuery(const Packet &pkt);
|
2015-10-14 21:12:12 +00:00
|
|
|
|
|
|
|
/**
|
2015-10-20 22:27:53 +00:00
|
|
|
* Call every ~ZT_CLUSTER_PERIODIC_TASK_PERIOD milliseconds.
|
2015-10-14 21:12:12 +00:00
|
|
|
*/
|
|
|
|
void doPeriodicTasks();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a member ID to this cluster
|
|
|
|
*
|
|
|
|
* @param memberId Member ID
|
|
|
|
*/
|
|
|
|
void addMember(uint16_t memberId);
|
|
|
|
|
2015-10-20 22:27:53 +00:00
|
|
|
/**
|
|
|
|
* Remove a member ID from this cluster
|
|
|
|
*
|
|
|
|
* @param memberId Member ID to remove
|
|
|
|
*/
|
|
|
|
void removeMember(uint16_t memberId);
|
|
|
|
|
|
|
|
/**
|
2015-10-27 21:37:38 +00:00
|
|
|
* Find a better cluster endpoint for this peer (if any)
|
2015-10-27 16:36:48 +00:00
|
|
|
*
|
2015-10-27 21:37:38 +00:00
|
|
|
* @param redirectTo InetAddress to be set to a better endpoint (if there is one)
|
2015-10-27 16:36:48 +00:00
|
|
|
* @param peerAddress Address of peer to (possibly) redirect
|
2015-10-20 22:27:53 +00:00
|
|
|
* @param peerPhysicalAddress Physical address of peer's current best path (where packet was most recently received or getBestPath()->address())
|
|
|
|
* @param offload Always redirect if possible -- can be used to offload peers during shutdown
|
2015-10-27 21:37:38 +00:00
|
|
|
* @return True if redirectTo was set to a new address, false if redirectTo was not modified
|
2015-10-20 22:27:53 +00:00
|
|
|
*/
|
2015-10-27 21:37:38 +00:00
|
|
|
bool findBetterEndpoint(InetAddress &redirectTo,const Address &peerAddress,const InetAddress &peerPhysicalAddress,bool offload);
|
2015-10-20 22:27:53 +00:00
|
|
|
|
2017-02-01 22:18:56 +00:00
|
|
|
/**
|
|
|
|
* @param ip Address to check
|
|
|
|
* @return True if this is a cluster frontplane address (excluding our addresses)
|
|
|
|
*/
|
|
|
|
bool isClusterPeerFrontplane(const InetAddress &ip) const;
|
|
|
|
|
2015-10-26 19:41:08 +00:00
|
|
|
/**
|
|
|
|
* Fill out ZT_ClusterStatus structure (from core API)
|
|
|
|
*
|
|
|
|
* @param status Reference to structure to hold result (anything there is replaced)
|
|
|
|
*/
|
|
|
|
void status(ZT_ClusterStatus &status) const;
|
|
|
|
|
2015-10-14 21:12:12 +00:00
|
|
|
private:
|
2015-10-20 23:24:21 +00:00
|
|
|
void _send(uint16_t memberId,StateMessageType type,const void *msg,unsigned int len);
|
2015-10-14 21:12:12 +00:00
|
|
|
void _flush(uint16_t memberId);
|
|
|
|
|
2015-11-08 21:57:02 +00:00
|
|
|
void _doREMOTE_WHOIS(uint64_t fromMemberId,const Packet &remotep);
|
|
|
|
void _doREMOTE_MULTICAST_GATHER(uint64_t fromMemberId,const Packet &remotep);
|
|
|
|
|
2015-11-10 17:05:01 +00:00
|
|
|
// These are initialized in the constructor and remain immutable ------------
|
2015-10-14 21:12:12 +00:00
|
|
|
uint16_t _masterSecret[ZT_SHA512_DIGEST_LEN / sizeof(uint16_t)];
|
|
|
|
unsigned char _key[ZT_PEER_SECRET_KEY_LENGTH];
|
|
|
|
const RuntimeEnvironment *RR;
|
2015-11-10 17:05:01 +00:00
|
|
|
_ClusterSendQueue *const _sendQueue;
|
2015-10-20 22:27:53 +00:00
|
|
|
void (*_sendFunction)(void *,unsigned int,const void *,unsigned int);
|
|
|
|
void *_sendFunctionArg;
|
|
|
|
int (*_addressToLocationFunction)(void *,const struct sockaddr_storage *,int *,int *,int *);
|
|
|
|
void *_addressToLocationFunctionArg;
|
2015-10-14 21:12:12 +00:00
|
|
|
const int32_t _x;
|
|
|
|
const int32_t _y;
|
|
|
|
const int32_t _z;
|
|
|
|
const uint16_t _id;
|
2015-10-20 22:27:53 +00:00
|
|
|
const std::vector<InetAddress> _zeroTierPhysicalEndpoints;
|
2015-11-10 17:05:01 +00:00
|
|
|
// end immutable fields -----------------------------------------------------
|
2015-10-14 21:12:12 +00:00
|
|
|
|
|
|
|
struct _Member
|
|
|
|
{
|
|
|
|
unsigned char key[ZT_PEER_SECRET_KEY_LENGTH];
|
|
|
|
|
|
|
|
uint64_t lastReceivedAliveAnnouncement;
|
|
|
|
uint64_t lastAnnouncedAliveTo;
|
|
|
|
|
|
|
|
uint64_t load;
|
2015-11-07 00:12:41 +00:00
|
|
|
uint64_t peers;
|
2015-10-14 21:12:12 +00:00
|
|
|
int32_t x,y,z;
|
|
|
|
|
2015-10-20 22:27:53 +00:00
|
|
|
std::vector<InetAddress> zeroTierPhysicalEndpoints;
|
2015-10-14 21:12:12 +00:00
|
|
|
|
|
|
|
Buffer<ZT_CLUSTER_MAX_MESSAGE_LENGTH> q;
|
|
|
|
|
|
|
|
Mutex lock;
|
|
|
|
|
2015-10-20 22:27:53 +00:00
|
|
|
inline void clear()
|
|
|
|
{
|
|
|
|
lastReceivedAliveAnnouncement = 0;
|
|
|
|
lastAnnouncedAliveTo = 0;
|
|
|
|
load = 0;
|
2015-11-07 00:12:41 +00:00
|
|
|
peers = 0;
|
2015-10-20 22:27:53 +00:00
|
|
|
x = 0;
|
|
|
|
y = 0;
|
|
|
|
z = 0;
|
|
|
|
zeroTierPhysicalEndpoints.clear();
|
|
|
|
q.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
_Member() { this->clear(); }
|
2015-10-14 21:12:12 +00:00
|
|
|
~_Member() { Utils::burn(key,sizeof(key)); }
|
|
|
|
};
|
2015-10-27 22:57:26 +00:00
|
|
|
_Member *const _members;
|
2015-10-14 21:12:12 +00:00
|
|
|
|
|
|
|
std::vector<uint16_t> _memberIds;
|
|
|
|
Mutex _memberIds_m;
|
|
|
|
|
2017-02-01 20:00:25 +00:00
|
|
|
struct _RemotePeer
|
|
|
|
{
|
|
|
|
_RemotePeer() : lastHavePeerReceived(0),lastSentWantPeer(0) {}
|
|
|
|
~_RemotePeer() { Utils::burn(key,ZT_PEER_SECRET_KEY_LENGTH); }
|
|
|
|
uint64_t lastHavePeerReceived;
|
|
|
|
uint64_t lastSentWantPeer;
|
|
|
|
uint8_t key[ZT_PEER_SECRET_KEY_LENGTH]; // secret key from identity agreement
|
|
|
|
};
|
|
|
|
std::map< std::pair<Address,unsigned int>,_RemotePeer > _remotePeers; // we need ordered behavior and lower_bound here
|
2015-11-08 21:57:02 +00:00
|
|
|
Mutex _remotePeers_m;
|
|
|
|
|
2015-11-02 23:15:20 +00:00
|
|
|
uint64_t _lastFlushed;
|
2015-11-08 21:57:02 +00:00
|
|
|
uint64_t _lastCleanedRemotePeers;
|
2015-11-10 17:05:01 +00:00
|
|
|
uint64_t _lastCleanedQueue;
|
2015-10-14 21:12:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace ZeroTier
|
|
|
|
|
|
|
|
#endif // ZT_ENABLE_CLUSTER
|
|
|
|
|
|
|
|
#endif
|