mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-05 20:13:44 +02:00
make NodeStatus a plain data class
This commit is contained in:
parent
acf5b3579b
commit
4861ec5a40
6 changed files with 75 additions and 63 deletions
|
@ -114,10 +114,6 @@ jmethodID VirtualNetworkType_fromInt_method;
|
||||||
// Instance fields
|
// Instance fields
|
||||||
//
|
//
|
||||||
|
|
||||||
jfieldID NodeStatus_address_field;
|
|
||||||
jfieldID NodeStatus_online_field;
|
|
||||||
jfieldID NodeStatus_publicIdentity_field;
|
|
||||||
jfieldID NodeStatus_secretIdentity_field;
|
|
||||||
jfieldID Node_configListener_field;
|
jfieldID Node_configListener_field;
|
||||||
jfieldID Node_eventListener_field;
|
jfieldID Node_eventListener_field;
|
||||||
jfieldID Node_frameListener_field;
|
jfieldID Node_frameListener_field;
|
||||||
|
@ -218,7 +214,7 @@ void setupJNICache(JavaVM *vm) {
|
||||||
EXCEPTIONANDNULLCHECK(InetSocketAddress_ctor = env->GetMethodID(InetSocketAddress_class, "<init>", "(Ljava/net/InetAddress;I)V"));
|
EXCEPTIONANDNULLCHECK(InetSocketAddress_ctor = env->GetMethodID(InetSocketAddress_class, "<init>", "(Ljava/net/InetAddress;I)V"));
|
||||||
EXCEPTIONANDNULLCHECK(InetSocketAddress_getAddress_method = env->GetMethodID(InetSocketAddress_class, "getAddress", "()Ljava/net/InetAddress;"));
|
EXCEPTIONANDNULLCHECK(InetSocketAddress_getAddress_method = env->GetMethodID(InetSocketAddress_class, "getAddress", "()Ljava/net/InetAddress;"));
|
||||||
EXCEPTIONANDNULLCHECK(InetSocketAddress_getPort_method = env->GetMethodID(InetSocketAddress_class, "getPort", "()I"));
|
EXCEPTIONANDNULLCHECK(InetSocketAddress_getPort_method = env->GetMethodID(InetSocketAddress_class, "getPort", "()I"));
|
||||||
EXCEPTIONANDNULLCHECK(NodeStatus_ctor = env->GetMethodID(NodeStatus_class, "<init>", "()V"));
|
EXCEPTIONANDNULLCHECK(NodeStatus_ctor = env->GetMethodID(NodeStatus_class, "<init>", "(JLjava/lang/String;Ljava/lang/String;Z)V"));
|
||||||
EXCEPTIONANDNULLCHECK(PacketSender_onSendPacketRequested_method = env->GetMethodID(PacketSender_class, "onSendPacketRequested", "(JLjava/net/InetSocketAddress;[BI)I"));
|
EXCEPTIONANDNULLCHECK(PacketSender_onSendPacketRequested_method = env->GetMethodID(PacketSender_class, "onSendPacketRequested", "(JLjava/net/InetSocketAddress;[BI)I"));
|
||||||
EXCEPTIONANDNULLCHECK(PathChecker_onPathCheck_method = env->GetMethodID(PathChecker_class, "onPathCheck", "(JJLjava/net/InetSocketAddress;)Z"));
|
EXCEPTIONANDNULLCHECK(PathChecker_onPathCheck_method = env->GetMethodID(PathChecker_class, "onPathCheck", "(JJLjava/net/InetSocketAddress;)Z"));
|
||||||
EXCEPTIONANDNULLCHECK(PathChecker_onPathLookup_method = env->GetMethodID(PathChecker_class, "onPathLookup", "(JI)Ljava/net/InetSocketAddress;"));
|
EXCEPTIONANDNULLCHECK(PathChecker_onPathLookup_method = env->GetMethodID(PathChecker_class, "onPathLookup", "(JI)Ljava/net/InetSocketAddress;"));
|
||||||
|
@ -247,10 +243,6 @@ void setupJNICache(JavaVM *vm) {
|
||||||
// Instance fields
|
// Instance fields
|
||||||
//
|
//
|
||||||
|
|
||||||
EXCEPTIONANDNULLCHECK(NodeStatus_address_field = env->GetFieldID(NodeStatus_class, "address", "J"));
|
|
||||||
EXCEPTIONANDNULLCHECK(NodeStatus_online_field = env->GetFieldID(NodeStatus_class, "online", "Z"));
|
|
||||||
EXCEPTIONANDNULLCHECK(NodeStatus_publicIdentity_field = env->GetFieldID(NodeStatus_class, "publicIdentity", "Ljava/lang/String;"));
|
|
||||||
EXCEPTIONANDNULLCHECK(NodeStatus_secretIdentity_field = env->GetFieldID(NodeStatus_class, "secretIdentity", "Ljava/lang/String;"));
|
|
||||||
EXCEPTIONANDNULLCHECK(Node_configListener_field = env->GetFieldID(Node_class, "configListener", "Lcom/zerotier/sdk/VirtualNetworkConfigListener;"));
|
EXCEPTIONANDNULLCHECK(Node_configListener_field = env->GetFieldID(Node_class, "configListener", "Lcom/zerotier/sdk/VirtualNetworkConfigListener;"));
|
||||||
EXCEPTIONANDNULLCHECK(Node_eventListener_field = env->GetFieldID(Node_class, "eventListener", "Lcom/zerotier/sdk/EventListener;"));
|
EXCEPTIONANDNULLCHECK(Node_eventListener_field = env->GetFieldID(Node_class, "eventListener", "Lcom/zerotier/sdk/EventListener;"));
|
||||||
EXCEPTIONANDNULLCHECK(Node_frameListener_field = env->GetFieldID(Node_class, "frameListener", "Lcom/zerotier/sdk/VirtualNetworkFrameListener;"));
|
EXCEPTIONANDNULLCHECK(Node_frameListener_field = env->GetFieldID(Node_class, "frameListener", "Lcom/zerotier/sdk/VirtualNetworkFrameListener;"));
|
||||||
|
|
|
@ -83,10 +83,6 @@ extern jmethodID VirtualNetworkType_fromInt_method;
|
||||||
// Instance fields
|
// Instance fields
|
||||||
//
|
//
|
||||||
|
|
||||||
extern jfieldID NodeStatus_address_field;
|
|
||||||
extern jfieldID NodeStatus_online_field;
|
|
||||||
extern jfieldID NodeStatus_publicIdentity_field;
|
|
||||||
extern jfieldID NodeStatus_secretIdentity_field;
|
|
||||||
extern jfieldID Node_configListener_field;
|
extern jfieldID Node_configListener_field;
|
||||||
extern jfieldID Node_eventListener_field;
|
extern jfieldID Node_eventListener_field;
|
||||||
extern jfieldID Node_frameListener_field;
|
extern jfieldID Node_frameListener_field;
|
||||||
|
|
|
@ -428,3 +428,34 @@ jobject newVirtualNetworkDNS(JNIEnv *env, const ZT_VirtualNetworkDNS &dns)
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jobject newNodeStatus(JNIEnv *env, const ZT_NodeStatus &status) {
|
||||||
|
|
||||||
|
jstring pubIdentStr = env->NewStringUTF(status.publicIdentity);
|
||||||
|
if(env->ExceptionCheck() || pubIdentStr == NULL)
|
||||||
|
{
|
||||||
|
LOGE("Exception creating new string");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
jstring secIdentStr = env->NewStringUTF(status.secretIdentity);
|
||||||
|
if(env->ExceptionCheck() || secIdentStr == NULL)
|
||||||
|
{
|
||||||
|
LOGE("Exception creating new string");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
jobject nodeStatusObj = env->NewObject(
|
||||||
|
NodeStatus_class,
|
||||||
|
NodeStatus_ctor,
|
||||||
|
status.address,
|
||||||
|
pubIdentStr,
|
||||||
|
secIdentStr,
|
||||||
|
status.online);
|
||||||
|
if(env->ExceptionCheck() || nodeStatusObj == NULL) {
|
||||||
|
LOGE("Exception creating new NodeStatus");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nodeStatusObj;
|
||||||
|
}
|
||||||
|
|
|
@ -96,4 +96,6 @@ jobject newVirtualNetworkRoute(JNIEnv *env, const ZT_VirtualNetworkRoute &route)
|
||||||
|
|
||||||
jobject newVirtualNetworkDNS(JNIEnv *env, const ZT_VirtualNetworkDNS &dns);
|
jobject newVirtualNetworkDNS(JNIEnv *env, const ZT_VirtualNetworkDNS &dns);
|
||||||
|
|
||||||
|
jobject newNodeStatus(JNIEnv *env, const ZT_NodeStatus &status);
|
||||||
|
|
||||||
#endif // ZT_jniutils_h_
|
#endif // ZT_jniutils_h_
|
||||||
|
|
|
@ -1126,41 +1126,11 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_status
|
||||||
{
|
{
|
||||||
int64_t nodeId = (int64_t) id;
|
int64_t nodeId = (int64_t) id;
|
||||||
ZT_Node *node = findNode(nodeId);
|
ZT_Node *node = findNode(nodeId);
|
||||||
if(node == NULL)
|
|
||||||
{
|
|
||||||
// cannot find valid node. We should never get here.
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// create a com.zerotier.sdk.NodeStatus object
|
|
||||||
jobject nodeStatusObj = env->NewObject(NodeStatus_class, NodeStatus_ctor);
|
|
||||||
if(nodeStatusObj == NULL)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
ZT_NodeStatus nodeStatus;
|
ZT_NodeStatus nodeStatus;
|
||||||
ZT_Node_status(node, &nodeStatus);
|
ZT_Node_status(node, &nodeStatus);
|
||||||
|
|
||||||
env->SetLongField(nodeStatusObj, NodeStatus_address_field, nodeStatus.address);
|
return newNodeStatus(env, nodeStatus);
|
||||||
|
|
||||||
jstring pubIdentStr = env->NewStringUTF(nodeStatus.publicIdentity);
|
|
||||||
if(pubIdentStr == NULL)
|
|
||||||
{
|
|
||||||
return NULL; // out of memory
|
|
||||||
}
|
|
||||||
env->SetObjectField(nodeStatusObj, NodeStatus_publicIdentity_field, pubIdentStr);
|
|
||||||
|
|
||||||
jstring secIdentStr = env->NewStringUTF(nodeStatus.secretIdentity);
|
|
||||||
if(secIdentStr == NULL)
|
|
||||||
{
|
|
||||||
return NULL; // out of memory
|
|
||||||
}
|
|
||||||
env->SetObjectField(nodeStatusObj, NodeStatus_secretIdentity_field, secIdentStr);
|
|
||||||
|
|
||||||
env->SetBooleanField(nodeStatusObj, NodeStatus_online_field, nodeStatus.online);
|
|
||||||
|
|
||||||
return nodeStatusObj;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -27,43 +27,64 @@
|
||||||
|
|
||||||
package com.zerotier.sdk;
|
package com.zerotier.sdk;
|
||||||
|
|
||||||
public final class NodeStatus {
|
import com.zerotier.sdk.util.StringUtils;
|
||||||
private long address;
|
|
||||||
private String publicIdentity;
|
|
||||||
private String secretIdentity;
|
|
||||||
private boolean online;
|
|
||||||
|
|
||||||
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
|
* 40-bit ZeroTier address of this node
|
||||||
*/
|
*/
|
||||||
public final long getAddress() {
|
public long getAddress() {
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Public identity in string-serialized form (safe to send to others)
|
* Public identity in string-serialized form (safe to send to others)
|
||||||
*
|
*
|
||||||
* <p>This identity will remain valid as long as the node exists.</p>
|
* <p>This identity will remain valid as long as the node exists.</p>
|
||||||
*/
|
*/
|
||||||
public final String getPublicIdentity() {
|
public String getPublicIdentity() {
|
||||||
return publicIdentity;
|
return publicIdentity;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Full identity including secret key in string-serialized form
|
* Full identity including secret key in string-serialized form
|
||||||
*
|
*
|
||||||
* <p>This identity will remain valid as long as the node exists.</p>
|
* <p>This identity will remain valid as long as the node exists.</p>
|
||||||
*/
|
*/
|
||||||
public final String getSecretIdentity() {
|
public String getSecretIdentity() {
|
||||||
return secretIdentity;
|
return secretIdentity;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* True if some kind of connectivity appears available
|
* True if some kind of connectivity appears available
|
||||||
*/
|
*/
|
||||||
public final boolean isOnline() {
|
public boolean isOnline() {
|
||||||
return online;
|
return online;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue