Skip to content

Commit

Permalink
added orbit/deorbit methods to java Node implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
glimberg committed Mar 29, 2017
1 parent 1c5fdb8 commit 5f611da
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
48 changes: 48 additions & 0 deletions java/jni/com_zerotierone_sdk_Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,54 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_multicastUnsubscribe(
return createResultObject(env, rc);
}

/*
* Class: com_zerotier_sdk_Node
* Method: orbit
* Signature: (JJJ)Lcom/zerotier/sdk/ResultCode;
*/
JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_orbit(
JNIEnv *env, jobject obj,
jlong id,
jlong in_moonWorldId,
jlong in_moonSeed)
{
uint64_t nodeId = (uint64_t)id;
ZT_Node *node = findNode(nodeId);
if(node == NULL)
{
return createResultObject(env, ZT_RESULT_FATAL_ERROR_INTERNAL);
}

uint64_t moonWorldId = (uint64_t)in_moonWorldId;
uint64_t moonSeed = (uint64_t)in_moonSeed;

ZT_ResultCode rc = ZT_Node_orbit(node, NULL, moonWorldId, moonSeed);
return createResultObject(env, rc);
}

/*
* Class: com_zerotier_sdk_Node
* Method: deorbit
* Signature: (JJ)L/com/zerotier/sdk/ResultCode;
*/
JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_deorbit(
JNIEnv *env, jobject obj,
jlong id,
jlong in_moonWorldId)
{
uint64_t nodeId = (uint64_t)id;
ZT_Node *node = findNode(nodeId);
if(node == NULL)
{
return createResultObject(env, ZT_RESULT_FATAL_ERROR_INTERNAL);
}

uint64_t moonWorldId = (uint64_t)in_moonWorldId;

ZT_ResultCode rc = ZT_Node_deorbit(node, NULL, moonWorldId);
return createResultObject(env, rc);
}

/*
* Class: com_zerotier_sdk_Node
* Method: address
Expand Down
38 changes: 38 additions & 0 deletions java/src/com/zerotier/sdk/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public class Node {
* @param eventListener User written instance of the {@link EventListener} interface to receive status updates and non-fatal error notices. This instance must be unique per Node object.
* @param frameListener
* @param configListener User written instance of the {@link VirtualNetworkConfigListener} interface to be called when virtual LANs are created, deleted, or their config parameters change. This instance must be unique per Node object.
* @param pathChecker User written instance of the {@link PathChecker} interface. Not required and can be null.
*/
public Node(long now,
DataStoreGetListener getListener,
Expand Down Expand Up @@ -321,6 +322,34 @@ public ResultCode multicastUnsubscribe(
return multicastUnsubscribe(nodeId, nwid, multicastGroup, multicastAdi);
}

/**
* Add or update a moon
*
* Moons are persisted in the data store in moons.d/, so this can persist
* across invocations if the contents of moon.d are scanned and orbit is
* called for each on startup.
*
* @param moonWorldId Moon's world ID
* @param moonSeed If non-zero, the ZeroTier address of any member of the moon to query for moon definition
* @return Error if moon was invalid or failed to be added
*/
public ResultCode orbit(
long moonWorldId,
long moonSeed) {
return orbit(nodeId, moonWorldId, moonSeed);
}

/**
* Remove a moon (does nothing if not present)
*
* @param moonWorldId World ID of moon to remove
* @return Error if anything bad happened
*/
public ResultCode deorbit(
long moonWorldId) {
return deorbit(nodeId, moonWorldId);
}

/**
* Get this node's 40-bit ZeroTier address
*
Expand Down Expand Up @@ -423,6 +452,15 @@ private native ResultCode multicastUnsubscribe(
long multicastGroup,
long multicastAdi);

private native ResultCode orbit(
long nodeId,
long moonWorldId,
long moonSeed);

private native ResultCode deorbit(
long nodeId,
long moonWorldId);

private native long address(long nodeId);

private native NodeStatus status(long nodeId);
Expand Down

0 comments on commit 5f611da

Please sign in to comment.