mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-16 14:18:24 +00:00
1.10.4 merge into main (#1893)
* add note about forceTcpRelay
* Create a sample systemd unit for tcp proxy
* set gitattributes for rust & cargo so hashes dont conflict on Windows
* Revert "set gitattributes for rust & cargo so hashes dont conflict on Windows"
This reverts commit 032dc5c108
.
* Turn off autocrlf for rust source
Doesn't appear to play nice well when it comes to git and vendored cargo package hashes
* Fix #1883 (#1886)
Still unknown as to why, but the call to `nc->GetProperties()` can fail
when setting a friendly name on the Windows virtual ethernet adapter.
Ensure that `ncp` is not null before continuing and accessing the device
GUID.
* Don't vendor packages for zeroidc (#1885)
* Added docker environment way to join networks (#1871)
* add StringUtils
* fix headers
use recommended headers and remove unused headers
* move extern "C"
only JNI functions need to be exported
* cleanup
* fix ANDROID-50: RESULT_ERROR_BAD_PARAMETER typo
* fix typo in log message
* fix typos in JNI method signatures
* fix typo
* fix ANDROID-51: fieldName is uninitialized
* fix ANDROID-35: memory leak
* fix missing DeleteLocalRef in loops
* update to use unique error codes
* add GETENV macro
* add LOG_TAG defines
* ANDROID-48: add ZT_jnicache.cpp
* ANDROID-48: use ZT_jnicache.cpp and remove ZT_jnilookup.cpp and ZT_jniarray.cpp
* add Event.fromInt
* add PeerRole.fromInt
* add ResultCode.fromInt
* fix ANDROID-36: issues with ResultCode
* add VirtualNetworkConfigOperation.fromInt
* fix ANDROID-40: VirtualNetworkConfigOperation out-of-sync with ZT_VirtualNetworkConfigOperation enum
* add VirtualNetworkStatus.fromInt
* fix ANDROID-37: VirtualNetworkStatus out-of-sync with ZT_VirtualNetworkStatus enum
* add VirtualNetworkType.fromInt
* make NodeStatus a plain data class
* fix ANDROID-52: synchronization bug with nodeMap
* Node init work: separate Node construction and init
* add Node.toString
* make PeerPhysicalPath a plain data class
* remove unused PeerPhysicalPath.fixed
* add array functions
* make Peer a plain data class
* make Version a plain data class
* fix ANDROID-42: copy/paste error
* fix ANDROID-49: VirtualNetworkConfig.equals is wrong
* reimplement VirtualNetworkConfig.equals
* reimplement VirtualNetworkConfig.compareTo
* add VirtualNetworkConfig.hashCode
* make VirtualNetworkConfig a plain data class
* remove unused VirtualNetworkConfig.enabled
* reimplement VirtualNetworkDNS.equals
* add VirtualNetworkDNS.hashCode
* make VirtualNetworkDNS a plain data class
* reimplement VirtualNetworkRoute.equals
* reimplement VirtualNetworkRoute.compareTo
* reimplement VirtualNetworkRoute.toString
* add VirtualNetworkRoute.hashCode
* make VirtualNetworkRoute a plain data class
* add isSocketAddressEmpty
* add addressPort
* add fromSocketAddressObject
* invert logic in a couple of places and return early
* newInetAddress and newInetSocketAddress work
allow newInetSocketAddress to return NULL if given empty address
* fix ANDROID-38: stack corruption in onSendPacketRequested
* use GETENV macro
* JniRef work
JniRef does not use callbacks struct, so remove
fix NewGlobalRef / DeleteGlobalRef mismatch
* use PRId64 macros
* switch statement work
* comments and logging
* Modifier 'public' is redundant for interface members
* NodeException can be made a checked Exception
* 'NodeException' does not define a 'serialVersionUID' field
* 'finalize()' should not be overridden
this is fine to do because ZeroTierOneService calls close() when it is done
* error handling, error reporting, asserts, logging
* simplify loadLibrary
* rename Node.networks -> Node.networkConfigs
* Windows file permissions fix (#1887)
* Allow macOS interfaces to use multiple IP addresses (#1879)
Co-authored-by: Sean OMeara <someara@users.noreply.github.com>
Co-authored-by: Grant Limberg <glimberg@users.noreply.github.com>
* Fix condition where full HELLOs might not be sent when necessary (#1877)
Co-authored-by: Grant Limberg <glimberg@users.noreply.github.com>
* 1.10.4 version bumps
* Add security policy to repo (#1889)
* [+] add e2k64 arch (#1890)
* temp fix for ANDROID-56: crash inside newNetworkConfig from too many args
* 1.10.4 release notes
---------
Co-authored-by: travis laduke <travisladuke@gmail.com>
Co-authored-by: Grant Limberg <grant.limberg@zerotier.com>
Co-authored-by: Grant Limberg <glimberg@users.noreply.github.com>
Co-authored-by: Leonardo Amaral <leleobhz@users.noreply.github.com>
Co-authored-by: Brenton Bostick <bostick@gmail.com>
Co-authored-by: Sean OMeara <someara@users.noreply.github.com>
Co-authored-by: Joseph Henry <joseph-henry@users.noreply.github.com>
Co-authored-by: Roman Peshkichev <roman.peshkichev@gmail.com>
This commit is contained in:
@ -24,6 +24,7 @@
|
||||
* redistribute it in a modified binary form, please contact ZeroTier Networks
|
||||
* LLC. Start here: http://www.zerotier.com/
|
||||
*/
|
||||
|
||||
package com.zerotier.sdk;
|
||||
|
||||
public interface DataStoreGetListener {
|
||||
@ -48,7 +49,7 @@ public interface DataStoreGetListener {
|
||||
* @param out_buffer buffer to put the object in
|
||||
* @return size of the object
|
||||
*/
|
||||
public long onDataStoreGet(
|
||||
long onDataStoreGet(
|
||||
String name,
|
||||
byte[] out_buffer);
|
||||
}
|
||||
|
@ -24,6 +24,7 @@
|
||||
* redistribute it in a modified binary form, please contact ZeroTier Networks
|
||||
* LLC. Start here: http://www.zerotier.com/
|
||||
*/
|
||||
|
||||
package com.zerotier.sdk;
|
||||
|
||||
public interface DataStorePutListener {
|
||||
@ -43,7 +44,7 @@ public interface DataStorePutListener {
|
||||
* @param secure set to user read/write only.
|
||||
* @return 0 on success.
|
||||
*/
|
||||
public int onDataStorePut(
|
||||
int onDataStorePut(
|
||||
String name,
|
||||
byte[] buffer,
|
||||
boolean secure);
|
||||
@ -54,6 +55,6 @@ public interface DataStorePutListener {
|
||||
* @param name Object name
|
||||
* @return 0 on success.
|
||||
*/
|
||||
public int onDelete(
|
||||
int onDelete(
|
||||
String name);
|
||||
}
|
||||
|
@ -27,26 +27,32 @@
|
||||
|
||||
package com.zerotier.sdk;
|
||||
|
||||
/**
|
||||
* Status codes sent to status update callback when things happen
|
||||
*
|
||||
* Defined in ZeroTierOne.h as ZT_Event
|
||||
*/
|
||||
public enum Event {
|
||||
|
||||
/**
|
||||
* Node has been initialized
|
||||
*
|
||||
* This is the first event generated, and is always sent. It may occur
|
||||
* before Node's constructor returns.
|
||||
*/
|
||||
EVENT_UP,
|
||||
EVENT_UP(0),
|
||||
|
||||
/**
|
||||
* Node is offline -- network does not seem to be reachable by any available strategy
|
||||
*/
|
||||
EVENT_OFFLINE,
|
||||
EVENT_OFFLINE(1),
|
||||
|
||||
/**
|
||||
* Node is online -- at least one upstream node appears reachable
|
||||
*
|
||||
* Meta-data: none
|
||||
*/
|
||||
EVENT_ONLINE,
|
||||
EVENT_ONLINE(2),
|
||||
|
||||
/**
|
||||
* Node is shutting down
|
||||
@ -55,7 +61,7 @@ public enum Event {
|
||||
* It's done for convenience, since cleaning up other state in the event
|
||||
* handler may appear more idiomatic.</p>
|
||||
*/
|
||||
EVENT_DOWN,
|
||||
EVENT_DOWN(3),
|
||||
|
||||
/**
|
||||
* Your identity has collided with another node's ZeroTier address
|
||||
@ -85,7 +91,7 @@ public enum Event {
|
||||
* condition is a good way to make sure it never arises. It's like how
|
||||
* umbrellas prevent rain and smoke detectors prevent fires. They do, right?</p>
|
||||
*/
|
||||
EVENT_FATAL_ERROR_IDENTITY_COLLISION,
|
||||
EVENT_FATAL_ERROR_IDENTITY_COLLISION(4),
|
||||
|
||||
/**
|
||||
* Trace (debugging) message
|
||||
@ -94,5 +100,55 @@ public enum Event {
|
||||
*
|
||||
* <p>Meta-data: {@link String}, TRACE message</p>
|
||||
*/
|
||||
EVENT_TRACE
|
||||
}
|
||||
EVENT_TRACE(5),
|
||||
|
||||
/**
|
||||
* VERB_USER_MESSAGE received
|
||||
*
|
||||
* These are generated when a VERB_USER_MESSAGE packet is received via
|
||||
* ZeroTier VL1.
|
||||
*/
|
||||
EVENT_USER_MESSAGE(6),
|
||||
|
||||
/**
|
||||
* Remote trace received
|
||||
*
|
||||
* These are generated when a VERB_REMOTE_TRACE is received. Note
|
||||
* that any node can fling one of these at us. It is your responsibility
|
||||
* to filter and determine if it's worth paying attention to. If it's
|
||||
* not just drop it. Most nodes that are not active controllers ignore
|
||||
* these, and controllers only save them if they pertain to networks
|
||||
* with remote tracing enabled.
|
||||
*/
|
||||
EVENT_REMOTE_TRACE(7);
|
||||
|
||||
@SuppressWarnings({"FieldCanBeLocal", "unused"})
|
||||
private final int id;
|
||||
|
||||
Event(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public static Event fromInt(int id) {
|
||||
switch (id) {
|
||||
case 0:
|
||||
return EVENT_UP;
|
||||
case 1:
|
||||
return EVENT_OFFLINE;
|
||||
case 2:
|
||||
return EVENT_ONLINE;
|
||||
case 3:
|
||||
return EVENT_DOWN;
|
||||
case 4:
|
||||
return EVENT_FATAL_ERROR_IDENTITY_COLLISION;
|
||||
case 5:
|
||||
return EVENT_TRACE;
|
||||
case 6:
|
||||
return EVENT_USER_MESSAGE;
|
||||
case 7:
|
||||
return EVENT_REMOTE_TRACE;
|
||||
default:
|
||||
throw new RuntimeException("Unhandled value: " + id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,19 +27,17 @@
|
||||
|
||||
package com.zerotier.sdk;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.lang.String;
|
||||
|
||||
/**
|
||||
* Interface to handle callbacks for ZeroTier One events.
|
||||
*/
|
||||
public interface EventListener {
|
||||
|
||||
/**
|
||||
* Callback for events with no other associated metadata
|
||||
*
|
||||
* @param event {@link Event} enum
|
||||
*/
|
||||
public void onEvent(Event event);
|
||||
void onEvent(Event event);
|
||||
|
||||
/**
|
||||
* Trace messages
|
||||
@ -48,5 +46,5 @@ public interface EventListener {
|
||||
*
|
||||
* @param message the trace message
|
||||
*/
|
||||
public void onTrace(String message);
|
||||
void onTrace(String message);
|
||||
}
|
||||
|
@ -1,93 +0,0 @@
|
||||
package com.zerotier.sdk;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* Simple library class for working with JNI (Java Native Interface)
|
||||
*
|
||||
* @see http://adamheinrich.com/2012/how-to-load-native-jni-library-from-jar
|
||||
*
|
||||
* @author Adam Heirnich <adam@adamh.cz>, http://www.adamh.cz
|
||||
*/
|
||||
public class NativeUtils {
|
||||
|
||||
/**
|
||||
* Private constructor - this class will never be instanced
|
||||
*/
|
||||
private NativeUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads library from current JAR archive
|
||||
*
|
||||
* The file from JAR is copied into system temporary directory and then loaded. The temporary file is deleted after exiting.
|
||||
* Method uses String as filename because the pathname is "abstract", not system-dependent.
|
||||
*
|
||||
* @param filename The filename inside JAR as absolute path (beginning with '/'), e.g. /package/File.ext
|
||||
* @throws IOException If temporary file creation or read/write operation fails
|
||||
* @throws IllegalArgumentException If source file (param path) does not exist
|
||||
* @throws IllegalArgumentException If the path is not absolute or if the filename is shorter than three characters (restriction of {@see File#createTempFile(java.lang.String, java.lang.String)}).
|
||||
*/
|
||||
public static void loadLibraryFromJar(String path) throws IOException {
|
||||
|
||||
if (!path.startsWith("/")) {
|
||||
throw new IllegalArgumentException("The path has to be absolute (start with '/').");
|
||||
}
|
||||
|
||||
// Obtain filename from path
|
||||
String[] parts = path.split("/");
|
||||
String filename = (parts.length > 1) ? parts[parts.length - 1] : null;
|
||||
|
||||
// Split filename to prefix and suffix (extension)
|
||||
String prefix = "";
|
||||
String suffix = null;
|
||||
if (filename != null) {
|
||||
parts = filename.split("\\.", 2);
|
||||
prefix = parts[0];
|
||||
suffix = (parts.length > 1) ? "."+parts[parts.length - 1] : null; // Thanks, davs! :-)
|
||||
}
|
||||
|
||||
// Check if the filename is okay
|
||||
if (filename == null || prefix.length() < 3) {
|
||||
throw new IllegalArgumentException("The filename has to be at least 3 characters long.");
|
||||
}
|
||||
|
||||
// Prepare temporary file
|
||||
File temp = File.createTempFile(prefix, suffix);
|
||||
temp.deleteOnExit();
|
||||
|
||||
if (!temp.exists()) {
|
||||
throw new FileNotFoundException("File " + temp.getAbsolutePath() + " does not exist.");
|
||||
}
|
||||
|
||||
// Prepare buffer for data copying
|
||||
byte[] buffer = new byte[1024];
|
||||
int readBytes;
|
||||
|
||||
// Open and check input stream
|
||||
InputStream is = NativeUtils.class.getResourceAsStream(path);
|
||||
if (is == null) {
|
||||
throw new FileNotFoundException("File " + path + " was not found inside JAR.");
|
||||
}
|
||||
|
||||
// Open output stream and copy data between source file in JAR and the temporary file
|
||||
OutputStream os = new FileOutputStream(temp);
|
||||
try {
|
||||
while ((readBytes = is.read(buffer)) != -1) {
|
||||
os.write(buffer, 0, readBytes);
|
||||
}
|
||||
} finally {
|
||||
// If read/write fails, close streams safely before throwing an exception
|
||||
os.close();
|
||||
is.close();
|
||||
}
|
||||
|
||||
// Finally, load the library
|
||||
System.load(temp.getAbsolutePath());
|
||||
}
|
||||
}
|
@ -28,95 +28,72 @@
|
||||
package com.zerotier.sdk;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* A ZeroTier One node
|
||||
*/
|
||||
public class Node {
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("ZeroTierOneJNI");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
try {
|
||||
if(System.getProperty("os.name").startsWith("Windows")) {
|
||||
System.out.println("Arch: " + System.getProperty("sun.arch.data.model"));
|
||||
if(System.getProperty("sun.arch.data.model").equals("64")) {
|
||||
NativeUtils.loadLibraryFromJar("/lib/ZeroTierOneJNI_win64.dll");
|
||||
} else {
|
||||
NativeUtils.loadLibraryFromJar("/lib/ZeroTierOneJNI_win32.dll");
|
||||
}
|
||||
} else if(System.getProperty("os.name").startsWith("Mac")) {
|
||||
NativeUtils.loadLibraryFromJar("/lib/libZeroTierOneJNI.jnilib");
|
||||
} else {
|
||||
// TODO: Linux
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
static {
|
||||
System.loadLibrary("ZeroTierOneJNI");
|
||||
}
|
||||
|
||||
private static final String TAG = "NODE";
|
||||
|
||||
/**
|
||||
* Node ID for JNI purposes.
|
||||
* Currently set to the now value passed in at the constructor
|
||||
*
|
||||
* -1 if the node has already been closed
|
||||
*/
|
||||
private long nodeId;
|
||||
|
||||
private final DataStoreGetListener getListener;
|
||||
private final DataStorePutListener putListener;
|
||||
private final PacketSender sender;
|
||||
private final EventListener eventListener;
|
||||
private final VirtualNetworkFrameListener frameListener;
|
||||
private final VirtualNetworkConfigListener configListener;
|
||||
private final PathChecker pathChecker;
|
||||
private final long nodeId;
|
||||
|
||||
/**
|
||||
* Create a new ZeroTier One node
|
||||
*
|
||||
* @param now Current clock in milliseconds
|
||||
*/
|
||||
public Node(long now) {
|
||||
this.nodeId = now;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init a new ZeroTier One node
|
||||
*
|
||||
* <p>Note that this can take a few seconds the first time it's called, as it
|
||||
* will generate an identity.</p>
|
||||
*
|
||||
* @param now Current clock in milliseconds
|
||||
* @param getListener User written instance of the {@link DataStoreGetListener} interface called to get objects from persistent storage. This instance must be unique per Node object.
|
||||
* @param putListener User written instance of the {@link DataStorePutListener} interface called to put objects in persistent storage. This instance must be unique per Node object.
|
||||
* @param sender
|
||||
* @param sender User written instance of the {@link PacketSender} interface to send ZeroTier packets out over the wire.
|
||||
* @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 frameListener User written instance of the {@link VirtualNetworkFrameListener} interface to send a frame out to a virtual network port.
|
||||
* @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,
|
||||
DataStorePutListener putListener,
|
||||
PacketSender sender,
|
||||
EventListener eventListener,
|
||||
VirtualNetworkFrameListener frameListener,
|
||||
VirtualNetworkConfigListener configListener,
|
||||
PathChecker pathChecker) throws NodeException
|
||||
{
|
||||
this.nodeId = now;
|
||||
|
||||
this.getListener = getListener;
|
||||
this.putListener = putListener;
|
||||
this.sender = sender;
|
||||
this.eventListener = eventListener;
|
||||
this.frameListener = frameListener;
|
||||
this.configListener = configListener;
|
||||
this.pathChecker = pathChecker;
|
||||
|
||||
ResultCode rc = node_init(now);
|
||||
if(rc != ResultCode.RESULT_OK)
|
||||
{
|
||||
// TODO: Throw Exception
|
||||
public ResultCode init(
|
||||
DataStoreGetListener getListener,
|
||||
DataStorePutListener putListener,
|
||||
PacketSender sender,
|
||||
EventListener eventListener,
|
||||
VirtualNetworkFrameListener frameListener,
|
||||
VirtualNetworkConfigListener configListener,
|
||||
PathChecker pathChecker) throws NodeException {
|
||||
ResultCode rc = node_init(
|
||||
nodeId,
|
||||
getListener,
|
||||
putListener,
|
||||
sender,
|
||||
eventListener,
|
||||
frameListener,
|
||||
configListener,
|
||||
pathChecker);
|
||||
if(rc != ResultCode.RESULT_OK) {
|
||||
throw new NodeException(rc.toString());
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
public boolean isInited() {
|
||||
return node_isInited(nodeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Close this Node.
|
||||
@ -124,15 +101,12 @@ public class Node {
|
||||
* <p>The Node object can no longer be used once this method is called.</p>
|
||||
*/
|
||||
public void close() {
|
||||
if(nodeId != -1) {
|
||||
node_delete(nodeId);
|
||||
nodeId = -1;
|
||||
}
|
||||
node_delete(nodeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void finalize() {
|
||||
close();
|
||||
public String toString() {
|
||||
return "Node(" + nodeId + ")";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -166,6 +140,7 @@ public class Node {
|
||||
* Process a packet received from the physical wire
|
||||
*
|
||||
* @param now Current clock in milliseconds
|
||||
* @param localSocket Local socket or -1
|
||||
* @param remoteAddress Origin of packet
|
||||
* @param packetData Packet data
|
||||
* @param nextBackgroundTaskDeadline Value/result: set to deadline for next call to processBackgroundTasks()
|
||||
@ -392,8 +367,8 @@ public class Node {
|
||||
*
|
||||
* @return List of networks or NULL on failure
|
||||
*/
|
||||
public VirtualNetworkConfig[] networks() {
|
||||
return networks(nodeId);
|
||||
public VirtualNetworkConfig[] networkConfigs() {
|
||||
return networkConfigs(nodeId);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -408,7 +383,17 @@ public class Node {
|
||||
//
|
||||
// function declarations for JNI
|
||||
//
|
||||
private native ResultCode node_init(long now);
|
||||
private native ResultCode node_init(
|
||||
long nodeId,
|
||||
DataStoreGetListener dataStoreGetListener,
|
||||
DataStorePutListener dataStorePutListener,
|
||||
PacketSender packetSender,
|
||||
EventListener eventListener,
|
||||
VirtualNetworkFrameListener virtualNetworkFrameListener,
|
||||
VirtualNetworkConfigListener virtualNetworkConfigListener,
|
||||
PathChecker pathChecker);
|
||||
|
||||
private native boolean node_isInited(long nodeId);
|
||||
|
||||
private native void node_delete(long nodeId);
|
||||
|
||||
@ -471,5 +456,5 @@ public class Node {
|
||||
|
||||
private native Peer[] peers(long nodeId);
|
||||
|
||||
private native VirtualNetworkConfig[] networks(long nodeId);
|
||||
}
|
||||
private native VirtualNetworkConfig[] networkConfigs(long nodeId);
|
||||
}
|
||||
|
@ -27,10 +27,11 @@
|
||||
|
||||
package com.zerotier.sdk;
|
||||
|
||||
import java.lang.RuntimeException;
|
||||
public class NodeException extends Exception {
|
||||
|
||||
public class NodeException extends RuntimeException {
|
||||
private static final long serialVersionUID = 6268040509883125819L;
|
||||
|
||||
public NodeException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,43 +27,64 @@
|
||||
|
||||
package com.zerotier.sdk;
|
||||
|
||||
public final class NodeStatus {
|
||||
private long address;
|
||||
private String publicIdentity;
|
||||
private String secretIdentity;
|
||||
private boolean online;
|
||||
import com.zerotier.sdk.util.StringUtils;
|
||||
|
||||
private NodeStatus() {}
|
||||
/**
|
||||
* Current node status
|
||||
*
|
||||
* Defined in ZeroTierOne.h as ZT_NodeStatus
|
||||
*/
|
||||
public class NodeStatus {
|
||||
|
||||
private final long address;
|
||||
|
||||
private final String publicIdentity;
|
||||
|
||||
private final String secretIdentity;
|
||||
|
||||
private final boolean online;
|
||||
|
||||
public NodeStatus(long address, String publicIdentity, String secretIdentity, boolean online) {
|
||||
this.address = address;
|
||||
this.publicIdentity = publicIdentity;
|
||||
this.secretIdentity = secretIdentity;
|
||||
this.online = online;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "NodeStatus(" + StringUtils.addressToString(address) + ", " + publicIdentity + ", " + secretIdentity + ", " + online + ")";
|
||||
}
|
||||
|
||||
/**
|
||||
* 40-bit ZeroTier address of this node
|
||||
*/
|
||||
public final long getAddress() {
|
||||
return address;
|
||||
}
|
||||
public long getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
/**
|
||||
* Public identity in string-serialized form (safe to send to others)
|
||||
*
|
||||
* <p>This identity will remain valid as long as the node exists.</p>
|
||||
*/
|
||||
public final String getPublicIdentity() {
|
||||
return publicIdentity;
|
||||
}
|
||||
public String getPublicIdentity() {
|
||||
return publicIdentity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Full identity including secret key in string-serialized form
|
||||
*
|
||||
* <p>This identity will remain valid as long as the node exists.</p>
|
||||
*/
|
||||
public final String getSecretIdentity() {
|
||||
return secretIdentity;
|
||||
}
|
||||
public String getSecretIdentity() {
|
||||
return secretIdentity;
|
||||
}
|
||||
|
||||
/**
|
||||
* True if some kind of connectivity appears available
|
||||
*/
|
||||
public final boolean isOnline() {
|
||||
return online;
|
||||
}
|
||||
}
|
||||
public boolean isOnline() {
|
||||
return online;
|
||||
}
|
||||
}
|
||||
|
@ -24,12 +24,14 @@
|
||||
* redistribute it in a modified binary form, please contact ZeroTier Networks
|
||||
* LLC. Start here: http://www.zerotier.com/
|
||||
*/
|
||||
|
||||
package com.zerotier.sdk;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
|
||||
public interface PacketSender {
|
||||
|
||||
/**
|
||||
* Function to send a ZeroTier packet out over the wire
|
||||
*
|
||||
@ -40,9 +42,10 @@ public interface PacketSender {
|
||||
* @param localSocket socket file descriptor to send from. Set to -1 if not specified.
|
||||
* @param remoteAddr {@link InetSocketAddress} to send to
|
||||
* @param packetData data to send
|
||||
* @param ttl TTL is ignored
|
||||
* @return 0 on success, any error code on failure.
|
||||
*/
|
||||
public int onSendPacketRequested(
|
||||
int onSendPacketRequested(
|
||||
long localSocket,
|
||||
InetSocketAddress remoteAddr,
|
||||
byte[] packetData,
|
||||
|
@ -8,6 +8,7 @@ package com.zerotier.sdk;
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
public interface PathChecker {
|
||||
|
||||
/**
|
||||
* Callback to check whether a path should be used for ZeroTier traffic
|
||||
*
|
||||
@ -28,6 +29,7 @@ public interface PathChecker {
|
||||
* @param ztAddress ZeroTier address or 0 for none/any
|
||||
* @param localSocket Local interface socket. -1 if unspecified
|
||||
* @param remoteAddress remote address
|
||||
* @return true if the path should be used
|
||||
*/
|
||||
boolean onPathCheck(long ztAddress, long localSocket, InetSocketAddress remoteAddress);
|
||||
|
||||
|
@ -27,68 +27,92 @@
|
||||
|
||||
package com.zerotier.sdk;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import com.zerotier.sdk.util.StringUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Peer status result
|
||||
* Peer status result buffer
|
||||
*
|
||||
* Defined in ZeroTierOne.h as ZT_Peer
|
||||
*/
|
||||
public final class Peer {
|
||||
private long address;
|
||||
private int versionMajor;
|
||||
private int versionMinor;
|
||||
private int versionRev;
|
||||
private int latency;
|
||||
private PeerRole role;
|
||||
private PeerPhysicalPath[] paths;
|
||||
public class Peer {
|
||||
|
||||
private Peer() {}
|
||||
private final long address;
|
||||
|
||||
private final int versionMajor;
|
||||
|
||||
private final int versionMinor;
|
||||
|
||||
private final int versionRev;
|
||||
|
||||
private final int latency;
|
||||
|
||||
private final PeerRole role;
|
||||
|
||||
private final PeerPhysicalPath[] paths;
|
||||
|
||||
public Peer(long address, int versionMajor, int versionMinor, int versionRev, int latency, PeerRole role, PeerPhysicalPath[] paths) {
|
||||
this.address = address;
|
||||
this.versionMajor = versionMajor;
|
||||
this.versionMinor = versionMinor;
|
||||
this.versionRev = versionRev;
|
||||
this.latency = latency;
|
||||
this.role = role;
|
||||
this.paths = paths;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Peer(" + StringUtils.addressToString(address) + ", " + versionMajor + ", " + versionMinor + ", " + versionRev + ", " + latency + ", " + role + ", " + Arrays.toString(paths) + ")";
|
||||
}
|
||||
|
||||
/**
|
||||
* ZeroTier address (40 bits)
|
||||
*/
|
||||
public final long address() {
|
||||
public long getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remote major version or -1 if not known
|
||||
*/
|
||||
public final int versionMajor() {
|
||||
public int getVersionMajor() {
|
||||
return versionMajor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remote minor version or -1 if not known
|
||||
*/
|
||||
public final int versionMinor() {
|
||||
public int getVersionMinor() {
|
||||
return versionMinor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remote revision or -1 if not known
|
||||
*/
|
||||
public final int versionRev() {
|
||||
public int getVersionRev() {
|
||||
return versionRev;
|
||||
}
|
||||
|
||||
/**
|
||||
* Last measured latency in milliseconds or zero if unknown
|
||||
*/
|
||||
public final int latency() {
|
||||
public int getLatency() {
|
||||
return latency;
|
||||
}
|
||||
|
||||
/**
|
||||
* What trust hierarchy role does this device have?
|
||||
*/
|
||||
public final PeerRole role() {
|
||||
public PeerRole getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
/**
|
||||
* Known network paths to peer
|
||||
*/
|
||||
public final PeerPhysicalPath[] paths() {
|
||||
public PeerPhysicalPath[] getPaths() {
|
||||
return paths;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,48 +31,62 @@ import java.net.InetSocketAddress;
|
||||
|
||||
/**
|
||||
* Physical network path to a peer
|
||||
*
|
||||
* Defined in ZeroTierOne.h as ZT_PeerPhysicalPath
|
||||
*/
|
||||
public final class PeerPhysicalPath {
|
||||
private InetSocketAddress address;
|
||||
private long lastSend;
|
||||
private long lastReceive;
|
||||
private boolean fixed;
|
||||
private boolean preferred;
|
||||
public class PeerPhysicalPath {
|
||||
|
||||
private PeerPhysicalPath() {}
|
||||
private final InetSocketAddress address;
|
||||
|
||||
private final long lastSend;
|
||||
|
||||
private final long lastReceive;
|
||||
|
||||
private final boolean preferred;
|
||||
|
||||
public PeerPhysicalPath(InetSocketAddress address, long lastSend, long lastReceive, boolean preferred) {
|
||||
this.address = address;
|
||||
if (lastSend < 0) {
|
||||
throw new RuntimeException("lastSend < 0: " + lastSend);
|
||||
}
|
||||
this.lastSend = lastSend;
|
||||
if (lastReceive < 0) {
|
||||
throw new RuntimeException("lastReceive < 0: " + lastReceive);
|
||||
}
|
||||
this.lastReceive = lastReceive;
|
||||
this.preferred = preferred;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PeerPhysicalPath(" + address + ", " + lastSend + ", " + lastReceive + ", " + preferred + ")";
|
||||
}
|
||||
|
||||
/**
|
||||
* Address of endpoint
|
||||
*/
|
||||
public final InetSocketAddress address() {
|
||||
public InetSocketAddress getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
/**
|
||||
* Time of last send in milliseconds or 0 for never
|
||||
*/
|
||||
public final long lastSend() {
|
||||
public long getLastSend() {
|
||||
return lastSend;
|
||||
}
|
||||
|
||||
/**
|
||||
* Time of last receive in milliseconds or 0 for never
|
||||
*/
|
||||
public final long lastReceive() {
|
||||
public long getLastReceive() {
|
||||
return lastReceive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is path fixed? (i.e. not learned, static)
|
||||
*/
|
||||
public final boolean isFixed() {
|
||||
return fixed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is path preferred?
|
||||
*/
|
||||
public final boolean isPreferred() {
|
||||
public boolean isPreferred() {
|
||||
return preferred;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,19 +27,45 @@
|
||||
|
||||
package com.zerotier.sdk;
|
||||
|
||||
/**
|
||||
* What trust hierarchy role does this peer have?
|
||||
*
|
||||
* Defined in ZeroTierOne.h as ZT_PeerRole
|
||||
*/
|
||||
public enum PeerRole {
|
||||
|
||||
/**
|
||||
* An ordinary node
|
||||
*/
|
||||
PEER_ROLE_LEAF,
|
||||
PEER_ROLE_LEAF(0),
|
||||
|
||||
/**
|
||||
* moon root
|
||||
*/
|
||||
PEER_ROLE_MOON,
|
||||
PEER_ROLE_MOON(1),
|
||||
|
||||
/**
|
||||
* planetary root
|
||||
*/
|
||||
PEER_ROLE_PLANET
|
||||
}
|
||||
PEER_ROLE_PLANET(2);
|
||||
|
||||
@SuppressWarnings({"FieldCanBeLocal", "unused"})
|
||||
private final int id;
|
||||
|
||||
PeerRole(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public static PeerRole fromInt(int id) {
|
||||
switch (id) {
|
||||
case 0:
|
||||
return PEER_ROLE_LEAF;
|
||||
case 1:
|
||||
return PEER_ROLE_MOON;
|
||||
case 2:
|
||||
return PEER_ROLE_PLANET;
|
||||
default:
|
||||
throw new RuntimeException("Unhandled value: " + id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,12 +34,20 @@ package com.zerotier.sdk;
|
||||
* occurs, the node should be considered to not be working correctly. These
|
||||
* indicate serious problems like an inaccessible data store or a compile
|
||||
* problem.</p>
|
||||
*
|
||||
* Defined in ZeroTierOne.h as ZT_ResultCode
|
||||
*/
|
||||
public enum ResultCode {
|
||||
|
||||
/**
|
||||
* Operation completed normally
|
||||
*/
|
||||
RESULT_OK(0),
|
||||
RESULT_OK(0),
|
||||
|
||||
/**
|
||||
* Call produced no error but no action was taken
|
||||
*/
|
||||
RESULT_OK_IGNORED(1),
|
||||
|
||||
// Fatal errors (>=100, <1000)
|
||||
/**
|
||||
@ -68,12 +76,36 @@ public enum ResultCode {
|
||||
|
||||
RESULT_ERROR_BAD_PARAMETER(1002);
|
||||
|
||||
|
||||
private final int id;
|
||||
ResultCode(int id) { this.id = id; }
|
||||
public int getValue() { return id; }
|
||||
private final int id;
|
||||
|
||||
public boolean isFatal(int id) {
|
||||
return (id > 100 && id < 1000);
|
||||
ResultCode(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
|
||||
public static ResultCode fromInt(int id) {
|
||||
switch (id) {
|
||||
case 0:
|
||||
return RESULT_OK;
|
||||
case 1:
|
||||
return RESULT_OK_IGNORED;
|
||||
case 100:
|
||||
return RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
||||
case 101:
|
||||
return RESULT_FATAL_ERROR_DATA_STORE_FAILED;
|
||||
case 102:
|
||||
return RESULT_FATAL_ERROR_INTERNAL;
|
||||
case 1000:
|
||||
return RESULT_ERROR_NETWORK_NOT_FOUND;
|
||||
case 1001:
|
||||
return RESULT_ERROR_UNSUPPORTED_OPERATION;
|
||||
case 1002:
|
||||
return RESULT_ERROR_BAD_PARAMETER;
|
||||
default:
|
||||
throw new RuntimeException("Unhandled value: " + id);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isFatal() {
|
||||
return (id >= 100 && id < 1000);
|
||||
}
|
||||
}
|
||||
|
@ -27,10 +27,27 @@
|
||||
|
||||
package com.zerotier.sdk;
|
||||
|
||||
public final class Version {
|
||||
private Version() {}
|
||||
|
||||
public int major = 0;
|
||||
public int minor = 0;
|
||||
public int revision = 0;
|
||||
}
|
||||
public class Version {
|
||||
|
||||
private final int major;
|
||||
private final int minor;
|
||||
private final int revision;
|
||||
|
||||
public Version(int major, int minor, int revision) {
|
||||
this.major = major;
|
||||
this.minor = minor;
|
||||
this.revision = revision;
|
||||
}
|
||||
|
||||
public int getMajor() {
|
||||
return major;
|
||||
}
|
||||
|
||||
public int getMinor() {
|
||||
return minor;
|
||||
}
|
||||
|
||||
public int getRevision() {
|
||||
return revision;
|
||||
}
|
||||
}
|
||||
|
@ -29,197 +29,305 @@ package com.zerotier.sdk;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import java.lang.Comparable;
|
||||
import java.lang.Override;
|
||||
import java.lang.String;
|
||||
import java.util.ArrayList;
|
||||
import com.zerotier.sdk.util.StringUtils;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
public final class VirtualNetworkConfig implements Comparable<VirtualNetworkConfig> {
|
||||
/**
|
||||
* Virtual network configuration
|
||||
*
|
||||
* Defined in ZeroTierOne.h as ZT_VirtualNetworkConfig
|
||||
*/
|
||||
public class VirtualNetworkConfig implements Comparable<VirtualNetworkConfig> {
|
||||
|
||||
private final static String TAG = "VirtualNetworkConfig";
|
||||
|
||||
public static final int MAX_MULTICAST_SUBSCRIPTIONS = 4096;
|
||||
public static final int ZT_MAX_ZT_ASSIGNED_ADDRESSES = 16;
|
||||
|
||||
private long nwid;
|
||||
private long mac;
|
||||
private String name;
|
||||
private VirtualNetworkStatus status;
|
||||
private VirtualNetworkType type;
|
||||
private int mtu;
|
||||
private boolean dhcp;
|
||||
private boolean bridge;
|
||||
private boolean broadcastEnabled;
|
||||
private int portError;
|
||||
private boolean enabled;
|
||||
private long netconfRevision;
|
||||
private InetSocketAddress[] assignedAddresses;
|
||||
private VirtualNetworkRoute[] routes;
|
||||
private VirtualNetworkDNS dns;
|
||||
private final long nwid;
|
||||
|
||||
private VirtualNetworkConfig() {
|
||||
private final long mac;
|
||||
|
||||
private final String name;
|
||||
|
||||
private final VirtualNetworkStatus status;
|
||||
|
||||
private final VirtualNetworkType type;
|
||||
|
||||
private final int mtu;
|
||||
|
||||
private final boolean dhcp;
|
||||
|
||||
private final boolean bridge;
|
||||
|
||||
private final boolean broadcastEnabled;
|
||||
|
||||
//
|
||||
// ANDROID-56: temporarily remove parameters to prevent crashing
|
||||
//
|
||||
// private final int portError;
|
||||
//
|
||||
// private final long netconfRevision;
|
||||
|
||||
private final InetSocketAddress[] assignedAddresses;
|
||||
|
||||
private final VirtualNetworkRoute[] routes;
|
||||
|
||||
private final VirtualNetworkDNS dns;
|
||||
|
||||
public VirtualNetworkConfig(long nwid, long mac, String name, VirtualNetworkStatus status, VirtualNetworkType type, int mtu, boolean dhcp, boolean bridge, boolean broadcastEnabled, InetSocketAddress[] assignedAddresses, VirtualNetworkRoute[] routes, VirtualNetworkDNS dns) {
|
||||
this.nwid = nwid;
|
||||
this.mac = mac;
|
||||
this.name = name;
|
||||
this.status = status;
|
||||
this.type = type;
|
||||
if (mtu < 0) {
|
||||
throw new RuntimeException("mtu < 0: " + mtu);
|
||||
}
|
||||
this.mtu = mtu;
|
||||
this.dhcp = dhcp;
|
||||
this.bridge = bridge;
|
||||
this.broadcastEnabled = broadcastEnabled;
|
||||
// this.portError = portError;
|
||||
// if (netconfRevision < 0) {
|
||||
// throw new RuntimeException("netconfRevision < 0: " + netconfRevision);
|
||||
// }
|
||||
// this.netconfRevision = netconfRevision;
|
||||
this.assignedAddresses = assignedAddresses;
|
||||
this.routes = routes;
|
||||
this.dns = dns;
|
||||
}
|
||||
|
||||
public boolean equals(VirtualNetworkConfig cfg) {
|
||||
ArrayList<String> aaCurrent = new ArrayList<>();
|
||||
ArrayList<String> aaNew = new ArrayList<>();
|
||||
for (InetSocketAddress s : assignedAddresses) {
|
||||
aaCurrent.add(s.toString());
|
||||
}
|
||||
for (InetSocketAddress s : cfg.assignedAddresses) {
|
||||
aaNew.add(s.toString());
|
||||
}
|
||||
Collections.sort(aaCurrent);
|
||||
Collections.sort(aaNew);
|
||||
boolean aaEqual = aaCurrent.equals(aaNew);
|
||||
@Override
|
||||
public String toString() {
|
||||
return "VirtualNetworkConfig(" + StringUtils.networkIdToString(nwid) + ", " + StringUtils.macAddressToString(mac) + ", " + name + ", " + status + ", " + type + ", " + mtu + ", " + dhcp + ", " + bridge + ", " + broadcastEnabled + ", " + Arrays.toString(assignedAddresses) + ", " + Arrays.toString(routes) + ", " + dns + ")";
|
||||
}
|
||||
|
||||
ArrayList<String> rCurrent = new ArrayList<>();
|
||||
ArrayList<String> rNew = new ArrayList<>();
|
||||
for (VirtualNetworkRoute r : routes) {
|
||||
rCurrent.add(r.toString());
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
|
||||
if (!(o instanceof VirtualNetworkConfig)) {
|
||||
return false;
|
||||
}
|
||||
for (VirtualNetworkRoute r : cfg.routes) {
|
||||
rNew.add(r.toString());
|
||||
}
|
||||
Collections.sort(rCurrent);
|
||||
Collections.sort(rNew);
|
||||
boolean routesEqual = rCurrent.equals(rNew);
|
||||
|
||||
VirtualNetworkConfig cfg = (VirtualNetworkConfig) o;
|
||||
|
||||
if (this.nwid != cfg.nwid) {
|
||||
Log.i(TAG, "nwid Changed. Old: " + Long.toHexString(this.nwid) + " (" + Long.toString(this.nwid) + "), " +
|
||||
"New: " + Long.toHexString(cfg.nwid) + " (" + Long.toString(cfg.nwid) + ")");
|
||||
Log.i(TAG, "NetworkID Changed. Old: " + StringUtils.networkIdToString(this.nwid) + " (" + this.nwid + "), " +
|
||||
"New: " + StringUtils.networkIdToString(cfg.nwid) + " (" + cfg.nwid + ")");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.mac != cfg.mac) {
|
||||
Log.i(TAG, "MAC Changed. Old: " + Long.toHexString(this.mac) + ", New: " + Long.toHexString(cfg.mac));
|
||||
Log.i(TAG, "MAC Changed. Old: " + StringUtils.macAddressToString(this.mac) + ", New: " + StringUtils.macAddressToString(cfg.mac));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this.name.equals(cfg.name)) {
|
||||
Log.i(TAG, "Name Changed. Old: " + this.name + " New: "+ cfg.name);
|
||||
Log.i(TAG, "Name Changed. Old: " + this.name + ", New: " + cfg.name);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this.type.equals(cfg.type)) {
|
||||
Log.i(TAG, "TYPE changed. Old " + this.type + ", New: " + cfg.type);
|
||||
if (this.status != cfg.status) {
|
||||
Log.i(TAG, "Status Changed. Old: " + this.status + ", New: " + cfg.status);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.type != cfg.type) {
|
||||
Log.i(TAG, "Type changed. Old " + this.type + ", New: " + cfg.type);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.mtu != cfg.mtu) {
|
||||
Log.i(TAG, "MTU Changed. Old: " + this.mtu + ", New: " + cfg.mtu);
|
||||
Log.i(TAG, "MTU Changed. Old: " + this.mtu + ", New: " + cfg.mtu);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.dhcp != cfg.dhcp) {
|
||||
Log.i(TAG, "DHCP Flag Changed. Old: " + this.dhcp + ", New: " + cfg.dhcp);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.bridge != cfg.bridge) {
|
||||
Log.i(TAG, "Bridge Flag Changed. Old: " + this.bridge + ", New: " + cfg.bridge);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.broadcastEnabled != cfg.broadcastEnabled) {
|
||||
Log.i(TAG, "Broadcast Flag Changed. Old: "+ this.broadcastEnabled +", New: " + this.broadcastEnabled);
|
||||
Log.i(TAG, "Broadcast Flag Changed. Old: "+ this.broadcastEnabled + ", New: " + cfg.broadcastEnabled);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.portError != cfg.portError) {
|
||||
Log.i(TAG, "Port Error Changed. Old: " + this.portError + ", New: " + this.portError);
|
||||
}
|
||||
// if (this.portError != cfg.portError) {
|
||||
// Log.i(TAG, "Port Error Changed. Old: " + this.portError + ", New: " + cfg.portError);
|
||||
//
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// if (this.netconfRevision != cfg.netconfRevision) {
|
||||
// Log.i(TAG, "NetConfRevision Changed. Old: " + this.netconfRevision + ", New: " + cfg.netconfRevision);
|
||||
//
|
||||
// return false;
|
||||
// }
|
||||
|
||||
if (this.enabled != cfg.enabled) {
|
||||
Log.i(TAG, "Enabled Changed. Old: " + this.enabled + ", New: " + this.enabled);
|
||||
}
|
||||
if (!Arrays.equals(assignedAddresses, cfg.assignedAddresses)) {
|
||||
|
||||
ArrayList<String> aaCurrent = new ArrayList<>();
|
||||
ArrayList<String> aaNew = new ArrayList<>();
|
||||
for (InetSocketAddress s : assignedAddresses) {
|
||||
aaCurrent.add(s.toString());
|
||||
}
|
||||
for (InetSocketAddress s : cfg.assignedAddresses) {
|
||||
aaNew.add(s.toString());
|
||||
}
|
||||
Collections.sort(aaCurrent);
|
||||
Collections.sort(aaNew);
|
||||
|
||||
if (!aaEqual) {
|
||||
Log.i(TAG, "Assigned Addresses Changed");
|
||||
Log.i(TAG, "Old:");
|
||||
for (String s : aaCurrent) {
|
||||
Log.i(TAG, " " + s);
|
||||
}
|
||||
Log.i(TAG, "");
|
||||
Log.i(TAG, "New:");
|
||||
for (String s : aaNew) {
|
||||
Log.i(TAG, " " +s);
|
||||
}
|
||||
Log.i(TAG, "");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!routesEqual) {
|
||||
if (!Arrays.equals(routes, cfg.routes)) {
|
||||
|
||||
ArrayList<String> rCurrent = new ArrayList<>();
|
||||
ArrayList<String> rNew = new ArrayList<>();
|
||||
for (VirtualNetworkRoute r : routes) {
|
||||
rCurrent.add(r.toString());
|
||||
}
|
||||
for (VirtualNetworkRoute r : cfg.routes) {
|
||||
rNew.add(r.toString());
|
||||
}
|
||||
Collections.sort(rCurrent);
|
||||
Collections.sort(rNew);
|
||||
|
||||
Log.i(TAG, "Managed Routes Changed");
|
||||
Log.i(TAG, "Old:");
|
||||
for (String s : rCurrent) {
|
||||
Log.i(TAG, " " + s);
|
||||
}
|
||||
Log.i(TAG, "");
|
||||
Log.i(TAG, "New:");
|
||||
for (String s : rNew) {
|
||||
Log.i(TAG, " " + s);
|
||||
}
|
||||
Log.i(TAG, "");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean dnsEquals = false;
|
||||
if (this.dns == null || cfg.dns == null) {
|
||||
dnsEquals = true;
|
||||
} else if (this.dns != null) {
|
||||
dnsEquals = this.dns.equals(cfg.dns);
|
||||
boolean dnsEquals;
|
||||
if (this.dns == null) {
|
||||
//noinspection RedundantIfStatement
|
||||
if (cfg.dns == null) {
|
||||
dnsEquals = true;
|
||||
} else {
|
||||
dnsEquals = false;
|
||||
}
|
||||
} else {
|
||||
if (cfg.dns == null) {
|
||||
dnsEquals = false;
|
||||
} else {
|
||||
dnsEquals = this.dns.equals(cfg.dns);
|
||||
}
|
||||
}
|
||||
|
||||
return this.nwid == cfg.nwid &&
|
||||
this.mac == cfg.mac &&
|
||||
this.name.equals(cfg.name) &&
|
||||
this.status.equals(cfg.status) &&
|
||||
this.type.equals(cfg.type) &&
|
||||
this.mtu == cfg.mtu &&
|
||||
this.dhcp == cfg.dhcp &&
|
||||
this.bridge == cfg.bridge &&
|
||||
this.broadcastEnabled == cfg.broadcastEnabled &&
|
||||
this.portError == cfg.portError &&
|
||||
this.enabled == cfg.enabled &&
|
||||
dnsEquals &&
|
||||
aaEqual && routesEqual;
|
||||
if (!dnsEquals) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(VirtualNetworkConfig cfg) {
|
||||
if(cfg.nwid == this.nwid) {
|
||||
return 0;
|
||||
} else {
|
||||
return this.nwid > cfg.nwid ? 1 : -1;
|
||||
}
|
||||
return Long.compare(this.nwid, cfg.nwid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
int result = 17;
|
||||
result = 37 * result + (int) (nwid ^ (nwid >>> 32));
|
||||
result = 37 * result + (int) (mac ^ (mac >>> 32));
|
||||
result = 37 * result + name.hashCode();
|
||||
result = 37 * result + status.hashCode();
|
||||
result = 37 * result + type.hashCode();
|
||||
result = 37 * result + mtu;
|
||||
result = 37 * result + (dhcp ? 1 : 0);
|
||||
result = 37 * result + (bridge ? 1 : 0);
|
||||
result = 37 * result + (broadcastEnabled ? 1 : 0);
|
||||
// result = 37 * result + portError;
|
||||
// result = 37 * result + (int) (netconfRevision ^ (netconfRevision >>> 32));
|
||||
result = 37 * result + Arrays.hashCode(assignedAddresses);
|
||||
result = 37 * result + Arrays.hashCode(routes);
|
||||
result = 37 * result + (dns == null ? 0 : dns.hashCode());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 64-bit ZeroTier network ID
|
||||
*/
|
||||
public final long networkId() {
|
||||
public long getNwid() {
|
||||
return nwid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ethernet MAC (40 bits) that should be assigned to port
|
||||
* Ethernet MAC (48 bits) that should be assigned to port
|
||||
*/
|
||||
public final long macAddress() {
|
||||
public long getMac() {
|
||||
return mac;
|
||||
}
|
||||
|
||||
/**
|
||||
* Network name (from network configuration master)
|
||||
*/
|
||||
public final String name() {
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Network configuration request status
|
||||
*/
|
||||
public final VirtualNetworkStatus networkStatus() {
|
||||
public VirtualNetworkStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Network type
|
||||
*/
|
||||
public final VirtualNetworkType networkType() {
|
||||
public VirtualNetworkType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maximum interface MTU
|
||||
*/
|
||||
public final int mtu() {
|
||||
public int getMtu() {
|
||||
return mtu;
|
||||
}
|
||||
|
||||
@ -230,7 +338,7 @@ public final class VirtualNetworkConfig implements Comparable<VirtualNetworkConf
|
||||
* for security or other reasons. This is simply a netconf parameter that
|
||||
* means 'DHCP is available on this network.'</p>
|
||||
*/
|
||||
public final boolean isDhcpAvailable() {
|
||||
public boolean isDhcp() {
|
||||
return dhcp;
|
||||
}
|
||||
|
||||
@ -240,35 +348,35 @@ public final class VirtualNetworkConfig implements Comparable<VirtualNetworkConf
|
||||
* <p>This is informational. If this is false, bridged packets will simply
|
||||
* be dropped and bridging won't work.</p>
|
||||
*/
|
||||
public final boolean isBridgeEnabled() {
|
||||
public boolean isBridge() {
|
||||
return bridge;
|
||||
}
|
||||
|
||||
/**
|
||||
* If true, this network supports and allows broadcast (ff:ff:ff:ff:ff:ff) traffic
|
||||
*/
|
||||
public final boolean broadcastEnabled() {
|
||||
public boolean isBroadcastEnabled() {
|
||||
return broadcastEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the network is in PORT_ERROR state, this is the error most recently returned by the port config callback
|
||||
*/
|
||||
public final int portError() {
|
||||
return portError;
|
||||
}
|
||||
// public int getPortError() {
|
||||
// return portError;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Network config revision as reported by netconf master
|
||||
*
|
||||
* <p>If this is zero, it means we're still waiting for our netconf.</p>
|
||||
*/
|
||||
public final long netconfRevision() {
|
||||
return netconfRevision;
|
||||
}
|
||||
// public long getNetconfRevision() {
|
||||
// return netconfRevision;
|
||||
// }
|
||||
|
||||
/**
|
||||
* ZeroTier-assigned addresses (in {@link java.net.InetSocketAddress} objects)
|
||||
* ZeroTier-assigned addresses (in {@link InetSocketAddress} objects)
|
||||
*
|
||||
* For IP, the port number of the sockaddr_XX structure contains the number
|
||||
* of bits in the address netmask. Only the IP address and port are used.
|
||||
@ -277,16 +385,21 @@ public final class VirtualNetworkConfig implements Comparable<VirtualNetworkConf
|
||||
* This is only used for ZeroTier-managed address assignments sent by the
|
||||
* virtual network's configuration master.
|
||||
*/
|
||||
public final InetSocketAddress[] assignedAddresses() {
|
||||
public InetSocketAddress[] getAssignedAddresses() {
|
||||
return assignedAddresses;
|
||||
}
|
||||
|
||||
/**
|
||||
* ZeroTier-assigned routes (in {@link com.zerotier.sdk.VirtualNetworkRoute} objects)
|
||||
*
|
||||
* @return
|
||||
* ZeroTier-assigned routes (in {@link VirtualNetworkRoute} objects)
|
||||
*/
|
||||
public final VirtualNetworkRoute[] routes() { return routes; }
|
||||
public VirtualNetworkRoute[] getRoutes() {
|
||||
return routes;
|
||||
}
|
||||
|
||||
public final VirtualNetworkDNS dns() { return dns; }
|
||||
/**
|
||||
* Network specific DNS configuration
|
||||
*/
|
||||
public VirtualNetworkDNS getDns() {
|
||||
return dns;
|
||||
}
|
||||
}
|
||||
|
@ -25,11 +25,11 @@
|
||||
* LLC. Start here: http://www.zerotier.com/
|
||||
*/
|
||||
|
||||
|
||||
package com.zerotier.sdk;
|
||||
|
||||
|
||||
public interface VirtualNetworkConfigListener {
|
||||
|
||||
/**
|
||||
* Callback called to update virtual network port configuration
|
||||
*
|
||||
@ -40,7 +40,7 @@ public interface VirtualNetworkConfigListener {
|
||||
* This in turn should be used by the underlying implementation to create
|
||||
* and configure tap devices at the OS (or virtual network stack) layer.</P>
|
||||
*
|
||||
* This should not call {@link Node#multicastSubscribe} or other network-modifying
|
||||
* This should not call {@link Node#multicastSubscribe(long, long)} or other network-modifying
|
||||
* methods, as this could cause a deadlock in multithreaded or interrupt
|
||||
* driven environments.
|
||||
*
|
||||
@ -53,8 +53,8 @@ public interface VirtualNetworkConfigListener {
|
||||
* @param config {@link VirtualNetworkConfig} object with the new configuration
|
||||
* @return 0 on success
|
||||
*/
|
||||
public int onNetworkConfigurationUpdated(
|
||||
int onNetworkConfigurationUpdated(
|
||||
long nwid,
|
||||
VirtualNetworkConfigOperation op,
|
||||
VirtualNetworkConfig config);
|
||||
}
|
||||
}
|
||||
|
@ -24,26 +24,55 @@
|
||||
* redistribute it in a modified binary form, please contact ZeroTier Networks
|
||||
* LLC. Start here: http://www.zerotier.com/
|
||||
*/
|
||||
|
||||
package com.zerotier.sdk;
|
||||
|
||||
/**
|
||||
* Virtual network configuration update type
|
||||
*
|
||||
* Defined in ZeroTierOne.h as ZT_VirtualNetworkConfigOperation
|
||||
*/
|
||||
public enum VirtualNetworkConfigOperation {
|
||||
|
||||
/**
|
||||
* Network is coming up (either for the first time or after service restart)
|
||||
*/
|
||||
VIRTUAL_NETWORK_CONFIG_OPERATION_UP,
|
||||
VIRTUAL_NETWORK_CONFIG_OPERATION_UP(1),
|
||||
|
||||
/**
|
||||
* Network configuration has been updated
|
||||
*/
|
||||
VIRTUAL_NETWORK_CONFIG_OPERATION_CONFIG_UPDATE,
|
||||
VIRTUAL_NETWORK_CONFIG_OPERATION_CONFIG_UPDATE(2),
|
||||
|
||||
/**
|
||||
* Network is going down (not permanently)
|
||||
*/
|
||||
VIRTUAL_NETWORK_CONFIG_OPERATION_DOWN,
|
||||
VIRTUAL_NETWORK_CONFIG_OPERATION_DOWN(3),
|
||||
|
||||
/**
|
||||
* Network is going down permanently (leave/delete)
|
||||
*/
|
||||
VIRTUAL_NETWORK_CONFIG_OPERATION_DESTROY
|
||||
VIRTUAL_NETWORK_CONFIG_OPERATION_DESTROY(4);
|
||||
|
||||
@SuppressWarnings({"FieldCanBeLocal", "unused"})
|
||||
private final int id;
|
||||
|
||||
VirtualNetworkConfigOperation(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public static VirtualNetworkConfigOperation fromInt(int id) {
|
||||
switch (id) {
|
||||
case 1:
|
||||
return VIRTUAL_NETWORK_CONFIG_OPERATION_UP;
|
||||
case 2:
|
||||
return VIRTUAL_NETWORK_CONFIG_OPERATION_CONFIG_UPDATE;
|
||||
case 3:
|
||||
return VIRTUAL_NETWORK_CONFIG_OPERATION_DOWN;
|
||||
case 4:
|
||||
return VIRTUAL_NETWORK_CONFIG_OPERATION_DESTROY;
|
||||
default:
|
||||
throw new RuntimeException("Unhandled value: " + id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,15 +8,48 @@ package com.zerotier.sdk;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* DNS configuration to be pushed on a virtual network
|
||||
*
|
||||
* Defined in ZeroTierOne.h as ZT_VirtualNetworkDNS
|
||||
*/
|
||||
public class VirtualNetworkDNS implements Comparable<VirtualNetworkDNS> {
|
||||
private String domain;
|
||||
private ArrayList<InetSocketAddress> servers;
|
||||
|
||||
public VirtualNetworkDNS() {}
|
||||
private final String domain;
|
||||
private final ArrayList<InetSocketAddress> servers;
|
||||
|
||||
public boolean equals(VirtualNetworkDNS o) {
|
||||
if (o == null) return false;
|
||||
return domain.equals(o.domain) && servers.equals(o.servers);
|
||||
public VirtualNetworkDNS(String domain, ArrayList<InetSocketAddress> servers) {
|
||||
this.domain = domain;
|
||||
this.servers = servers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "VirtualNetworkDNS(" + domain + ", " + servers + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
|
||||
if (o == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(o instanceof VirtualNetworkDNS)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
VirtualNetworkDNS d = (VirtualNetworkDNS) o;
|
||||
|
||||
if (!domain.equals(d.domain)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!servers.equals(d.servers)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -24,7 +57,21 @@ public class VirtualNetworkDNS implements Comparable<VirtualNetworkDNS> {
|
||||
return domain.compareTo(o.domain);
|
||||
}
|
||||
|
||||
public String getSearchDomain() { return domain; }
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
public ArrayList<InetSocketAddress> getServers() { return servers; }
|
||||
int result = 17;
|
||||
result = 37 * result + domain.hashCode();
|
||||
result = 37 * result + servers.hashCode();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getDomain() {
|
||||
return domain;
|
||||
}
|
||||
|
||||
public ArrayList<InetSocketAddress> getServers() {
|
||||
return servers;
|
||||
}
|
||||
}
|
||||
|
@ -28,17 +28,18 @@
|
||||
package com.zerotier.sdk;
|
||||
|
||||
public interface VirtualNetworkFrameListener {
|
||||
|
||||
/**
|
||||
* Function to send a frame out to a virtual network port
|
||||
*
|
||||
* @param nwid ZeroTier One network ID
|
||||
* @param srcMac source MAC address
|
||||
* @param destMac destination MAC address
|
||||
* @param ethertype
|
||||
* @param vlanId
|
||||
* @param etherType EtherType
|
||||
* @param vlanId VLAN ID
|
||||
* @param frameData data to send
|
||||
*/
|
||||
public void onVirtualNetworkFrame(
|
||||
void onVirtualNetworkFrame(
|
||||
long nwid,
|
||||
long srcMac,
|
||||
long destMac,
|
||||
|
@ -29,80 +29,135 @@ package com.zerotier.sdk;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
public final class VirtualNetworkRoute implements Comparable<VirtualNetworkRoute>
|
||||
/**
|
||||
* A route to be pushed on a virtual network
|
||||
*
|
||||
* Defined in ZeroTierOne.h as ZT_VirtualNetworkRoute
|
||||
*/
|
||||
public class VirtualNetworkRoute implements Comparable<VirtualNetworkRoute>
|
||||
{
|
||||
private VirtualNetworkRoute() {
|
||||
target = null;
|
||||
via = null;
|
||||
flags = 0;
|
||||
metric = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Target network / netmask bits (in port field) or NULL or 0.0.0.0/0 for default
|
||||
*/
|
||||
public InetSocketAddress target;
|
||||
|
||||
private final InetSocketAddress target;
|
||||
|
||||
/**
|
||||
* Gateway IP address (port ignored) or NULL (family == 0) for LAN-local (no gateway)
|
||||
*/
|
||||
public InetSocketAddress via;
|
||||
private final InetSocketAddress via;
|
||||
|
||||
/**
|
||||
* Route flags
|
||||
*/
|
||||
public int flags;
|
||||
private final int flags;
|
||||
|
||||
/**
|
||||
* Route metric (not currently used)
|
||||
*/
|
||||
public int metric;
|
||||
private final int metric;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(target.toString());
|
||||
if (via != null) {
|
||||
sb.append(via.toString());
|
||||
}
|
||||
return sb.toString();
|
||||
public VirtualNetworkRoute(InetSocketAddress target, InetSocketAddress via, int flags, int metric) {
|
||||
this.target = target;
|
||||
this.via = via;
|
||||
this.flags = flags;
|
||||
this.metric = metric;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(VirtualNetworkRoute other) {
|
||||
return this.toString().compareTo(other.toString());
|
||||
}
|
||||
public String toString() {
|
||||
return "VirtualNetworkRoute(" + target + ", " + via + ", " + flags + ", " + metric + ")";
|
||||
}
|
||||
|
||||
public boolean equals(VirtualNetworkRoute other) {
|
||||
boolean targetEquals = false;
|
||||
if (target == null && other.target == null) {
|
||||
targetEquals = true;
|
||||
}
|
||||
else if (target == null && other.target != null) {
|
||||
targetEquals = false;
|
||||
}
|
||||
else if (target != null && other.target == null) {
|
||||
targetEquals = false;
|
||||
}
|
||||
else {
|
||||
targetEquals = target.toString().equals(other.target.toString());
|
||||
@Override
|
||||
public int compareTo(VirtualNetworkRoute other) {
|
||||
throw new RuntimeException("Unimplemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
|
||||
if (!(o instanceof VirtualNetworkRoute)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
VirtualNetworkRoute other = (VirtualNetworkRoute) o;
|
||||
|
||||
boolean targetEquals;
|
||||
if (target == null) {
|
||||
//noinspection RedundantIfStatement
|
||||
if (other.target == null) {
|
||||
targetEquals = true;
|
||||
} else {
|
||||
targetEquals = false;
|
||||
}
|
||||
} else {
|
||||
if (other.target == null) {
|
||||
targetEquals = false;
|
||||
} else {
|
||||
targetEquals = target.equals(other.target);
|
||||
}
|
||||
}
|
||||
|
||||
if (!targetEquals) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean viaEquals;
|
||||
if (via == null && other.via == null) {
|
||||
viaEquals = true;
|
||||
}
|
||||
else if (via == null && other.via != null) {
|
||||
viaEquals = false;
|
||||
}
|
||||
else if (via != null && other.via == null) {
|
||||
viaEquals = false;
|
||||
}
|
||||
else {
|
||||
viaEquals = via.toString().equals(other.via.toString());
|
||||
if (via == null) {
|
||||
//noinspection RedundantIfStatement
|
||||
if (other.via == null) {
|
||||
viaEquals = true;
|
||||
} else {
|
||||
viaEquals = false;
|
||||
}
|
||||
} else {
|
||||
if (other.via == null) {
|
||||
viaEquals = false;
|
||||
} else {
|
||||
viaEquals = via.equals(other.via);
|
||||
}
|
||||
}
|
||||
|
||||
return viaEquals && targetEquals;
|
||||
if (!viaEquals) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (flags != other.flags) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (metric != other.metric) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
int result = 17;
|
||||
result = 37 * result + (target == null ? 0 : target.hashCode());
|
||||
result = 37 * result + (via == null ? 0 : via.hashCode());
|
||||
result = 37 * result + flags;
|
||||
result = 37 * result + metric;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public InetSocketAddress getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public InetSocketAddress getVia() {
|
||||
return via;
|
||||
}
|
||||
|
||||
public int getFlags() {
|
||||
return flags;
|
||||
}
|
||||
|
||||
public int getMetric() {
|
||||
return metric;
|
||||
}
|
||||
}
|
||||
|
@ -24,41 +24,76 @@
|
||||
* redistribute it in a modified binary form, please contact ZeroTier Networks
|
||||
* LLC. Start here: http://www.zerotier.com/
|
||||
*/
|
||||
|
||||
package com.zerotier.sdk;
|
||||
|
||||
/**
|
||||
* Virtual network status codes
|
||||
*
|
||||
* Defined in ZeroTierOne.h as ZT_VirtualNetworkStatus
|
||||
*/
|
||||
public enum VirtualNetworkStatus {
|
||||
|
||||
/**
|
||||
* Waiting for network configuration (also means revision == 0)
|
||||
*/
|
||||
NETWORK_STATUS_REQUESTING_CONFIGURATION,
|
||||
NETWORK_STATUS_REQUESTING_CONFIGURATION(0),
|
||||
|
||||
/**
|
||||
* Configuration received and we are authorized
|
||||
*/
|
||||
NETWORK_STATUS_OK,
|
||||
|
||||
/**
|
||||
* Netconf master said SSO auth required.
|
||||
*/
|
||||
NETWORK_STATUS_AUTHENTICATION_REQUIRED,
|
||||
NETWORK_STATUS_OK(1),
|
||||
|
||||
/**
|
||||
* Netconf master told us 'nope'
|
||||
*/
|
||||
NETWORK_STATUS_ACCESS_DENIED,
|
||||
NETWORK_STATUS_ACCESS_DENIED(2),
|
||||
|
||||
/**
|
||||
* Netconf master exists, but this virtual network does not
|
||||
*/
|
||||
NETWORK_STATUS_NOT_FOUND,
|
||||
NETWORK_STATUS_NOT_FOUND(3),
|
||||
|
||||
/**
|
||||
* Initialization of network failed or other internal error
|
||||
*/
|
||||
NETWORK_STATUS_PORT_ERROR,
|
||||
NETWORK_STATUS_PORT_ERROR(4),
|
||||
|
||||
/**
|
||||
* ZeroTier One version too old
|
||||
*/
|
||||
NETWORK_STATUS_CLIENT_TOO_OLD
|
||||
NETWORK_STATUS_CLIENT_TOO_OLD(5),
|
||||
|
||||
/**
|
||||
* External authentication is required (e.g. SSO)
|
||||
*/
|
||||
NETWORK_STATUS_AUTHENTICATION_REQUIRED(6);
|
||||
|
||||
@SuppressWarnings({"FieldCanBeLocal", "unused"})
|
||||
private final int id;
|
||||
|
||||
VirtualNetworkStatus(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public static VirtualNetworkStatus fromInt(int id) {
|
||||
switch (id) {
|
||||
case 0:
|
||||
return NETWORK_STATUS_REQUESTING_CONFIGURATION;
|
||||
case 1:
|
||||
return NETWORK_STATUS_OK;
|
||||
case 2:
|
||||
return NETWORK_STATUS_ACCESS_DENIED;
|
||||
case 3:
|
||||
return NETWORK_STATUS_NOT_FOUND;
|
||||
case 4:
|
||||
return NETWORK_STATUS_PORT_ERROR;
|
||||
case 5:
|
||||
return NETWORK_STATUS_CLIENT_TOO_OLD;
|
||||
case 6:
|
||||
return NETWORK_STATUS_AUTHENTICATION_REQUIRED;
|
||||
default:
|
||||
throw new RuntimeException("Unhandled value: " + id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,16 +24,41 @@
|
||||
* redistribute it in a modified binary form, please contact ZeroTier Networks
|
||||
* LLC. Start here: http://www.zerotier.com/
|
||||
*/
|
||||
|
||||
package com.zerotier.sdk;
|
||||
|
||||
/**
|
||||
* Virtual network type codes
|
||||
*
|
||||
* Defined in ZeroTierOne.h as ZT_VirtualNetworkType
|
||||
*/
|
||||
public enum VirtualNetworkType {
|
||||
|
||||
/**
|
||||
* Private networks are authorized via certificates of membership
|
||||
*/
|
||||
NETWORK_TYPE_PRIVATE,
|
||||
NETWORK_TYPE_PRIVATE(0),
|
||||
|
||||
/**
|
||||
* Public networks have no access control -- they'll always be AUTHORIZED
|
||||
*/
|
||||
NETWORK_TYPE_PUBLIC
|
||||
NETWORK_TYPE_PUBLIC(1);
|
||||
|
||||
@SuppressWarnings({"FieldCanBeLocal", "unused"})
|
||||
private final int id;
|
||||
|
||||
VirtualNetworkType(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public static VirtualNetworkType fromInt(int id) {
|
||||
switch (id) {
|
||||
case 0:
|
||||
return NETWORK_TYPE_PRIVATE;
|
||||
case 1:
|
||||
return NETWORK_TYPE_PUBLIC;
|
||||
default:
|
||||
throw new RuntimeException("Unhandled value: " + id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
52
java/src/com/zerotier/sdk/util/StringUtils.java
Normal file
52
java/src/com/zerotier/sdk/util/StringUtils.java
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* ZeroTier One - Network Virtualization Everywhere
|
||||
* Copyright (C) 2011-2023 ZeroTier, Inc. https://www.zerotier.com/
|
||||
*/
|
||||
|
||||
package com.zerotier.sdk.util;
|
||||
|
||||
public class StringUtils {
|
||||
|
||||
/**
|
||||
* Convert mac address to string.
|
||||
*
|
||||
* @param mac MAC address
|
||||
* @return string in XX:XX:XX:XX:XX:XX format
|
||||
*/
|
||||
public static String macAddressToString(long mac) {
|
||||
|
||||
int[] macChars = new int[6];
|
||||
for (int i = 0; i < 6; i++) {
|
||||
macChars[i] = (int) (mac % 256);
|
||||
mac >>= 8;
|
||||
}
|
||||
|
||||
return String.format("%02x:%02x:%02x:%02x:%02x:%02x", macChars[5], macChars[4], macChars[3], macChars[2], macChars[1], macChars[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert long to hex string.
|
||||
*
|
||||
* @param networkId long
|
||||
* @return string with 0 padding
|
||||
*/
|
||||
public static String networkIdToString(long networkId) {
|
||||
return String.format("%016x", networkId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert node address to string.
|
||||
*
|
||||
* Node addresses are 40 bits, so print 10 hex characters.
|
||||
*
|
||||
* @param address Node address
|
||||
* @return formatted string
|
||||
*/
|
||||
public static String addressToString(long address) {
|
||||
return String.format("%010x", address);
|
||||
}
|
||||
|
||||
public static String etherTypeToString(long etherType) {
|
||||
return String.format("%04x", etherType);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user