This commit is contained in:
zzz
2013-12-04 14:21:03 +00:00
parent 434b9fa0d1
commit 7b0b07933f
8 changed files with 40 additions and 105 deletions

View File

@@ -1,11 +1,5 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package net.i2p.i2ptunnel.udp; package net.i2p.i2ptunnel.udp;
// i2p
import net.i2p.client.I2PSession; import net.i2p.client.I2PSession;
import net.i2p.client.I2PSessionException; import net.i2p.client.I2PSessionException;
import net.i2p.data.Destination; import net.i2p.data.Destination;
@@ -19,17 +13,23 @@ import net.i2p.client.datagram.I2PDatagramMaker;
* @author welterde * @author welterde
*/ */
public class I2PSink implements Sink { public class I2PSink implements Sink {
public I2PSink(I2PSession sess, Destination dest) { public I2PSink(I2PSession sess, Destination dest) {
this(sess, dest, false); this(sess, dest, false);
} }
public I2PSink(I2PSession sess, Destination dest, boolean raw) { public I2PSink(I2PSession sess, Destination dest, boolean raw) {
this.sess = sess; this.sess = sess;
this.dest = dest; this.dest = dest;
this.raw = raw; this.raw = raw;
// create maker // create maker
if (!raw) if (raw) {
this.maker = null;
} else {
this.maker = new I2PDatagramMaker();
this.maker.setI2PDatagramMaker(this.sess); this.maker.setI2PDatagramMaker(this.sess);
}
} }
/** @param src ignored */ /** @param src ignored */
@@ -46,7 +46,8 @@ public class I2PSink implements Sink {
// send message // send message
try { 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); I2PSession.PORT_UNSPECIFIED, I2PSession.PORT_UNSPECIFIED);
} catch(I2PSessionException exc) { } catch(I2PSessionException exc) {
// TODO: handle better // TODO: handle better
@@ -54,8 +55,8 @@ public class I2PSink implements Sink {
} }
} }
protected boolean raw; protected final boolean raw;
protected I2PSession sess; protected final I2PSession sess;
protected Destination dest; protected final Destination dest;
protected final I2PDatagramMaker maker= new I2PDatagramMaker(); // FIXME should be final and use a factory. FIXME protected final I2PDatagramMaker maker;
} }

View File

@@ -1,11 +1,5 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package net.i2p.i2ptunnel.udp; package net.i2p.i2ptunnel.udp;
// i2p
import net.i2p.client.I2PSession; import net.i2p.client.I2PSession;
import net.i2p.client.I2PSessionException; import net.i2p.client.I2PSessionException;
import net.i2p.data.Destination; import net.i2p.data.Destination;
@@ -19,16 +13,22 @@ import net.i2p.client.datagram.I2PDatagramMaker;
* @author zzz modded from I2PSink by welterde * @author zzz modded from I2PSink by welterde
*/ */
public class I2PSinkAnywhere implements Sink { public class I2PSinkAnywhere implements Sink {
public I2PSinkAnywhere(I2PSession sess) { public I2PSinkAnywhere(I2PSession sess) {
this(sess, false); this(sess, false);
} }
public I2PSinkAnywhere(I2PSession sess, boolean raw) { public I2PSinkAnywhere(I2PSession sess, boolean raw) {
this.sess = sess; this.sess = sess;
this.raw = raw; this.raw = raw;
// create maker // create maker
if (!raw) if (raw) {
this.maker = null;
} else {
this.maker = new I2PDatagramMaker();
this.maker.setI2PDatagramMaker(this.sess); this.maker.setI2PDatagramMaker(this.sess);
}
} }
/** @param to - where it's going */ /** @param to - where it's going */
@@ -44,7 +44,8 @@ public class I2PSinkAnywhere implements Sink {
// send message // send message
try { 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); I2PSession.PORT_UNSPECIFIED, I2PSession.PORT_UNSPECIFIED);
} catch(I2PSessionException exc) { } catch(I2PSessionException exc) {
// TODO: handle better // TODO: handle better
@@ -52,8 +53,7 @@ public class I2PSinkAnywhere implements Sink {
} }
} }
protected boolean raw; protected final boolean raw;
protected I2PSession sess; protected final I2PSession sess;
protected Destination dest; protected final I2PDatagramMaker maker;
protected final I2PDatagramMaker maker = new I2PDatagramMaker();
} }

View File

@@ -1,15 +1,8 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package net.i2p.i2ptunnel.udp; package net.i2p.i2ptunnel.udp;
// system
import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
// i2p
import net.i2p.client.I2PSession; import net.i2p.client.I2PSession;
import net.i2p.client.I2PSessionListener; import net.i2p.client.I2PSessionListener;
import net.i2p.client.datagram.I2PDatagramDissector; import net.i2p.client.datagram.I2PDatagramDissector;
@@ -19,15 +12,17 @@ import net.i2p.client.datagram.I2PDatagramDissector;
* @author welterde * @author welterde
*/ */
public class I2PSource implements Source, Runnable { public class I2PSource implements Source, Runnable {
public I2PSource(I2PSession sess) { public I2PSource(I2PSession sess) {
this(sess, true, false); this(sess, true, false);
} }
public I2PSource(I2PSession sess, boolean verify) { public I2PSource(I2PSession sess, boolean verify) {
this(sess, verify, false); this(sess, verify, false);
} }
public I2PSource(I2PSession sess, boolean verify, boolean raw) { public I2PSource(I2PSession sess, boolean verify, boolean raw) {
this.sess = sess; this.sess = sess;
this.sink = null;
this.verify = verify; this.verify = verify;
this.raw = raw; this.raw = raw;
@@ -80,11 +75,6 @@ public class I2PSource implements Source, Runnable {
} }
} }
protected class Listener implements I2PSessionListener { protected class Listener implements I2PSessionListener {
public void messageAvailable(I2PSession sess, int id, long size) { public void messageAvailable(I2PSession sess, int id, long size) {
@@ -109,15 +99,10 @@ public class I2PSource implements Source, Runnable {
} }
protected final I2PSession sess;
protected final BlockingQueue<Integer> queue;
protected I2PSession sess;
protected BlockingQueue<Integer> queue;
protected Sink sink; protected Sink sink;
protected Thread thread; protected final Thread thread;
protected boolean verify; protected final boolean verify;
protected boolean raw; protected final boolean raw;
} }

View File

@@ -1,11 +1,5 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package net.i2p.i2ptunnel.udp; package net.i2p.i2ptunnel.udp;
// i2p
import net.i2p.data.Destination; import net.i2p.data.Destination;
/** /**

View File

@@ -1,8 +1,3 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package net.i2p.i2ptunnel.udp; package net.i2p.i2ptunnel.udp;
/** /**

View File

@@ -1,8 +1,3 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package net.i2p.i2ptunnel.udp; package net.i2p.i2ptunnel.udp;
/** /**

View File

@@ -1,16 +1,9 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package net.i2p.i2ptunnel.udp; package net.i2p.i2ptunnel.udp;
// system
import java.net.DatagramSocket; import java.net.DatagramSocket;
import java.net.DatagramPacket; import java.net.DatagramPacket;
import java.net.InetAddress; import java.net.InetAddress;
// i2p
import net.i2p.data.Destination; import net.i2p.data.Destination;
/** /**
@@ -18,6 +11,7 @@ import net.i2p.data.Destination;
* @author welterde * @author welterde
*/ */
public class UDPSink implements Sink { public class UDPSink implements Sink {
public UDPSink(InetAddress host, int port) { public UDPSink(InetAddress host, int port) {
// create socket // create socket
try { try {
@@ -61,17 +55,8 @@ public class UDPSink implements Sink {
this.sock.close(); this.sock.close();
} }
protected final DatagramSocket sock;
protected final InetAddress remoteHost;
protected final int remotePort;
protected DatagramSocket sock;
protected InetAddress remoteHost;
protected int remotePort;
} }

View File

@@ -1,11 +1,5 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package net.i2p.i2ptunnel.udp; package net.i2p.i2ptunnel.udp;
// system
import java.net.DatagramSocket; import java.net.DatagramSocket;
import java.net.DatagramPacket; import java.net.DatagramPacket;
@@ -15,9 +9,8 @@ import java.net.DatagramPacket;
*/ */
public class UDPSource implements Source, Runnable { public class UDPSource implements Source, Runnable {
public static final int MAX_SIZE = 15360; public static final int MAX_SIZE = 15360;
public UDPSource(int port) { public UDPSource(int port) {
this.sink = null;
// create udp-socket // create udp-socket
try { try {
this.sock = new DatagramSocket(port); this.sock = new DatagramSocket(port);
@@ -31,7 +24,6 @@ public class UDPSource implements Source, Runnable {
/** use socket from UDPSink */ /** use socket from UDPSink */
public UDPSource(DatagramSocket sock) { public UDPSource(DatagramSocket sock) {
this.sink = null;
this.sock = sock; this.sock = sock;
this.thread = new Thread(this); this.thread = new Thread(this);
} }
@@ -73,19 +65,7 @@ public class UDPSource implements Source, Runnable {
this.sock.close(); this.sock.close();
} }
protected final DatagramSocket sock;
protected DatagramSocket sock;
protected Sink sink; protected Sink sink;
protected Thread thread; protected final Thread thread;
} }