use of net.i2p.util.I2PAppThread in project i2p.i2p by i2p.
the class SAMMessageSession method start.
/*
* @since 0.9.25
*/
public void start() {
Thread t = new I2PAppThread(handler, "SAMMessageSessionHandler");
t.start();
}
use of net.i2p.util.I2PAppThread in project i2p.i2p by i2p.
the class SAMStreamSession method createSocketHandler.
/**
* Create a new SAM STREAM session socket handler, detaching its thread.
*
* @param s Socket to be handled
* @param id Socket id, or 0 if it must be auto-generated
*
* @return An id associated to the socket handler
*/
protected int createSocketHandler(I2PSocket s, int id) {
SAMStreamSessionSocketReader reader = null;
StreamSender sender = null;
if (id == 0) {
id = createUniqueId();
}
try {
reader = newSAMStreamSessionSocketReader(s, id);
sender = newStreamSender(s, id);
} catch (IOException e) {
_log.error("IOException when creating SAM STREAM session socket handler", e);
recv.stopStreamReceiving();
return 0;
}
synchronized (handlersMap) {
handlersMap.put(Integer.valueOf(id), reader);
sendersMap.put(Integer.valueOf(id), sender);
}
I2PAppThread t = new I2PAppThread(reader, "SAMReader" + id);
t.start();
t = new I2PAppThread(sender, "SAMSender" + id);
t.start();
return id;
}
use of net.i2p.util.I2PAppThread in project i2p.i2p by i2p.
the class SAMStreamSession method start.
/*
* @since 0.9.25
*/
public void start() {
if (server != null) {
Thread t = new I2PAppThread(server, "SAMStreamSessionServer");
t.start();
}
}
use of net.i2p.util.I2PAppThread in project i2p.i2p by i2p.
the class TCPtoI2P method run.
/**
* TCP stream to I2P stream thread starter
*/
public void run() {
String line, input;
InputStream Iin = null;
OutputStream Iout = null;
InputStream in = null;
OutputStream out = null;
Thread t = null;
Thread q = null;
try {
try {
in = sock.getInputStream();
out = sock.getOutputStream();
line = lnRead(in);
input = line.toLowerCase(Locale.US);
Destination dest = null;
if (input.endsWith(".i2p")) {
// dest = I2PTunnel.destFromName(input);
dest = I2PAppContext.getGlobalContext().namingService().lookup(input);
if (dest != null) {
line = dest.toBase64();
} else {
Emsg("Can't find destination: " + input, out);
return;
}
}
dest = new Destination();
dest.fromBase64(line);
try {
// get a client socket
I2P = socketManager.connect(dest);
// temp bugfix, this *SHOULD* be the default
I2P.setReadTimeout(0);
// make readers/writers
Iin = I2P.getInputStream();
Iout = I2P.getOutputStream();
// setup to cross the streams
// app -> I2P
TCPio conn_c = new TCPio(in, Iout, lives);
// I2P -> app
TCPio conn_a = new TCPio(Iin, out, lives);
t = new I2PAppThread(conn_c, Thread.currentThread().getName() + " TCPioA");
q = new I2PAppThread(conn_a, Thread.currentThread().getName() + " TCPioB");
// Fire!
t.start();
q.start();
while (t.isAlive() && q.isAlive() && lives.get()) {
// AND is used here to kill off the other thread
// sleep for 10 ms
Thread.sleep(10);
}
} catch (I2PException e) {
Emsg(e.toString(), out);
} catch (ConnectException e) {
Emsg(e.toString(), out);
} catch (NoRouteToHostException e) {
Emsg(e.toString(), out);
}
} catch (InterruptedIOException e) {
// We're breaking away.
} catch (InterruptedException e) {
// ditto
} catch (IOException e) {
try {
Emsg(e.toString(), out);
} catch (IOException ex) {
// ditto
}
} catch (DataFormatException e) {
try {
Emsg(e.toString(), out);
} catch (IOException ex) {
// ditto
}
}
} finally {
try {
t.interrupt();
} catch (Exception e) {
}
try {
q.interrupt();
} catch (Exception e) {
}
try {
in.close();
} catch (Exception e) {
}
try {
out.close();
} catch (Exception e) {
}
try {
Iin.close();
} catch (Exception e) {
}
try {
Iout.close();
} catch (Exception e) {
}
try {
// System.out.println("TCPtoI2P: Close I2P");
I2P.close();
} catch (Exception e) {
}
try {
// System.out.println("TCPtoI2P: Close sock");
sock.close();
} catch (Exception e) {
}
}
// System.out.println("TCPtoI2P: Done.");
}
use of net.i2p.util.I2PAppThread in project i2p.i2p by i2p.
the class I2Plistener method run.
/**
* Simply listen on I2P port, and thread connections
*/
public void run() {
boolean g = false;
I2PSocket sessSocket = null;
int conn = 0;
try {
try {
serverSocket.setSoTimeout(50);
while (lives.get()) {
try {
sessSocket = serverSocket.accept();
g = true;
} catch (ConnectException ce) {
g = false;
} catch (SocketTimeoutException ste) {
g = false;
}
if (g) {
g = false;
conn++;
// toss the connection to a new thread.
I2PtoTCP conn_c = new I2PtoTCP(sessSocket, info, database, lives);
Thread t = new I2PAppThread(conn_c, Thread.currentThread().getName() + " I2PtoTCP " + conn);
t.start();
}
}
} catch (I2PException e) {
// bad stuff
System.out.println("Exception " + e);
}
} finally {
try {
serverSocket.close();
} catch (I2PException ex) {
}
// System.out.println("I2Plistener: Close");
}
}
Aggregations