| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- /*
- * 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.zerotierone.sdk;
- import java.nio.ByteBuffer;
- import java.lang.Long;
- import java.net.InetAddress;
- import java.util.ArrayList;
- public class Node {
- static {
- System.loadLibrary("ZeroTierOneJNI");
- }
- private static final String TAG = "NODE";
- /**
- * Node ID for JNI purposes.
- * Currently set to the now value passed in at the constructor
- *
- * -1 if the node has already been closed
- */
- private long nodeId;
- private final DataStoreGetListener getListener;
- private final DataStorePutListener putListener;
- private final PacketSender sender;
- private final EventListener eventListener;
- private final VirtualNetworkFrameListener frameListener;
- private final VirtualNetworkConfigListener configListener;
-
- public Node(long now,
- DataStoreGetListener getListener,
- DataStorePutListener putListener,
- PacketSender sender,
- EventListener eventListener,
- VirtualNetworkFrameListener frameListener,
- VirtualNetworkConfigListener configListener)
- {
- this.nodeId = now;
- this.getListener = getListener;
- this.putListener = putListener;
- this.sender = sender;
- this.eventListener = eventListener;
- this.frameListener = frameListener;
- this.configListener = configListener;
- ResultCode rc = node_init(now);
- if(rc != ResultCode.RESULT_OK)
- {
- // TODO: Throw Exception
- }
- }
- public void close() {
- if(nodeId != -1) {
- node_delete(nodeId);
- nodeId = -1;
- }
- }
- @Override
- protected void finalize() {
- close();
- }
- public ResultCode processVirtualNetworkFrame(
- long now,
- long nwid,
- long sourceMac,
- long destMac,
- int etherType,
- int vlanId,
- byte[] frameData,
- long[] nextBackgroundTaskDeadline) {
- return processVirtualNetworkFrame(
- nodeId, now, nwid, sourceMac, destMac, etherType, vlanId,
- frameData, nextBackgroundTaskDeadline);
- }
- public ResultCode processWirePacket(
- long now,
- InetAddress remoteAddress,
- int linkDesperation,
- byte[] packetData,
- long[] nextBackgroundTaskDeadline) {
- return processWirePacket(
- nodeId, now, remoteAddress, linkDesperation, packetData,
- nextBackgroundTaskDeadline);
- }
- public ResultCode processBackgroundTasks(long now, long[] nextBackgroundTaskDeadline) {
- return processBackgroundTasks(nodeId, now, nextBackgroundTaskDeadline);
- }
- public ResultCode join(long nwid) {
- return join(nodeId, nwid);
- }
- public ResultCode leave(long nwid) {
- return leave(nodeId, nwid);
- }
- public ResultCode multicastSubscribe(
- long nwid,
- long multicastGroup) {
- return multicastSubscribe(nodeId, nwid, multicastGroup, 0);
- }
- public ResultCode multicastSubscribe(
- long nwid,
- long multicastGroup,
- long multicastAdi) {
- return multicastSubscribe(nodeId, nwid, multicastGroup, multicastAdi);
- }
- public ResultCode multicastUnsubscribe(
- long nwid,
- long multicastGroup) {
- return multicastUnsubscribe(nodeId, nwid, multicastGroup, 0);
- }
- public ResultCode multicastUnsubscribe(
- long nwid,
- long multicastGroup,
- long multicastAdi) {
- return multicastUnsubscribe(nodeId, nwid, multicastGroup, multicastAdi);
- }
- public long address() {
- return address(nodeId);
- }
- public NodeStatus status() {
- return status(nodeId);
- }
- public ArrayList<Peer> peers() {
- return peers(nodeId);
- }
- public VirtualNetworkConfig networkConfig(long nwid) {
- return networkConfig(nodeId, nwid);
- }
- public ArrayList<VirtualNetworkConfig> networks() {
- return networks(nodeId);
- }
- public Version getVersion() {
- return version();
- }
- /**
- * function declarations for JNI
- */
- private native ResultCode node_init(long now);
- private native void node_delete(long nodeId);
- private native ResultCode processVirtualNetworkFrame(
- long nodeId,
- long now,
- long nwid,
- long sourceMac,
- long destMac,
- int etherType,
- int vlanId,
- byte[] frameData,
- long[] nextBackgroundTaskDeadline);
- private native ResultCode processWirePacket(
- long nodeId,
- long now,
- InetAddress remoteAddress,
- int linkDesperation,
- byte[] packetData,
- long[] nextBackgroundTaskDeadline);
- private native ResultCode processBackgroundTasks(
- long nodeId,
- long now,
- long[] nextBackgroundTaskDeadline);
- private native ResultCode join(long nodeId, long nwid);
- private native ResultCode leave(long nodeId, long nwid);
- private native ResultCode multicastSubscribe(
- long nodeId,
- long nwid,
- long multicastGroup,
- long multicastAdi);
- private native ResultCode multicastUnsubscribe(
- long nodeId,
- long nwid,
- long multicastGroup,
- long multicastAdi);
- private native long address(long nodeId);
- private native NodeStatus status(long nodeId);
- private native VirtualNetworkConfig networkConfig(long nodeId, long nwid);
- private native Version version();
- private native ArrayList<Peer> peers(long nodeId);
- private native ArrayList<VirtualNetworkConfig> networks(long nodeId);
- }
|