mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-06 12:33:44 +02:00
Merge branch 'dev' of http://10.6.6.2/zerotier/ZeroTierOne into dev
This commit is contained in:
commit
3790ebe77a
6 changed files with 239 additions and 5 deletions
|
@ -11,14 +11,14 @@ LOCAL_LDLIBS := -llog
|
||||||
# ZeroTierOne SDK source files
|
# ZeroTierOne SDK source files
|
||||||
LOCAL_SRC_FILES := \
|
LOCAL_SRC_FILES := \
|
||||||
$(ZT1)/ext/lz4/lz4.c \
|
$(ZT1)/ext/lz4/lz4.c \
|
||||||
$(ZT1)/ext/json-parser/json.c \
|
|
||||||
$(ZT1)/ext/http-parser/http_parser.c \
|
$(ZT1)/ext/http-parser/http_parser.c \
|
||||||
$(ZT1)/node/C25519.cpp \
|
$(ZT1)/node/C25519.cpp \
|
||||||
|
$(ZT1)/node/Capability.cpp \
|
||||||
$(ZT1)/node/CertificateOfMembership.cpp \
|
$(ZT1)/node/CertificateOfMembership.cpp \
|
||||||
$(ZT1)/node/DeferredPackets.cpp \
|
|
||||||
$(ZT1)/node/Identity.cpp \
|
$(ZT1)/node/Identity.cpp \
|
||||||
$(ZT1)/node/IncomingPacket.cpp \
|
$(ZT1)/node/IncomingPacket.cpp \
|
||||||
$(ZT1)/node/InetAddress.cpp \
|
$(ZT1)/node/InetAddress.cpp \
|
||||||
|
$(ZT1)/node/Membership.cpp \
|
||||||
$(ZT1)/node/Multicaster.cpp \
|
$(ZT1)/node/Multicaster.cpp \
|
||||||
$(ZT1)/node/Network.cpp \
|
$(ZT1)/node/Network.cpp \
|
||||||
$(ZT1)/node/NetworkConfig.cpp \
|
$(ZT1)/node/NetworkConfig.cpp \
|
||||||
|
@ -32,6 +32,7 @@ LOCAL_SRC_FILES := \
|
||||||
$(ZT1)/node/SelfAwareness.cpp \
|
$(ZT1)/node/SelfAwareness.cpp \
|
||||||
$(ZT1)/node/SHA512.cpp \
|
$(ZT1)/node/SHA512.cpp \
|
||||||
$(ZT1)/node/Switch.cpp \
|
$(ZT1)/node/Switch.cpp \
|
||||||
|
$(ZT1)/node/Tag.cpp \
|
||||||
$(ZT1)/node/Topology.cpp \
|
$(ZT1)/node/Topology.cpp \
|
||||||
$(ZT1)/node/Utils.cpp \
|
$(ZT1)/node/Utils.cpp \
|
||||||
$(ZT1)/osdep/Http.cpp \
|
$(ZT1)/osdep/Http.cpp \
|
||||||
|
|
|
@ -609,6 +609,7 @@ jobject newNetworkConfig(JNIEnv *env, const ZT_VirtualNetworkConfig &vnetConfig)
|
||||||
jfieldID portErrorField = NULL;
|
jfieldID portErrorField = NULL;
|
||||||
jfieldID netconfRevisionField = NULL;
|
jfieldID netconfRevisionField = NULL;
|
||||||
jfieldID assignedAddressesField = NULL;
|
jfieldID assignedAddressesField = NULL;
|
||||||
|
jfieldID routesField = NULL;
|
||||||
|
|
||||||
vnetConfigClass = lookup.findClass("com/zerotier/sdk/VirtualNetworkConfig");
|
vnetConfigClass = lookup.findClass("com/zerotier/sdk/VirtualNetworkConfig");
|
||||||
if(vnetConfigClass == NULL)
|
if(vnetConfigClass == NULL)
|
||||||
|
@ -716,6 +717,13 @@ jobject newNetworkConfig(JNIEnv *env, const ZT_VirtualNetworkConfig &vnetConfig)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
routesField = lookup.findField(vnetConfigClass, "routes", "[Lcom/zerotier/sdk/VirtualNetworkRoute");
|
||||||
|
if(env->ExceptionCheck() || routesField == NULL)
|
||||||
|
{
|
||||||
|
LOGE("Error getting routes field");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
env->SetLongField(vnetConfigObj, nwidField, vnetConfig.nwid);
|
env->SetLongField(vnetConfigObj, nwidField, vnetConfig.nwid);
|
||||||
env->SetLongField(vnetConfigObj, macField, vnetConfig.mac);
|
env->SetLongField(vnetConfigObj, macField, vnetConfig.mac);
|
||||||
jstring nameStr = env->NewStringUTF(vnetConfig.name);
|
jstring nameStr = env->NewStringUTF(vnetConfig.name);
|
||||||
|
@ -773,6 +781,34 @@ jobject newNetworkConfig(JNIEnv *env, const ZT_VirtualNetworkConfig &vnetConfig)
|
||||||
|
|
||||||
env->SetObjectField(vnetConfigObj, assignedAddressesField, assignedAddrArrayObj);
|
env->SetObjectField(vnetConfigObj, assignedAddressesField, assignedAddrArrayObj);
|
||||||
|
|
||||||
|
jclass virtualNetworkRouteClass = lookup.findClass("com/zerotier/sdk/VirtualNetworkRoute");
|
||||||
|
if(env->ExceptionCheck() || virtualNetworkRouteClass == NULL)
|
||||||
|
{
|
||||||
|
LOGE("Error finding VirtualNetworkRoute class");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
jobjectArray routesArrayObj = env->NewObjectArray(
|
||||||
|
vnetConfig.routeCount, virtualNetworkRouteClass, NULL);
|
||||||
|
if(env->ExceptionCheck() || routesArrayObj == NULL)
|
||||||
|
{
|
||||||
|
LOGE("Error creating VirtualNetworkRoute[] array");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(unsigned int i = 0; i < vnetConfig.routeCount; ++i)
|
||||||
|
{
|
||||||
|
jobject routeObj = newVirtualNetworkRoute(env, vnetConfig.routes[i]);
|
||||||
|
env->SetObjectArrayElement(routesArrayObj, i, routeObj);
|
||||||
|
if(env->ExceptionCheck())
|
||||||
|
{
|
||||||
|
LOGE("Error assigning VirtualNetworkRoute to array");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
env->SetObjectField(vnetConfigObj, routesField, routesArrayObj);
|
||||||
|
|
||||||
return vnetConfigObj;
|
return vnetConfigObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -831,6 +867,72 @@ jobject newVersion(JNIEnv *env, int major, int minor, int rev)
|
||||||
return versionObj;
|
return versionObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jobject newVirtualNetworkRoute(JNIEnv *env, const ZT_VirtualNetworkRoute &route)
|
||||||
|
{
|
||||||
|
jclass virtualNetworkRouteClass = NULL;
|
||||||
|
jmethodID routeConstructor = NULL;
|
||||||
|
|
||||||
|
virtualNetworkRouteClass = lookup.findClass("com/zerotier/sdk/VirtualNetworkRoute");
|
||||||
|
if(env->ExceptionCheck() || virtualNetworkRouteClass == NULL)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
routeConstructor = lookup.findMethod(virtualNetworkRouteClass, "<init>", "()V");
|
||||||
|
if(env->ExceptionCheck() || routeConstructor == NULL)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
jobject routeObj = env->NewObject(virtualNetworkRouteClass, routeConstructor);
|
||||||
|
if(env->ExceptionCheck() || routeObj == NULL)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
jfieldID targetField = NULL;
|
||||||
|
jfieldID viaField = NULL;
|
||||||
|
jfieldID flagsField = NULL;
|
||||||
|
jfieldID metricField = NULL;
|
||||||
|
|
||||||
|
targetField = lookup.findField(virtualNetworkRouteClass, "target",
|
||||||
|
"Ljava/net/InetSocketAddress");
|
||||||
|
if(env->ExceptionCheck() || targetField == NULL)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
viaField = lookup.findField(virtualNetworkRouteClass, "via",
|
||||||
|
"Ljava/net/InetSocketAddress");
|
||||||
|
if(env->ExceptionCheck() || targetField == NULL)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
flagsField = lookup.findField(virtualNetworkRouteClass, "flags", "I");
|
||||||
|
if(env->ExceptionCheck() || flagsField == NULL)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
metricField = lookup.findField(virtualNetworkRouteClass, "metric", "I");
|
||||||
|
if(env->ExceptionCheck() || metricField == NULL)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
jobject targetObj = newInetSocketAddress(env, route.target);
|
||||||
|
jobject viaObj = newInetSocketAddress(env, route.via);
|
||||||
|
|
||||||
|
env->SetObjectField(routeObj, targetField, targetObj);
|
||||||
|
env->SetObjectField(routeObj, viaField, viaObj);
|
||||||
|
env->SetIntField(routeObj, flagsField, (jint)route.flags);
|
||||||
|
env->SetIntField(routeObj, metricField, (jint)route.metric);
|
||||||
|
|
||||||
|
return routeObj;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,8 @@ jobject newNetworkConfig(JNIEnv *env, const ZT_VirtualNetworkConfig &config);
|
||||||
|
|
||||||
jobject newVersion(JNIEnv *env, int major, int minor, int rev);
|
jobject newVersion(JNIEnv *env, int major, int minor, int rev);
|
||||||
|
|
||||||
|
jobject newVirtualNetworkRoute(JNIEnv *env, const ZT_VirtualNetworkRoute &route);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -50,6 +50,7 @@ public final class VirtualNetworkConfig implements Comparable<VirtualNetworkConf
|
||||||
private boolean enabled;
|
private boolean enabled;
|
||||||
private long netconfRevision;
|
private long netconfRevision;
|
||||||
private InetSocketAddress[] assignedAddresses;
|
private InetSocketAddress[] assignedAddresses;
|
||||||
|
private VirtualNetworkRoute[] routes;
|
||||||
|
|
||||||
private VirtualNetworkConfig() {
|
private VirtualNetworkConfig() {
|
||||||
|
|
||||||
|
@ -60,13 +61,24 @@ public final class VirtualNetworkConfig implements Comparable<VirtualNetworkConf
|
||||||
if(assignedAddresses.length == cfg.assignedAddresses.length) {
|
if(assignedAddresses.length == cfg.assignedAddresses.length) {
|
||||||
for(int i = 0; i < assignedAddresses.length; ++i) {
|
for(int i = 0; i < assignedAddresses.length; ++i) {
|
||||||
if(!assignedAddresses[i].equals(cfg.assignedAddresses[i])) {
|
if(!assignedAddresses[i].equals(cfg.assignedAddresses[i])) {
|
||||||
return false;
|
aaEqual = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
aaEqual = false;
|
aaEqual = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean routesEqual = true;
|
||||||
|
if(routes.length == cfg.routes.length) {
|
||||||
|
for (int i = 0; i < routes.length; ++i) {
|
||||||
|
if (!routes[i].equals(cfg.routes[i])) {
|
||||||
|
routesEqual = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
routesEqual = false;
|
||||||
|
}
|
||||||
|
|
||||||
return nwid == cfg.nwid &&
|
return nwid == cfg.nwid &&
|
||||||
mac == cfg.mac &&
|
mac == cfg.mac &&
|
||||||
name.equals(cfg.name) &&
|
name.equals(cfg.name) &&
|
||||||
|
@ -78,7 +90,7 @@ public final class VirtualNetworkConfig implements Comparable<VirtualNetworkConf
|
||||||
broadcastEnabled == cfg.broadcastEnabled &&
|
broadcastEnabled == cfg.broadcastEnabled &&
|
||||||
portError == cfg.portError &&
|
portError == cfg.portError &&
|
||||||
enabled == cfg.enabled &&
|
enabled == cfg.enabled &&
|
||||||
aaEqual;
|
aaEqual && routesEqual;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int compareTo(VirtualNetworkConfig cfg) {
|
public int compareTo(VirtualNetworkConfig cfg) {
|
||||||
|
@ -188,4 +200,11 @@ public final class VirtualNetworkConfig implements Comparable<VirtualNetworkConf
|
||||||
public final InetSocketAddress[] assignedAddresses() {
|
public final InetSocketAddress[] assignedAddresses() {
|
||||||
return assignedAddresses;
|
return assignedAddresses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ZeroTier-assigned routes (in {@link com.zerotier.sdk.VirtualNetworkRoute} objects)
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public final VirtualNetworkRoute[] routes() { return routes; }
|
||||||
}
|
}
|
||||||
|
|
55
java/src/com/zerotier/sdk/VirtualNetworkRoute.java
Normal file
55
java/src/com/zerotier/sdk/VirtualNetworkRoute.java
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
/*
|
||||||
|
* ZeroTier One - Network Virtualization Everywhere
|
||||||
|
* Copyright (C) 2011-2015 ZeroTier, Inc.
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
*
|
||||||
|
* --
|
||||||
|
*
|
||||||
|
* ZeroTier may be used and distributed under the terms of the GPLv3, which
|
||||||
|
* are available at: http://www.gnu.org/licenses/gpl-3.0.html
|
||||||
|
*
|
||||||
|
* If you would like to embed ZeroTier into a commercial application or
|
||||||
|
* 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 class VirtualNetworkRoute
|
||||||
|
{
|
||||||
|
private VirtualNetworkRoute() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Target network / netmask bits (in port field) or NULL or 0.0.0.0/0 for default
|
||||||
|
*/
|
||||||
|
public InetSocketAddress target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gateway IP address (port ignored) or NULL (family == 0) for LAN-local (no gateway)
|
||||||
|
*/
|
||||||
|
public InetSocketAddress via;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Route flags
|
||||||
|
*/
|
||||||
|
public int flags;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Route metric (not currently used)
|
||||||
|
*/
|
||||||
|
public int metric;
|
||||||
|
}
|
55
java/src/com/zerotier/sdk/VirtualnetworkRoute.java
Normal file
55
java/src/com/zerotier/sdk/VirtualnetworkRoute.java
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
/*
|
||||||
|
* ZeroTier One - Network Virtualization Everywhere
|
||||||
|
* Copyright (C) 2011-2015 ZeroTier, Inc.
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
*
|
||||||
|
* --
|
||||||
|
*
|
||||||
|
* ZeroTier may be used and distributed under the terms of the GPLv3, which
|
||||||
|
* are available at: http://www.gnu.org/licenses/gpl-3.0.html
|
||||||
|
*
|
||||||
|
* If you would like to embed ZeroTier into a commercial application or
|
||||||
|
* 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 class VirtualNetworkRoute
|
||||||
|
{
|
||||||
|
private VirtualNetworkRoute() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Target network / netmask bits (in port field) or NULL or 0.0.0.0/0 for default
|
||||||
|
*/
|
||||||
|
public InetSocketAddress target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gateway IP address (port ignored) or NULL (family == 0) for LAN-local (no gateway)
|
||||||
|
*/
|
||||||
|
public InetSocketAddress via;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Route flags
|
||||||
|
*/
|
||||||
|
public int flags;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Route metric (not currently used)
|
||||||
|
*/
|
||||||
|
public int metric;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue