mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-01-19 03:06:26 +00:00
make PeerPhysicalPath a plain data class
This commit is contained in:
parent
7ef68a9d6a
commit
63f70ba465
@ -114,10 +114,6 @@ jmethodID VirtualNetworkType_fromInt_method;
|
||||
// Instance fields
|
||||
//
|
||||
|
||||
jfieldID PeerPhysicalPath_address_field;
|
||||
jfieldID PeerPhysicalPath_lastReceive_field;
|
||||
jfieldID PeerPhysicalPath_lastSend_field;
|
||||
jfieldID PeerPhysicalPath_preferred_field;
|
||||
jfieldID Peer_address_field;
|
||||
jfieldID Peer_latency_field;
|
||||
jfieldID Peer_paths_field;
|
||||
@ -211,7 +207,7 @@ void setupJNICache(JavaVM *vm) {
|
||||
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_onPathLookup_method = env->GetMethodID(PathChecker_class, "onPathLookup", "(JI)Ljava/net/InetSocketAddress;"));
|
||||
EXCEPTIONANDNULLCHECK(PeerPhysicalPath_ctor = env->GetMethodID(PeerPhysicalPath_class, "<init>", "()V"));
|
||||
EXCEPTIONANDNULLCHECK(PeerPhysicalPath_ctor = env->GetMethodID(PeerPhysicalPath_class, "<init>", "(Ljava/net/InetSocketAddress;JJZZ)V"));
|
||||
EXCEPTIONANDNULLCHECK(Peer_ctor = env->GetMethodID(Peer_class, "<init>", "()V"));
|
||||
EXCEPTIONANDNULLCHECK(Version_ctor = env->GetMethodID(Version_class, "<init>", "()V"));
|
||||
EXCEPTIONANDNULLCHECK(VirtualNetworkConfigListener_onNetworkConfigurationUpdated_method = env->GetMethodID(VirtualNetworkConfigListener_class, "onNetworkConfigurationUpdated", "(JLcom/zerotier/sdk/VirtualNetworkConfigOperation;Lcom/zerotier/sdk/VirtualNetworkConfig;)I"));
|
||||
@ -236,10 +232,6 @@ void setupJNICache(JavaVM *vm) {
|
||||
// Instance fields
|
||||
//
|
||||
|
||||
EXCEPTIONANDNULLCHECK(PeerPhysicalPath_address_field = env->GetFieldID(PeerPhysicalPath_class, "address", "Ljava/net/InetSocketAddress;"));
|
||||
EXCEPTIONANDNULLCHECK(PeerPhysicalPath_lastReceive_field = env->GetFieldID(PeerPhysicalPath_class, "lastReceive", "J"));
|
||||
EXCEPTIONANDNULLCHECK(PeerPhysicalPath_lastSend_field = env->GetFieldID(PeerPhysicalPath_class, "lastSend", "J"));
|
||||
EXCEPTIONANDNULLCHECK(PeerPhysicalPath_preferred_field = env->GetFieldID(PeerPhysicalPath_class, "preferred", "Z"));
|
||||
EXCEPTIONANDNULLCHECK(Peer_address_field = env->GetFieldID(Peer_class, "address", "J"));
|
||||
EXCEPTIONANDNULLCHECK(Peer_latency_field = env->GetFieldID(Peer_class, "latency", "I"));
|
||||
EXCEPTIONANDNULLCHECK(Peer_paths_field = env->GetFieldID(Peer_class, "paths", "[Lcom/zerotier/sdk/PeerPhysicalPath;"));
|
||||
|
@ -83,10 +83,6 @@ extern jmethodID VirtualNetworkType_fromInt_method;
|
||||
// Instance fields
|
||||
//
|
||||
|
||||
extern jfieldID PeerPhysicalPath_address_field;
|
||||
extern jfieldID PeerPhysicalPath_lastReceive_field;
|
||||
extern jfieldID PeerPhysicalPath_lastSend_field;
|
||||
extern jfieldID PeerPhysicalPath_preferred_field;
|
||||
extern jfieldID Peer_address_field;
|
||||
extern jfieldID Peer_latency_field;
|
||||
extern jfieldID Peer_paths_field;
|
||||
|
@ -201,26 +201,23 @@ jobject newPeerPhysicalPath(JNIEnv *env, const ZT_PeerPhysicalPath &ppp)
|
||||
{
|
||||
LOGV("newPeerPhysicalPath Called");
|
||||
|
||||
jobject pppObject = env->NewObject(PeerPhysicalPath_class, PeerPhysicalPath_ctor);
|
||||
if(env->ExceptionCheck() || pppObject == NULL)
|
||||
{
|
||||
LOGE("Error creating PPP object");
|
||||
return NULL; // out of memory
|
||||
}
|
||||
|
||||
jobject addressObject = newInetSocketAddress(env, ppp.address);
|
||||
if(env->ExceptionCheck() || addressObject == NULL) {
|
||||
LOGE("Error creating InetSocketAddress object");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
env->SetObjectField(pppObject, PeerPhysicalPath_address_field, addressObject);
|
||||
env->SetLongField(pppObject, PeerPhysicalPath_lastSend_field, ppp.lastSend);
|
||||
env->SetLongField(pppObject, PeerPhysicalPath_lastReceive_field, ppp.lastReceive);
|
||||
env->SetBooleanField(pppObject, PeerPhysicalPath_preferred_field, ppp.preferred);
|
||||
|
||||
if(env->ExceptionCheck()) {
|
||||
LOGE("Exception assigning fields to PeerPhysicalPath object");
|
||||
jobject pppObject = env->NewObject(
|
||||
PeerPhysicalPath_class,
|
||||
PeerPhysicalPath_ctor,
|
||||
addressObject,
|
||||
ppp.lastSend,
|
||||
ppp.lastReceive,
|
||||
ppp.preferred);
|
||||
if(env->ExceptionCheck() || pppObject == NULL)
|
||||
{
|
||||
LOGE("Error creating PPP object");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pppObject;
|
||||
|
@ -31,48 +31,72 @@ 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 fixed;
|
||||
|
||||
private final boolean preferred;
|
||||
|
||||
public PeerPhysicalPath(InetSocketAddress address, long lastSend, long lastReceive, boolean fixed, 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.fixed = fixed;
|
||||
this.preferred = preferred;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PeerPhysicalPath(" + address + ", " + lastSend + ", " + lastReceive + ", " + fixed + ", " + 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() {
|
||||
public boolean isFixed() {
|
||||
return fixed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is path preferred?
|
||||
*/
|
||||
public final boolean isPreferred() {
|
||||
public boolean isPreferred() {
|
||||
return preferred;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user