mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-01-31 08:25:38 +00:00
make VirtualNetworkRoute a plain data class
This commit is contained in:
parent
d0c0585553
commit
809022b273
@ -110,15 +110,6 @@ jmethodID VirtualNetworkConfigOperation_fromInt_method;
|
||||
jmethodID VirtualNetworkStatus_fromInt_method;
|
||||
jmethodID VirtualNetworkType_fromInt_method;
|
||||
|
||||
//
|
||||
// Instance fields
|
||||
//
|
||||
|
||||
jfieldID VirtualNetworkRoute_flags_field;
|
||||
jfieldID VirtualNetworkRoute_metric_field;
|
||||
jfieldID VirtualNetworkRoute_target_field;
|
||||
jfieldID VirtualNetworkRoute_via_field;
|
||||
|
||||
//
|
||||
// Enums
|
||||
//
|
||||
@ -188,7 +179,7 @@ void setupJNICache(JavaVM *vm) {
|
||||
EXCEPTIONANDNULLCHECK(VirtualNetworkConfig_ctor = env->GetMethodID(VirtualNetworkConfig_class, "<init>", "(JJLjava/lang/String;Lcom/zerotier/sdk/VirtualNetworkStatus;Lcom/zerotier/sdk/VirtualNetworkType;IZZZIJ[Ljava/net/InetSocketAddress;[Lcom/zerotier/sdk/VirtualNetworkRoute;Lcom/zerotier/sdk/VirtualNetworkDNS;)V"));
|
||||
EXCEPTIONANDNULLCHECK(VirtualNetworkDNS_ctor = env->GetMethodID(VirtualNetworkDNS_class, "<init>", "(Ljava/lang/String;Ljava/util/ArrayList;)V"));
|
||||
EXCEPTIONANDNULLCHECK(VirtualNetworkFrameListener_onVirtualNetworkFrame_method = env->GetMethodID(VirtualNetworkFrameListener_class, "onVirtualNetworkFrame", "(JJJJJ[B)V"));
|
||||
EXCEPTIONANDNULLCHECK(VirtualNetworkRoute_ctor = env->GetMethodID(VirtualNetworkRoute_class, "<init>", "()V"));
|
||||
EXCEPTIONANDNULLCHECK(VirtualNetworkRoute_ctor = env->GetMethodID(VirtualNetworkRoute_class, "<init>", "(Ljava/net/InetSocketAddress;Ljava/net/InetSocketAddress;II)V"));
|
||||
|
||||
//
|
||||
// Static methods
|
||||
@ -202,15 +193,6 @@ void setupJNICache(JavaVM *vm) {
|
||||
EXCEPTIONANDNULLCHECK(VirtualNetworkStatus_fromInt_method = env->GetStaticMethodID(VirtualNetworkStatus_class, "fromInt", "(I)Lcom/zerotier/sdk/VirtualNetworkStatus;"));
|
||||
EXCEPTIONANDNULLCHECK(VirtualNetworkType_fromInt_method = env->GetStaticMethodID(VirtualNetworkType_class, "fromInt", "(I)Lcom/zerotier/sdk/VirtualNetworkType;"));
|
||||
|
||||
//
|
||||
// Instance fields
|
||||
//
|
||||
|
||||
EXCEPTIONANDNULLCHECK(VirtualNetworkRoute_flags_field = env->GetFieldID(VirtualNetworkRoute_class, "flags", "I"));
|
||||
EXCEPTIONANDNULLCHECK(VirtualNetworkRoute_metric_field = env->GetFieldID(VirtualNetworkRoute_class, "metric", "I"));
|
||||
EXCEPTIONANDNULLCHECK(VirtualNetworkRoute_target_field = env->GetFieldID(VirtualNetworkRoute_class, "target", "Ljava/net/InetSocketAddress;"));
|
||||
EXCEPTIONANDNULLCHECK(VirtualNetworkRoute_via_field = env->GetFieldID(VirtualNetworkRoute_class, "via", "Ljava/net/InetSocketAddress;"));
|
||||
|
||||
//
|
||||
// Enums
|
||||
//
|
||||
|
@ -79,15 +79,6 @@ extern jmethodID VirtualNetworkConfigOperation_fromInt_method;
|
||||
extern jmethodID VirtualNetworkStatus_fromInt_method;
|
||||
extern jmethodID VirtualNetworkType_fromInt_method;
|
||||
|
||||
//
|
||||
// Instance fields
|
||||
//
|
||||
|
||||
extern jfieldID VirtualNetworkRoute_flags_field;
|
||||
extern jfieldID VirtualNetworkRoute_metric_field;
|
||||
extern jfieldID VirtualNetworkRoute_target_field;
|
||||
extern jfieldID VirtualNetworkRoute_via_field;
|
||||
|
||||
//
|
||||
// Enums
|
||||
//
|
||||
|
@ -336,19 +336,34 @@ jobject newVersion(JNIEnv *env, int major, int minor, int rev)
|
||||
|
||||
jobject newVirtualNetworkRoute(JNIEnv *env, const ZT_VirtualNetworkRoute &route)
|
||||
{
|
||||
jobject routeObj = env->NewObject(VirtualNetworkRoute_class, VirtualNetworkRoute_ctor);
|
||||
if(env->ExceptionCheck() || routeObj == NULL)
|
||||
{
|
||||
//
|
||||
// may be NULL
|
||||
//
|
||||
jobject targetObj = newInetSocketAddress(env, route.target);
|
||||
if (env->ExceptionCheck()) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
jobject targetObj = newInetSocketAddress(env, route.target);
|
||||
//
|
||||
// may be NULL
|
||||
//
|
||||
jobject viaObj = newInetSocketAddress(env, route.via);
|
||||
if (env->ExceptionCheck()) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
env->SetObjectField(routeObj, VirtualNetworkRoute_target_field, targetObj);
|
||||
env->SetObjectField(routeObj, VirtualNetworkRoute_via_field, viaObj);
|
||||
env->SetIntField(routeObj, VirtualNetworkRoute_flags_field, (jint)route.flags);
|
||||
env->SetIntField(routeObj, VirtualNetworkRoute_metric_field, (jint)route.metric);
|
||||
jobject routeObj = env->NewObject(
|
||||
VirtualNetworkRoute_class,
|
||||
VirtualNetworkRoute_ctor,
|
||||
targetObj,
|
||||
viaObj,
|
||||
route.flags,
|
||||
route.metric);
|
||||
if(env->ExceptionCheck() || routeObj == NULL)
|
||||
{
|
||||
LOGE("Exception creating VirtualNetworkRoute");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return routeObj;
|
||||
}
|
||||
|
@ -29,34 +29,39 @@ 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;
|
||||
|
||||
public VirtualNetworkRoute(InetSocketAddress target, InetSocketAddress via, int flags, int metric) {
|
||||
this.target = target;
|
||||
this.via = via;
|
||||
this.flags = flags;
|
||||
this.metric = metric;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@ -139,4 +144,20 @@ public final class VirtualNetworkRoute implements Comparable<VirtualNetworkRoute
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public InetSocketAddress getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public InetSocketAddress getVia() {
|
||||
return via;
|
||||
}
|
||||
|
||||
public int getFlags() {
|
||||
return flags;
|
||||
}
|
||||
|
||||
public int getMetric() {
|
||||
return metric;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user