forked from I2P_Developers/i2p.i2p
make method private
fix timeout message add client sink pinger
This commit is contained in:
@@ -102,7 +102,10 @@ abstract class SAMHandler implements Runnable, Handler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static public void writeBytes(ByteBuffer data, SocketChannel out) throws IOException {
|
/**
|
||||||
|
* Caller must synch
|
||||||
|
*/
|
||||||
|
private static void writeBytes(ByteBuffer data, SocketChannel out) throws IOException {
|
||||||
while (data.hasRemaining()) out.write(data);
|
while (data.hasRemaining()) out.write(data);
|
||||||
out.socket().getOutputStream().flush();
|
out.socket().getOutputStream().flush();
|
||||||
}
|
}
|
||||||
@@ -132,7 +135,10 @@ abstract class SAMHandler implements Runnable, Handler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return success */
|
/**
|
||||||
|
* Unsynchronized, use with caution
|
||||||
|
* @return success
|
||||||
|
*/
|
||||||
public static boolean writeString(String str, SocketChannel out)
|
public static boolean writeString(String str, SocketChannel out)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
@@ -315,7 +315,7 @@ class SAMv3Handler extends SAMv1Handler
|
|||||||
} else if (_lastPing < 0) {
|
} else if (_lastPing < 0) {
|
||||||
if (_log.shouldWarn())
|
if (_log.shouldWarn())
|
||||||
_log.warn("2nd timeout");
|
_log.warn("2nd timeout");
|
||||||
writeString("XXX STATUS RESULT=I2P_ERROR MESSAGE=\"command timeout, bye\"\n");
|
writeString("SESSION STATUS RESULT=I2P_ERROR MESSAGE=\"command timeout, bye\"\n");
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
// don't clear buffer, don't send ping,
|
// don't clear buffer, don't send ping,
|
||||||
|
@@ -15,6 +15,7 @@ import gnu.getopt.Getopt;
|
|||||||
import net.i2p.I2PAppContext;
|
import net.i2p.I2PAppContext;
|
||||||
import net.i2p.data.Base32;
|
import net.i2p.data.Base32;
|
||||||
import net.i2p.data.DataHelper;
|
import net.i2p.data.DataHelper;
|
||||||
|
import net.i2p.util.I2PAppThread;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
import net.i2p.util.VersionComparator;
|
import net.i2p.util.VersionComparator;
|
||||||
|
|
||||||
@@ -35,6 +36,7 @@ public class SAMStreamSink {
|
|||||||
private String _conOptions;
|
private String _conOptions;
|
||||||
private SAMReader _reader, _reader2;
|
private SAMReader _reader, _reader2;
|
||||||
private boolean _isV3;
|
private boolean _isV3;
|
||||||
|
private boolean _isV32;
|
||||||
private String _v3ID;
|
private String _v3ID;
|
||||||
//private boolean _dead;
|
//private boolean _dead;
|
||||||
/** Connection id (Integer) to peer (Flooder) */
|
/** Connection id (Integer) to peer (Flooder) */
|
||||||
@@ -127,6 +129,11 @@ public class SAMStreamSink {
|
|||||||
throw new IOException("handshake failed");
|
throw new IOException("handshake failed");
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Handshake complete. we are " + ourDest);
|
_log.debug("Handshake complete. we are " + ourDest);
|
||||||
|
if (_isV32) {
|
||||||
|
_log.debug("Starting pinger");
|
||||||
|
Thread t = new Pinger(out);
|
||||||
|
t.start();
|
||||||
|
}
|
||||||
if (_isV3 && mode != V1DG && mode != V1RAW) {
|
if (_isV3 && mode != V1DG && mode != V1RAW) {
|
||||||
Socket sock2 = connect(isSSL);
|
Socket sock2 = connect(isSSL);
|
||||||
out = sock2.getOutputStream();
|
out = sock2.getOutputStream();
|
||||||
@@ -146,6 +153,32 @@ public class SAMStreamSink {
|
|||||||
_log.error("Unable to connect to SAM at " + _samHost + ":" + _samPort, e);
|
_log.error("Unable to connect to SAM at " + _samHost + ":" + _samPort, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class Pinger extends I2PAppThread {
|
||||||
|
private final OutputStream _out;
|
||||||
|
|
||||||
|
public Pinger(OutputStream out) {
|
||||||
|
super("SAM Sink Pinger");
|
||||||
|
setDaemon(true);
|
||||||
|
_out = out;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(127*1000);
|
||||||
|
synchronized(_out) {
|
||||||
|
_out.write(DataHelper.getASCII("PING " + System.currentTimeMillis() + '\n'));
|
||||||
|
_out.flush();
|
||||||
|
}
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
break;
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class SinkEventHandler extends SAMEventHandler {
|
private class SinkEventHandler extends SAMEventHandler {
|
||||||
|
|
||||||
@@ -353,6 +386,7 @@ public class SAMStreamSink {
|
|||||||
_isV3 = VersionComparator.comp(hisVersion, "3") >= 0;
|
_isV3 = VersionComparator.comp(hisVersion, "3") >= 0;
|
||||||
String dest;
|
String dest;
|
||||||
if (_isV3) {
|
if (_isV3) {
|
||||||
|
_isV32 = VersionComparator.comp(hisVersion, "3.2") >= 0;
|
||||||
// we use the filename as the name in sam.keys
|
// we use the filename as the name in sam.keys
|
||||||
// and read it in ourselves
|
// and read it in ourselves
|
||||||
File keys = new File("sam.keys");
|
File keys = new File("sam.keys");
|
||||||
|
Reference in New Issue
Block a user