mirror of
https://github.com/ZeroTier/ZeroTierOne
synced 2025-08-20 21:33:57 -07:00
Add some also-ZeroTier-written ext/ code for use in new clustering, delete some old code, and change Mac to use -Os which is just as fast as -Ofast and may be faster due to cache effects.
This commit is contained in:
parent
2ec88e8008
commit
2a4a50b1da
14 changed files with 2396 additions and 263 deletions
|
@ -157,21 +157,6 @@ extern "C" {
|
|||
*/
|
||||
#define ZT_CIRCUIT_TEST_REPORT_FLAGS_UPSTREAM_AUTHORIZED_IN_PATH 0x0000000000000001ULL
|
||||
|
||||
/**
|
||||
* Maximum number of cluster members (and max member ID plus one)
|
||||
*/
|
||||
#define ZT_CLUSTER_MAX_MEMBERS 128
|
||||
|
||||
/**
|
||||
* Maximum number of physical ZeroTier addresses a cluster member can report
|
||||
*/
|
||||
#define ZT_CLUSTER_MAX_ZT_PHYSICAL_ADDRESSES 16
|
||||
|
||||
/**
|
||||
* Maximum allowed cluster message length in bytes
|
||||
*/
|
||||
#define ZT_CLUSTER_MAX_MESSAGE_LENGTH (1500 - 48)
|
||||
|
||||
/**
|
||||
* Maximum value for link quality (min is 0)
|
||||
*/
|
||||
|
@ -1104,78 +1089,6 @@ typedef struct
|
|||
unsigned long peerCount;
|
||||
} ZT_PeerList;
|
||||
|
||||
/**
|
||||
* A cluster member's status
|
||||
*/
|
||||
typedef struct {
|
||||
/**
|
||||
* This cluster member's ID (from 0 to 1-ZT_CLUSTER_MAX_MEMBERS)
|
||||
*/
|
||||
unsigned int id;
|
||||
|
||||
/**
|
||||
* Number of milliseconds since last 'alive' heartbeat message received via cluster backplane address
|
||||
*/
|
||||
unsigned int msSinceLastHeartbeat;
|
||||
|
||||
/**
|
||||
* Non-zero if cluster member is alive
|
||||
*/
|
||||
int alive;
|
||||
|
||||
/**
|
||||
* X, Y, and Z coordinates of this member (if specified, otherwise zero)
|
||||
*
|
||||
* What these mean depends on the location scheme being used for
|
||||
* location-aware clustering. At present this is GeoIP and these
|
||||
* will be the X, Y, and Z coordinates of the location on a spherical
|
||||
* approximation of Earth where Earth's core is the origin (in km).
|
||||
* They don't have to be perfect and need only be comparable with others
|
||||
* to find shortest path via the standard vector distance formula.
|
||||
*/
|
||||
int x,y,z;
|
||||
|
||||
/**
|
||||
* Cluster member's last reported load
|
||||
*/
|
||||
uint64_t load;
|
||||
|
||||
/**
|
||||
* Number of peers
|
||||
*/
|
||||
uint64_t peers;
|
||||
|
||||
/**
|
||||
* Physical ZeroTier endpoints for this member (where peers are sent when directed here)
|
||||
*/
|
||||
struct sockaddr_storage zeroTierPhysicalEndpoints[ZT_CLUSTER_MAX_ZT_PHYSICAL_ADDRESSES];
|
||||
|
||||
/**
|
||||
* Number of physical ZeroTier endpoints this member is announcing
|
||||
*/
|
||||
unsigned int numZeroTierPhysicalEndpoints;
|
||||
} ZT_ClusterMemberStatus;
|
||||
|
||||
/**
|
||||
* ZeroTier cluster status
|
||||
*/
|
||||
typedef struct {
|
||||
/**
|
||||
* My cluster member ID (a record for 'self' is included in member[])
|
||||
*/
|
||||
unsigned int myId;
|
||||
|
||||
/**
|
||||
* Number of cluster members
|
||||
*/
|
||||
unsigned int clusterSize;
|
||||
|
||||
/**
|
||||
* Cluster member statuses
|
||||
*/
|
||||
ZT_ClusterMemberStatus members[ZT_CLUSTER_MAX_MEMBERS];
|
||||
} ZT_ClusterStatus;
|
||||
|
||||
/**
|
||||
* An instance of a ZeroTier One node (opaque)
|
||||
*/
|
||||
|
@ -1765,116 +1678,6 @@ int ZT_Node_sendUserMessage(ZT_Node *node,void *tptr,uint64_t dest,uint64_t type
|
|||
*/
|
||||
void ZT_Node_setNetconfMaster(ZT_Node *node,void *networkConfigMasterInstance);
|
||||
|
||||
/**
|
||||
* Initialize cluster operation
|
||||
*
|
||||
* This initializes the internal structures and state for cluster operation.
|
||||
* It takes two function pointers. The first is to a function that can be
|
||||
* used to send data to cluster peers (mechanism is not defined by Node),
|
||||
* and the second is to a function that can be used to get the location of
|
||||
* a physical address in X,Y,Z coordinate space (e.g. as cartesian coordinates
|
||||
* projected from the center of the Earth).
|
||||
*
|
||||
* Send function takes an arbitrary pointer followed by the cluster member ID
|
||||
* to send data to, a pointer to the data, and the length of the data. The
|
||||
* maximum message length is ZT_CLUSTER_MAX_MESSAGE_LENGTH (65535). Messages
|
||||
* must be delivered whole and may be dropped or transposed, though high
|
||||
* failure rates are undesirable and can cause problems. Validity checking or
|
||||
* CRC is also not required since the Node validates the authenticity of
|
||||
* cluster messages using cryptogrphic methods and will silently drop invalid
|
||||
* messages.
|
||||
*
|
||||
* Address to location function is optional and if NULL geo-handoff is not
|
||||
* enabled (in this case x, y, and z in clusterInit are also unused). It
|
||||
* takes an arbitrary pointer followed by a physical address and three result
|
||||
* parameters for x, y, and z. It returns zero on failure or nonzero if these
|
||||
* three coordinates have been set. Coordinate space is arbitrary and can be
|
||||
* e.g. coordinates on Earth relative to Earth's center. These can be obtained
|
||||
* from latitutde and longitude with versions of the Haversine formula.
|
||||
*
|
||||
* See: http://stackoverflow.com/questions/1185408/converting-from-longitude-latitude-to-cartesian-coordinates
|
||||
*
|
||||
* Neither the send nor the address to location function should block. If the
|
||||
* address to location function does not have a location for an address, it
|
||||
* should return zero and then look up the address for future use since it
|
||||
* will be called again in (typically) 1-3 minutes.
|
||||
*
|
||||
* Note that both functions can be called from any thread from which the
|
||||
* various Node functions are called, and so must be thread safe if multiple
|
||||
* threads are being used.
|
||||
*
|
||||
* @param node Node instance
|
||||
* @param myId My cluster member ID (less than or equal to ZT_CLUSTER_MAX_MEMBERS)
|
||||
* @param zeroTierPhysicalEndpoints Preferred physical address(es) for ZeroTier clients to contact this cluster member (for peer redirect)
|
||||
* @param numZeroTierPhysicalEndpoints Number of physical endpoints in zeroTierPhysicalEndpoints[] (max allowed: 255)
|
||||
* @param x My cluster member's X location
|
||||
* @param y My cluster member's Y location
|
||||
* @param z My cluster member's Z location
|
||||
* @param sendFunction Function to be called to send data to other cluster members
|
||||
* @param sendFunctionArg First argument to sendFunction()
|
||||
* @param addressToLocationFunction Function to be called to get the location of a physical address or NULL to disable geo-handoff
|
||||
* @param addressToLocationFunctionArg First argument to addressToLocationFunction()
|
||||
* @return OK or UNSUPPORTED_OPERATION if this Node was not built with cluster support
|
||||
*/
|
||||
enum ZT_ResultCode ZT_Node_clusterInit(
|
||||
ZT_Node *node,
|
||||
unsigned int myId,
|
||||
const struct sockaddr_storage *zeroTierPhysicalEndpoints,
|
||||
unsigned int numZeroTierPhysicalEndpoints,
|
||||
int x,
|
||||
int y,
|
||||
int z,
|
||||
void (*sendFunction)(void *,unsigned int,const void *,unsigned int),
|
||||
void *sendFunctionArg,
|
||||
int (*addressToLocationFunction)(void *,const struct sockaddr_storage *,int *,int *,int *),
|
||||
void *addressToLocationFunctionArg);
|
||||
|
||||
/**
|
||||
* Add a member to this cluster
|
||||
*
|
||||
* Calling this without having called clusterInit() will do nothing.
|
||||
*
|
||||
* @param node Node instance
|
||||
* @param memberId Member ID (must be less than or equal to ZT_CLUSTER_MAX_MEMBERS)
|
||||
* @return OK or error if clustering is disabled, ID invalid, etc.
|
||||
*/
|
||||
enum ZT_ResultCode ZT_Node_clusterAddMember(ZT_Node *node,unsigned int memberId);
|
||||
|
||||
/**
|
||||
* Remove a member from this cluster
|
||||
*
|
||||
* Calling this without having called clusterInit() will do nothing.
|
||||
*
|
||||
* @param node Node instance
|
||||
* @param memberId Member ID to remove (nothing happens if not present)
|
||||
*/
|
||||
void ZT_Node_clusterRemoveMember(ZT_Node *node,unsigned int memberId);
|
||||
|
||||
/**
|
||||
* Handle an incoming cluster state message
|
||||
*
|
||||
* The message itself contains cluster member IDs, and invalid or badly
|
||||
* addressed messages will be silently discarded.
|
||||
*
|
||||
* Calling this without having called clusterInit() will do nothing.
|
||||
*
|
||||
* @param node Node instance
|
||||
* @param msg Cluster message
|
||||
* @param len Length of cluster message
|
||||
*/
|
||||
void ZT_Node_clusterHandleIncomingMessage(ZT_Node *node,const void *msg,unsigned int len);
|
||||
|
||||
/**
|
||||
* Get the current status of the cluster from this node's point of view
|
||||
*
|
||||
* Calling this without clusterInit() or without cluster support will just
|
||||
* zero out the structure and show a cluster size of zero.
|
||||
*
|
||||
* @param node Node instance
|
||||
* @param cs Cluster status structure to fill with data
|
||||
*/
|
||||
void ZT_Node_clusterStatus(ZT_Node *node,ZT_ClusterStatus *cs);
|
||||
|
||||
/**
|
||||
* Set trusted paths
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue