summaryrefslogtreecommitdiff
path: root/java/src/com
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com')
-rw-r--r--java/src/com/zerotier/one/AndroidFileProvider.java43
-rw-r--r--java/src/com/zerotier/one/DataStore.java73
-rw-r--r--java/src/com/zerotier/one/DataStoreFileProvider.java12
-rw-r--r--java/src/com/zerotier/one/JavaFileProvider.java46
-rw-r--r--java/src/com/zerotier/one/OneService.java204
-rw-r--r--java/src/com/zerotier/sdk/MulticastGroup.java4
-rw-r--r--java/src/com/zerotier/sdk/PeerRole.java8
-rw-r--r--java/src/com/zerotier/sdk/VirtualNetworkConfig.java38
8 files changed, 45 insertions, 383 deletions
diff --git a/java/src/com/zerotier/one/AndroidFileProvider.java b/java/src/com/zerotier/one/AndroidFileProvider.java
deleted file mode 100644
index 0988f9df..00000000
--- a/java/src/com/zerotier/one/AndroidFileProvider.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package com.zerotier.one;
-
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-
-import android.content.Context;
-import android.util.Log;
-
-public class AndroidFileProvider implements DataStoreFileProvider {
- private static final String TAG = "AndroidFileProvider";
-
- Context _ctx;
-
- public AndroidFileProvider(Context ctx) {
- this._ctx = ctx;
- }
-
- @Override
- public FileInputStream getInputFileStream(String name)
- throws FileNotFoundException {
- Log.d(TAG, "Returning FileInputStream for: " + name);
- return _ctx.openFileInput(name);
- }
-
- @Override
- public FileOutputStream getOutputFileStream(String name)
- throws FileNotFoundException {
- Log.d(TAG, "Returning FileOutputStream for: " + name);
- return _ctx.openFileOutput(name, Context.MODE_PRIVATE);
- }
-
- @Override
- public void deleteFile(String name) throws IOException {
- boolean success = _ctx.deleteFile(name);
- if(!success)
- {
- throw new IOException("Unable to delete file.");
- }
- }
-
-}
diff --git a/java/src/com/zerotier/one/DataStore.java b/java/src/com/zerotier/one/DataStore.java
deleted file mode 100644
index d15b2d3d..00000000
--- a/java/src/com/zerotier/one/DataStore.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package com.zerotier.one;
-
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-
-import com.zerotier.sdk.DataStoreGetListener;
-import com.zerotier.sdk.DataStorePutListener;
-
-public class DataStore implements DataStoreGetListener, DataStorePutListener {
-
- private DataStoreFileProvider _provider;
-
- public DataStore(DataStoreFileProvider provider) {
- this._provider = provider;
- }
-
- @Override
- public int onDataStorePut(String name, byte[] buffer, boolean secure) {
- System.out.println("Writing File: " + name);
- try {
- FileOutputStream fos = _provider.getOutputFileStream(name);
- fos.write(buffer);
- fos.close();
- return 0;
- } catch (FileNotFoundException fnf) {
- fnf.printStackTrace();
- return -1;
- } catch (IOException io) {
- io.printStackTrace();
- return -2;
- }
- }
-
- @Override
- public int onDelete(String name) {
- System.out.println("Deleting File: " + name);
- try {
- _provider.deleteFile(name);
- return 0;
- } catch (IOException ex) {
- ex.printStackTrace();
- return -1;
- }
- }
-
- @Override
- public long onDataStoreGet(String name, byte[] out_buffer,
- long bufferIndex, long[] out_objectSize) {
- System.out.println("Reading File: " + name);
- try {
- FileInputStream fin = _provider.getInputFileStream(name);
- out_objectSize[0] = fin.getChannel().size();
- if(bufferIndex > 0)
- {
- fin.skip(bufferIndex);
- }
- int read = fin.read(out_buffer);
- fin.close();
- return read;
- } catch (FileNotFoundException fnf) {
- // Can't read a file that doesn't exist!
- out_objectSize[0] = 0;
- return 0;
- } catch (IOException io) {
- io.printStackTrace();
- return -2;
- }
- }
-
-
-}
diff --git a/java/src/com/zerotier/one/DataStoreFileProvider.java b/java/src/com/zerotier/one/DataStoreFileProvider.java
deleted file mode 100644
index ffe078eb..00000000
--- a/java/src/com/zerotier/one/DataStoreFileProvider.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package com.zerotier.one;
-
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-
-public interface DataStoreFileProvider {
- FileInputStream getInputFileStream(String name) throws FileNotFoundException;
- FileOutputStream getOutputFileStream(String name) throws FileNotFoundException;
- void deleteFile(String name) throws IOException;
-}
diff --git a/java/src/com/zerotier/one/JavaFileProvider.java b/java/src/com/zerotier/one/JavaFileProvider.java
deleted file mode 100644
index 41889e2f..00000000
--- a/java/src/com/zerotier/one/JavaFileProvider.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package com.zerotier.one;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-
-public class JavaFileProvider implements DataStoreFileProvider {
- private String _path;
-
- public JavaFileProvider(String path) {
- this._path = path;
- }
-
- @Override
- public FileInputStream getInputFileStream(String name)
- throws FileNotFoundException {
- File f = new File(_path + File.separator + name);
- return new FileInputStream(f);
- }
-
- @Override
- public FileOutputStream getOutputFileStream(String name)
- throws FileNotFoundException {
- File f = new File(_path + File.separator + name);
- if(!f.exists())
- {
- try {
- f.createNewFile();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- return new FileOutputStream(f);
- }
-
- @Override
- public void deleteFile(String name) throws IOException {
- File f = new File(_path + File.separator + name);
- boolean success = f.delete();
- if(!success) {
- throw new IOException("Unable to delete file: " + _path + File.pathSeparator + name);
- }
- }
-}
diff --git a/java/src/com/zerotier/one/OneService.java b/java/src/com/zerotier/one/OneService.java
deleted file mode 100644
index 1d3e34c8..00000000
--- a/java/src/com/zerotier/one/OneService.java
+++ /dev/null
@@ -1,204 +0,0 @@
-/*
- * 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.one;
-
-import java.io.IOException;
-import java.net.DatagramPacket;
-import java.net.DatagramSocket;
-import java.net.InetSocketAddress;
-import java.net.ServerSocket;
-import java.net.SocketException;
-import java.net.SocketTimeoutException;
-
-import com.zerotier.sdk.Event;
-import com.zerotier.sdk.EventListener;
-import com.zerotier.sdk.Node;
-import com.zerotier.sdk.PacketSender;
-import com.zerotier.sdk.ResultCode;
-import com.zerotier.sdk.Version;
-import com.zerotier.sdk.VirtualNetworkConfig;
-import com.zerotier.sdk.VirtualNetworkConfigListener;
-import com.zerotier.sdk.VirtualNetworkConfigOperation;
-import com.zerotier.sdk.VirtualNetworkFrameListener;
-
-public class OneService extends Thread implements Runnable, PacketSender,
- EventListener, VirtualNetworkConfigListener,
- VirtualNetworkFrameListener {
- private Node _node;
- private int _port;
-
- private DatagramSocket _udpSocket;
- private ServerSocket _tcpSocket;
- private DataStore _ds;
- private long _nextBackgroundTaskDeadline = 0;
-
- private final Thread _udpReceiveThread = new Thread() {
- @Override
- public void run() {
- try {
- long[] bgtask = new long[1];
- byte[] buffer = new byte[16384];
- while(true) {
-
- bgtask[0] = 0;
- DatagramPacket p = new DatagramPacket(buffer, buffer.length);
-
- try {
- _udpSocket.receive(p);
- if(p.getLength() > 0)
- {
- System.out.println("Got Data From: " + p.getAddress().toString() +":" + p.getPort());
-
- _node.processWirePacket(System.currentTimeMillis(), new InetSocketAddress(p.getAddress(), p.getPort()), p.getData(), bgtask);
- _nextBackgroundTaskDeadline = bgtask[0];
- }
- } catch (SocketTimeoutException e) {}
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- };
-
-
- public OneService(DataStoreFileProvider prov, int port) {
- this._port = port;
- this._ds = new DataStore(prov);
-
- try {
- _udpSocket = new DatagramSocket(_port);
- _udpSocket.setSoTimeout(100);
- _tcpSocket = new ServerSocket();
- _tcpSocket.bind(new InetSocketAddress("127.0.0.1", _port));
- } catch (SocketException e) {
- e.printStackTrace();
- return;
- } catch (IOException e) {
- e.printStackTrace();
- return;
- }
-
- _udpReceiveThread.start();
-
- _node = new Node(
- System.currentTimeMillis(),
- _ds,
- _ds,
- this,
- this,
- this,
- this);
- }
-
- @Override
- public void run() {
- if(_node == null)
- return;
-
- while(true) {
- try {
-
- long dl = _nextBackgroundTaskDeadline;
- long now = System.currentTimeMillis();
-
- if (dl <= now) {
- long[] returnDeadline = {0};
- ResultCode rc = _node.processBackgroundTasks(now, returnDeadline);
- _nextBackgroundTaskDeadline = returnDeadline[0];
-
- if(rc != ResultCode.RESULT_OK) {
- System.out.println(rc.toString());
- }
- }
-
- long delay = (dl > now) ? (dl - now) : 100;
- Thread.sleep(delay);
-
- } catch (Exception ex) {
- System.out.println("Exception in run loop: " + ex.getMessage());
- ex.printStackTrace();
- }
- }
- }
-
- @Override
- public int onSendPacketRequested(InetSocketAddress addr, byte[] packetData) {
- System.out.println("onSendPacketRequested to: " + addr.getHostString() +":"+ addr.getPort() + " ");
-
- if(_udpSocket == null)
- return -1;
- try {
- DatagramPacket p = new DatagramPacket(packetData, packetData.length, addr);
- _udpSocket.send(p);
- System.out.println("Sent");
- } catch (Exception e) {
- System.out.println("Error sending datagram: " + e.getMessage());
- return -1;
- }
- return 0;
- }
-
- @Override
- public void onVirtualNetworkFrame(long nwid, long srcMac, long destMac,
- long etherType, long vlanId, byte[] frameData) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public int onNetworkConfigurationUpdated(long nwid,
- VirtualNetworkConfigOperation op, VirtualNetworkConfig config) {
- // TODO Auto-generated method stub
- return 0;
- }
-
- @Override
- public void onEvent(Event event) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void onNetworkError(Event event, InetSocketAddress source) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void onOutOfDate(Version newVersion) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void onTrace(String message) {
- // TODO Auto-generated method stub
-
- }
-}
diff --git a/java/src/com/zerotier/sdk/MulticastGroup.java b/java/src/com/zerotier/sdk/MulticastGroup.java
index 5c4df87a..68114424 100644
--- a/java/src/com/zerotier/sdk/MulticastGroup.java
+++ b/java/src/com/zerotier/sdk/MulticastGroup.java
@@ -33,6 +33,10 @@ public final class MulticastGroup {
private long mac;
private long adi;
+ public boolean equals(MulticastGroup other) {
+ return mac == other.mac && adi == other.adi;
+ }
+
/**
* MAC address (least significant 48 bits)
*/
diff --git a/java/src/com/zerotier/sdk/PeerRole.java b/java/src/com/zerotier/sdk/PeerRole.java
index 7a5156e1..d7d55f05 100644
--- a/java/src/com/zerotier/sdk/PeerRole.java
+++ b/java/src/com/zerotier/sdk/PeerRole.java
@@ -34,12 +34,12 @@ public enum PeerRole {
PEER_ROLE_LEAF,
/**
- * Locally federated hub
+ * relay node
*/
- PEER_ROLE_HUB,
+ PEER_ROLE_RELAY,
/**
- * planetary rootserver
+ * root server
*/
- PEER_ROLE_ROOTSERVER
+ PEER_ROLE_ROOT
} \ No newline at end of file
diff --git a/java/src/com/zerotier/sdk/VirtualNetworkConfig.java b/java/src/com/zerotier/sdk/VirtualNetworkConfig.java
index 2be03acb..278fafd2 100644
--- a/java/src/com/zerotier/sdk/VirtualNetworkConfig.java
+++ b/java/src/com/zerotier/sdk/VirtualNetworkConfig.java
@@ -27,11 +27,13 @@
package com.zerotier.sdk;
+import java.lang.Comparable;
+import java.lang.Override;
import java.lang.String;
import java.util.ArrayList;
import java.net.InetSocketAddress;
-public final class VirtualNetworkConfig {
+public final class VirtualNetworkConfig implements Comparable<VirtualNetworkConfig> {
public static final int MAX_MULTICAST_SUBSCRIPTIONS = 4096;
public static final int ZT1_MAX_ZT_ASSIGNED_ADDRESSES = 16;
@@ -54,6 +56,40 @@ public final class VirtualNetworkConfig {
}
+ public boolean equals(VirtualNetworkConfig cfg) {
+ boolean aaEqual = true;
+ if(assignedAddresses.length == cfg.assignedAddresses.length) {
+ for(int i = 0; i < assignedAddresses.length; ++i) {
+ if(!assignedAddresses[i].equals(cfg.assignedAddresses[i])) {
+ return false;
+ }
+ }
+ } else {
+ aaEqual = false;
+ }
+
+ return nwid == cfg.nwid &&
+ mac == cfg.mac &&
+ name.equals(cfg.name) &&
+ status.equals(cfg.status) &&
+ type.equals(cfg.type) &&
+ mtu == cfg.mtu &&
+ dhcp == cfg.dhcp &&
+ bridge == cfg.bridge &&
+ broadcastEnabled == cfg.broadcastEnabled &&
+ portError == cfg.portError &&
+ enabled == cfg.enabled &&
+ aaEqual;
+ }
+
+ public int compareTo(VirtualNetworkConfig cfg) {
+ if(cfg.nwid == this.nwid) {
+ return 0;
+ } else {
+ return this.nwid > cfg.nwid ? 1 : -1;
+ }
+ }
+
/**
* 64-bit ZeroTier network ID
*/