From 7b0b07933fdbb632c1f715cf0922cb8a8ff00fd3 Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Wed, 4 Dec 2013 14:21:03 +0000
Subject: [PATCH] finals

---
 .../src/net/i2p/i2ptunnel/udp/I2PSink.java    | 25 ++++++++-------
 .../i2p/i2ptunnel/udp/I2PSinkAnywhere.java    | 24 +++++++-------
 .../src/net/i2p/i2ptunnel/udp/I2PSource.java  | 31 +++++--------------
 .../java/src/net/i2p/i2ptunnel/udp/Sink.java  |  6 ----
 .../src/net/i2p/i2ptunnel/udp/Source.java     |  5 ---
 .../src/net/i2p/i2ptunnel/udp/Stream.java     |  5 ---
 .../src/net/i2p/i2ptunnel/udp/UDPSink.java    | 23 +++-----------
 .../src/net/i2p/i2ptunnel/udp/UDPSource.java  | 26 ++--------------
 8 files changed, 40 insertions(+), 105 deletions(-)

diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/udp/I2PSink.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/udp/I2PSink.java
index c0e4c6693e..e4f47cdafb 100644
--- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/udp/I2PSink.java
+++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/udp/I2PSink.java
@@ -1,11 +1,5 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
 package net.i2p.i2ptunnel.udp;
 
-// i2p
 import net.i2p.client.I2PSession;
 import net.i2p.client.I2PSessionException;
 import net.i2p.data.Destination;
@@ -19,17 +13,23 @@ import net.i2p.client.datagram.I2PDatagramMaker;
  * @author welterde
  */
 public class I2PSink implements Sink {
+
     public I2PSink(I2PSession sess, Destination dest) {
         this(sess, dest, false);
     }
+
     public I2PSink(I2PSession sess, Destination dest, boolean raw) {
         this.sess = sess;
         this.dest = dest;
         this.raw = raw;
         
         // create maker
-        if (!raw)
+        if (raw) {
+            this.maker = null;
+        } else {
+            this.maker = new I2PDatagramMaker();
             this.maker.setI2PDatagramMaker(this.sess);
+        }
     }
     
     /** @param src ignored */
@@ -46,7 +46,8 @@ public class I2PSink implements Sink {
         
         // send message
         try {
-            this.sess.sendMessage(this.dest, payload, I2PSession.PROTO_DATAGRAM,
+            this.sess.sendMessage(this.dest, payload,
+                                  (this.raw ? I2PSession.PROTO_DATAGRAM_RAW : I2PSession.PROTO_DATAGRAM),
                                   I2PSession.PORT_UNSPECIFIED, I2PSession.PORT_UNSPECIFIED);
         } catch(I2PSessionException exc) {
             // TODO: handle better
@@ -54,8 +55,8 @@ public class I2PSink implements Sink {
         }
     }
     
-    protected boolean raw;
-    protected I2PSession sess;
-    protected Destination dest;
-    protected final I2PDatagramMaker maker= new I2PDatagramMaker(); // FIXME should be final and use a factory. FIXME
+    protected final boolean raw;
+    protected final I2PSession sess;
+    protected final Destination dest;
+    protected final I2PDatagramMaker maker;
 }
diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/udp/I2PSinkAnywhere.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/udp/I2PSinkAnywhere.java
index a2793e7dde..e33d93d107 100644
--- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/udp/I2PSinkAnywhere.java
+++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/udp/I2PSinkAnywhere.java
@@ -1,11 +1,5 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
 package net.i2p.i2ptunnel.udp;
 
-// i2p
 import net.i2p.client.I2PSession;
 import net.i2p.client.I2PSessionException;
 import net.i2p.data.Destination;
@@ -19,16 +13,22 @@ import net.i2p.client.datagram.I2PDatagramMaker;
  * @author zzz modded from I2PSink by welterde
  */
 public class I2PSinkAnywhere implements Sink {
+
     public I2PSinkAnywhere(I2PSession sess) {
         this(sess, false);
     }
+
     public I2PSinkAnywhere(I2PSession sess, boolean raw) {
         this.sess = sess;
         this.raw = raw;
         
         // create maker
-        if (!raw)
+        if (raw) {
+            this.maker = null;
+        } else {
+            this.maker = new I2PDatagramMaker();
             this.maker.setI2PDatagramMaker(this.sess);
+        }
     }
     
     /** @param to - where it's going */
@@ -44,7 +44,8 @@ public class I2PSinkAnywhere implements Sink {
         
         // send message
         try {
-            this.sess.sendMessage(to, payload, I2PSession.PROTO_DATAGRAM,
+            this.sess.sendMessage(to, payload,
+                                  (this.raw ? I2PSession.PROTO_DATAGRAM_RAW : I2PSession.PROTO_DATAGRAM),
                                   I2PSession.PORT_UNSPECIFIED, I2PSession.PORT_UNSPECIFIED);
         } catch(I2PSessionException exc) {
             // TODO: handle better
@@ -52,8 +53,7 @@ public class I2PSinkAnywhere implements Sink {
         }
     }
     
-    protected boolean raw;
-    protected I2PSession sess;
-    protected Destination dest;
-    protected final I2PDatagramMaker maker = new I2PDatagramMaker();
+    protected final boolean raw;
+    protected final I2PSession sess;
+    protected final I2PDatagramMaker maker;
 }
diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/udp/I2PSource.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/udp/I2PSource.java
index 04a8bde6a0..68a9d90a27 100644
--- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/udp/I2PSource.java
+++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/udp/I2PSource.java
@@ -1,15 +1,8 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
 package net.i2p.i2ptunnel.udp;
 
-// system
 import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.BlockingQueue;
 
-// i2p
 import net.i2p.client.I2PSession;
 import net.i2p.client.I2PSessionListener;
 import net.i2p.client.datagram.I2PDatagramDissector;
@@ -19,15 +12,17 @@ import net.i2p.client.datagram.I2PDatagramDissector;
  * @author welterde
  */
 public class I2PSource implements Source, Runnable {
+
     public I2PSource(I2PSession sess) {
         this(sess, true, false);
     }
+
     public I2PSource(I2PSession sess, boolean verify) {
         this(sess, verify, false);
     }
+
     public I2PSource(I2PSession sess, boolean verify, boolean raw) {
         this.sess = sess;
-        this.sink = null;
         this.verify = verify;
         this.raw = raw;
         
@@ -80,11 +75,6 @@ public class I2PSource implements Source, Runnable {
         }
     }
     
-    
-    
-    
-    
-    
     protected class Listener implements I2PSessionListener {
 
         public void messageAvailable(I2PSession sess, int id, long size) {
@@ -109,15 +99,10 @@ public class I2PSource implements Source, Runnable {
         
     }
     
-    
-    
-    
-    
-    
-    protected I2PSession sess;
-    protected BlockingQueue<Integer> queue;
+    protected final I2PSession sess;
+    protected final BlockingQueue<Integer> queue;
     protected Sink sink;
-    protected Thread thread;
-    protected boolean verify;
-    protected boolean raw;
+    protected final Thread thread;
+    protected final boolean verify;
+    protected final boolean raw;
 }
diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/udp/Sink.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/udp/Sink.java
index 49e3e47a3e..a3ddc6b84e 100644
--- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/udp/Sink.java
+++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/udp/Sink.java
@@ -1,11 +1,5 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
 package net.i2p.i2ptunnel.udp;
 
-// i2p
 import net.i2p.data.Destination;
 
 /**
diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/udp/Source.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/udp/Source.java
index f65d03b196..c1929cfe74 100644
--- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/udp/Source.java
+++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/udp/Source.java
@@ -1,8 +1,3 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
 package net.i2p.i2ptunnel.udp;
 
 /**
diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/udp/Stream.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/udp/Stream.java
index b8b57e696c..f0a79a801b 100644
--- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/udp/Stream.java
+++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/udp/Stream.java
@@ -1,8 +1,3 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
 package net.i2p.i2ptunnel.udp;
 
 /**
diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/udp/UDPSink.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/udp/UDPSink.java
index d2e8e89247..0b5905ad7e 100644
--- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/udp/UDPSink.java
+++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/udp/UDPSink.java
@@ -1,16 +1,9 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
 package net.i2p.i2ptunnel.udp;
 
-// system
 import java.net.DatagramSocket;
 import java.net.DatagramPacket;
 import java.net.InetAddress;
 
-// i2p
 import net.i2p.data.Destination;
 
 /**
@@ -18,6 +11,7 @@ import net.i2p.data.Destination;
  * @author welterde
  */
 public class UDPSink implements Sink {
+
     public UDPSink(InetAddress host, int port) {
         // create socket
         try {
@@ -61,17 +55,8 @@ public class UDPSink implements Sink {
         this.sock.close();    
     }    
     
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    protected DatagramSocket sock;
-    protected InetAddress remoteHost;
-    protected int remotePort;
+    protected final DatagramSocket sock;
+    protected final InetAddress remoteHost;
+    protected final int remotePort;
 
 }
diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/udp/UDPSource.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/udp/UDPSource.java
index fc1dd5bf22..6f1a20e5ff 100644
--- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/udp/UDPSource.java
+++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/udp/UDPSource.java
@@ -1,11 +1,5 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
 package net.i2p.i2ptunnel.udp;
 
-// system
 import java.net.DatagramSocket;
 import java.net.DatagramPacket;
 
@@ -15,9 +9,8 @@ import java.net.DatagramPacket;
  */
 public class UDPSource implements Source, Runnable {
     public static final int MAX_SIZE = 15360;
+
     public UDPSource(int port) {
-        this.sink = null;
-        
         // create udp-socket
         try {
             this.sock = new DatagramSocket(port);
@@ -31,7 +24,6 @@ public class UDPSource implements Source, Runnable {
 
     /** use socket from UDPSink */
     public UDPSource(DatagramSocket sock) {
-        this.sink = null;
         this.sock = sock;
         this.thread = new Thread(this);
     }
@@ -73,19 +65,7 @@ public class UDPSource implements Source, Runnable {
         this.sock.close();    
     }    
     
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    protected DatagramSocket sock;
+    protected final DatagramSocket sock;
     protected Sink sink;
-    protected Thread thread;
+    protected final Thread thread;
 }
-- 
GitLab