summaryrefslogtreecommitdiff
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/zerotier/sdk/Node.java43
-rw-r--r--java/src/com/zerotier/sdk/PathChecker.java45
2 files changed, 87 insertions, 1 deletions
diff --git a/java/src/com/zerotier/sdk/Node.java b/java/src/com/zerotier/sdk/Node.java
index 4bc6e184..8e7d44e7 100644
--- a/java/src/com/zerotier/sdk/Node.java
+++ b/java/src/com/zerotier/sdk/Node.java
@@ -74,6 +74,7 @@ public class Node {
private final EventListener eventListener;
private final VirtualNetworkFrameListener frameListener;
private final VirtualNetworkConfigListener configListener;
+ private final PathChecker pathChecker;
/**
* Create a new ZeroTier One node
@@ -88,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,
@@ -95,7 +97,8 @@ public class Node {
PacketSender sender,
EventListener eventListener,
VirtualNetworkFrameListener frameListener,
- VirtualNetworkConfigListener configListener) throws NodeException
+ VirtualNetworkConfigListener configListener,
+ PathChecker pathChecker) throws NodeException
{
this.nodeId = now;
@@ -105,6 +108,7 @@ public class Node {
this.eventListener = eventListener;
this.frameListener = frameListener;
this.configListener = configListener;
+ this.pathChecker = pathChecker;
ResultCode rc = node_init(now);
if(rc != ResultCode.RESULT_OK)
@@ -319,6 +323,34 @@ public class Node {
}
/**
+ * 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
*
* @return ZeroTier address (least significant 40 bits of 64-bit int)
@@ -420,6 +452,15 @@ public class Node {
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);
diff --git a/java/src/com/zerotier/sdk/PathChecker.java b/java/src/com/zerotier/sdk/PathChecker.java
new file mode 100644
index 00000000..3e02f112
--- /dev/null
+++ b/java/src/com/zerotier/sdk/PathChecker.java
@@ -0,0 +1,45 @@
+/*
+ * ZeroTier One - Network Virtualization Everywhere
+ * Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/
+ */
+
+package com.zerotier.sdk;
+
+import java.net.InetSocketAddress;
+
+public interface PathChecker {
+ /**
+ * Callback to check whether a path should be used for ZeroTier traffic
+ *
+ * This function must return true if the path should be used.
+ *
+ * If no path check function is specified, ZeroTier will still exclude paths
+ * that overlap with ZeroTier-assigned and managed IP address blocks. But the
+ * use of a path check function is recommended to ensure that recursion does
+ * not occur in cases where addresses are assigned by the OS or managed by
+ * an out of band mechanism like DHCP. The path check function should examine
+ * all configured ZeroTier interfaces and check to ensure that the supplied
+ * addresses will not result in ZeroTier traffic being sent over a ZeroTier
+ * interface (recursion).
+ *
+ * Obviously this is not required in configurations where this can't happen,
+ * such as network containers or embedded.
+ *
+ * @param ztAddress ZeroTier address or 0 for none/any
+ * @param localAddress Local interface address
+ * @param remoteAddress remote address
+ */
+ boolean onPathCheck(long ztAddress, InetSocketAddress localAddress, InetSocketAddress remoteAddress);
+
+ /**
+ * Function to get physical addresses for ZeroTier peers
+ *
+ * If provided this function will be occasionally called to get physical
+ * addresses that might be tried to reach a ZeroTier address.
+ *
+ * @param ztAddress ZeroTier address (least significant 40 bits)
+ * @param ss_family desired address family or -1 for any
+ * @return address and port of ztAddress or null
+ */
+ InetSocketAddress onPathLookup(long ztAddress, int ss_family);
+}