propagate from branch 'i2p.i2p.sam3' (head fa9e8f7d5cacabb84eaae8cc6b569b334f2e0238)
to branch 'i2p.i2p' (head 9cdab8e186f77c375fd81913d3b3c20e5ca69ca2)
This commit is contained in:
@ -297,6 +297,8 @@ address (leaving up to 1KB for header material). This FROM address
|
|||||||
is authenticated internally by SAM (making use of the destination's
|
is authenticated internally by SAM (making use of the destination's
|
||||||
signing key to verify the source) and includes replay prevention.
|
signing key to verify the source) and includes replay prevention.
|
||||||
|
|
||||||
|
** First method :
|
||||||
|
|
||||||
After establishing a SAM session with STYLE=DATAGRAM, the client can
|
After establishing a SAM session with STYLE=DATAGRAM, the client can
|
||||||
send datagrams through SAM's UDP port (7655).
|
send datagrams through SAM's UDP port (7655).
|
||||||
|
|
||||||
@ -314,6 +316,12 @@ following format :
|
|||||||
The first line will be discarded by SAM before sending the remaining
|
The first line will be discarded by SAM before sending the remaining
|
||||||
of the message to the specified destination.
|
of the message to the specified destination.
|
||||||
|
|
||||||
|
** Second method :
|
||||||
|
|
||||||
|
Datagrams can also be sent through the socket from which the datagram
|
||||||
|
session was opened. See the "DATAGRAM SEND" command of SAM versions 1
|
||||||
|
and 2.
|
||||||
|
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
SAM repliable datagrams : receiving a datagram
|
SAM repliable datagrams : receiving a datagram
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
|
@ -178,8 +178,8 @@ public class SAMv1Handler extends SAMHandler implements SAMRawReceiver, SAMDatag
|
|||||||
if (getDatagramSession() != null) {
|
if (getDatagramSession() != null) {
|
||||||
getDatagramSession().close();
|
getDatagramSession().close();
|
||||||
}
|
}
|
||||||
if (streamSession != null) {
|
if (getStreamSession() != null) {
|
||||||
streamSession.close();
|
getStreamSession().close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -192,7 +192,7 @@ public class SAMv1Handler extends SAMHandler implements SAMRawReceiver, SAMDatag
|
|||||||
try{
|
try{
|
||||||
if (opcode.equals("CREATE")) {
|
if (opcode.equals("CREATE")) {
|
||||||
if ((getRawSession() != null) || (getDatagramSession() != null)
|
if ((getRawSession() != null) || (getDatagramSession() != null)
|
||||||
|| (streamSession != null)) {
|
|| (getStreamSession() != null)) {
|
||||||
_log.debug("Trying to create a session, but one still exists");
|
_log.debug("Trying to create a session, but one still exists");
|
||||||
return writeString("SESSION STATUS RESULT=I2P_ERROR MESSAGE=\"Session already exists\"\n");
|
return writeString("SESSION STATUS RESULT=I2P_ERROR MESSAGE=\"Session already exists\"\n");
|
||||||
}
|
}
|
||||||
@ -408,7 +408,7 @@ public class SAMv1Handler extends SAMHandler implements SAMRawReceiver, SAMDatag
|
|||||||
|
|
||||||
in.readFully(data);
|
in.readFully(data);
|
||||||
|
|
||||||
if (!datagramSession.sendBytes(dest, data)) {
|
if (!getDatagramSession().sendBytes(dest, data)) {
|
||||||
_log.error("DATAGRAM SEND failed");
|
_log.error("DATAGRAM SEND failed");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -507,7 +507,7 @@ public class SAMv1Handler extends SAMHandler implements SAMRawReceiver, SAMDatag
|
|||||||
|
|
||||||
/* Parse and execute a STREAM message */
|
/* Parse and execute a STREAM message */
|
||||||
protected boolean execStreamMessage(String opcode, Properties props) {
|
protected boolean execStreamMessage(String opcode, Properties props) {
|
||||||
if (streamSession == null) {
|
if (getStreamSession() == null) {
|
||||||
_log.error("STREAM message received, but no STREAM session exists");
|
_log.error("STREAM message received, but no STREAM session exists");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -567,11 +567,11 @@ public class SAMv1Handler extends SAMHandler implements SAMRawReceiver, SAMDatag
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!streamSession.sendBytes(id, getClientSocket().socket().getInputStream(), size)) { // data)) {
|
if (!getStreamSession().sendBytes(id, getClientSocket().socket().getInputStream(), size)) { // data)) {
|
||||||
if (_log.shouldLog(Log.WARN))
|
if (_log.shouldLog(Log.WARN))
|
||||||
_log.warn("STREAM SEND [" + size + "] failed");
|
_log.warn("STREAM SEND [" + size + "] failed");
|
||||||
boolean rv = writeString("STREAM CLOSED RESULT=CANT_REACH_PEER ID=" + id + " MESSAGE=\"Send of " + size + " bytes failed\"\n");
|
boolean rv = writeString("STREAM CLOSED RESULT=CANT_REACH_PEER ID=" + id + " MESSAGE=\"Send of " + size + " bytes failed\"\n");
|
||||||
streamSession.closeConnection(id);
|
getStreamSession().closeConnection(id);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -622,7 +622,7 @@ public class SAMv1Handler extends SAMHandler implements SAMRawReceiver, SAMDatag
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
if (!streamSession.connect(id, dest, props)) {
|
if (!getStreamSession().connect(id, dest, props)) {
|
||||||
_log.debug("STREAM connection failed");
|
_log.debug("STREAM connection failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -673,7 +673,7 @@ public class SAMv1Handler extends SAMHandler implements SAMRawReceiver, SAMDatag
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean closed = streamSession.closeConnection(id);
|
boolean closed = getStreamSession().closeConnection(id);
|
||||||
if ( (!closed) && (_log.shouldLog(Log.WARN)) )
|
if ( (!closed) && (_log.shouldLog(Log.WARN)) )
|
||||||
_log.warn("Stream unable to be closed, but this is non fatal");
|
_log.warn("Stream unable to be closed, but this is non fatal");
|
||||||
return true;
|
return true;
|
||||||
@ -765,7 +765,7 @@ public class SAMv1Handler extends SAMHandler implements SAMRawReceiver, SAMDatag
|
|||||||
|
|
||||||
public void streamSendAnswer( int id, String result, String bufferState ) throws IOException
|
public void streamSendAnswer( int id, String result, String bufferState ) throws IOException
|
||||||
{
|
{
|
||||||
if ( streamSession == null )
|
if ( getStreamSession() == null )
|
||||||
{
|
{
|
||||||
_log.error ( "BUG! Want to answer to stream SEND, but session is null!" );
|
_log.error ( "BUG! Want to answer to stream SEND, but session is null!" );
|
||||||
throw new NullPointerException ( "BUG! STREAM session is null!" );
|
throw new NullPointerException ( "BUG! STREAM session is null!" );
|
||||||
@ -783,7 +783,7 @@ public class SAMv1Handler extends SAMHandler implements SAMRawReceiver, SAMDatag
|
|||||||
|
|
||||||
public void notifyStreamSendBufferFree( int id ) throws IOException
|
public void notifyStreamSendBufferFree( int id ) throws IOException
|
||||||
{
|
{
|
||||||
if ( streamSession == null )
|
if ( getStreamSession() == null )
|
||||||
{
|
{
|
||||||
_log.error ( "BUG! Stream outgoing buffer is free, but session is null!" );
|
_log.error ( "BUG! Stream outgoing buffer is free, but session is null!" );
|
||||||
throw new NullPointerException ( "BUG! STREAM session is null!" );
|
throw new NullPointerException ( "BUG! STREAM session is null!" );
|
||||||
@ -797,7 +797,7 @@ public class SAMv1Handler extends SAMHandler implements SAMRawReceiver, SAMDatag
|
|||||||
|
|
||||||
|
|
||||||
public void notifyStreamIncomingConnection(int id, Destination d) throws IOException {
|
public void notifyStreamIncomingConnection(int id, Destination d) throws IOException {
|
||||||
if (streamSession == null) {
|
if (getStreamSession() == null) {
|
||||||
_log.error("BUG! Received stream connection, but session is null!");
|
_log.error("BUG! Received stream connection, but session is null!");
|
||||||
throw new NullPointerException("BUG! STREAM session is null!");
|
throw new NullPointerException("BUG! STREAM session is null!");
|
||||||
}
|
}
|
||||||
@ -811,7 +811,7 @@ public class SAMv1Handler extends SAMHandler implements SAMRawReceiver, SAMDatag
|
|||||||
|
|
||||||
public void notifyStreamOutgoingConnection ( int id, String result, String msg ) throws IOException
|
public void notifyStreamOutgoingConnection ( int id, String result, String msg ) throws IOException
|
||||||
{
|
{
|
||||||
if ( streamSession == null )
|
if ( getStreamSession() == null )
|
||||||
{
|
{
|
||||||
_log.error ( "BUG! Received stream connection, but session is null!" );
|
_log.error ( "BUG! Received stream connection, but session is null!" );
|
||||||
throw new NullPointerException ( "BUG! STREAM session is null!" );
|
throw new NullPointerException ( "BUG! STREAM session is null!" );
|
||||||
@ -832,7 +832,7 @@ public class SAMv1Handler extends SAMHandler implements SAMRawReceiver, SAMDatag
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void receiveStreamBytes(int id, ByteBuffer data) throws IOException {
|
public void receiveStreamBytes(int id, ByteBuffer data) throws IOException {
|
||||||
if (streamSession == null) {
|
if (getStreamSession() == null) {
|
||||||
_log.error("Received stream bytes, but session is null!");
|
_log.error("Received stream bytes, but session is null!");
|
||||||
throw new NullPointerException("BUG! STREAM session is null!");
|
throw new NullPointerException("BUG! STREAM session is null!");
|
||||||
}
|
}
|
||||||
@ -852,7 +852,7 @@ public class SAMv1Handler extends SAMHandler implements SAMRawReceiver, SAMDatag
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void notifyStreamDisconnection(int id, String result, String msg) throws IOException {
|
public void notifyStreamDisconnection(int id, String result, String msg) throws IOException {
|
||||||
if (streamSession == null) {
|
if (getStreamSession() == null) {
|
||||||
_log.error("BUG! Received stream disconnection, but session is null!");
|
_log.error("BUG! Received stream disconnection, but session is null!");
|
||||||
throw new NullPointerException("BUG! STREAM session is null!");
|
throw new NullPointerException("BUG! STREAM session is null!");
|
||||||
}
|
}
|
||||||
@ -868,7 +868,7 @@ public class SAMv1Handler extends SAMHandler implements SAMRawReceiver, SAMDatag
|
|||||||
public void stopStreamReceiving() {
|
public void stopStreamReceiving() {
|
||||||
_log.debug("stopStreamReceiving() invoked", new Exception("stopped"));
|
_log.debug("stopStreamReceiving() invoked", new Exception("stopped"));
|
||||||
|
|
||||||
if (streamSession == null) {
|
if (getStreamSession() == null) {
|
||||||
_log.error("BUG! Got stream receiving stop, but session is null!");
|
_log.error("BUG! Got stream receiving stop, but session is null!");
|
||||||
throw new NullPointerException("BUG! STREAM session is null!");
|
throw new NullPointerException("BUG! STREAM session is null!");
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ public class SAMv2Handler extends SAMv1Handler implements SAMRawReceiver, SAMDat
|
|||||||
/* Parse and execute a STREAM message */
|
/* Parse and execute a STREAM message */
|
||||||
protected boolean execStreamMessage ( String opcode, Properties props )
|
protected boolean execStreamMessage ( String opcode, Properties props )
|
||||||
{
|
{
|
||||||
if ( streamSession == null )
|
if ( getStreamSession() == null )
|
||||||
{
|
{
|
||||||
_log.error ( "STREAM message received, but no STREAM session exists" );
|
_log.error ( "STREAM message received, but no STREAM session exists" );
|
||||||
return false;
|
return false;
|
||||||
@ -173,7 +173,7 @@ public class SAMv2Handler extends SAMv1Handler implements SAMRawReceiver, SAMDat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
streamSession.setReceiveLimit ( id, limit, nolimit ) ;
|
getStreamSession().setReceiveLimit ( id, limit, nolimit ) ;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -390,6 +390,8 @@ public class SAMv3Handler extends SAMv1Handler
|
|||||||
canContinue = execDestMessage(opcode, props);
|
canContinue = execDestMessage(opcode, props);
|
||||||
} else if (domain.equals("NAMING")) {
|
} else if (domain.equals("NAMING")) {
|
||||||
canContinue = execNamingMessage(opcode, props);
|
canContinue = execNamingMessage(opcode, props);
|
||||||
|
} else if (domain.equals("DATAGRAM")) {
|
||||||
|
canContinue = execDatagramMessage(opcode, props);
|
||||||
} else {
|
} else {
|
||||||
_log.debug("Unrecognized message domain: \""
|
_log.debug("Unrecognized message domain: \""
|
||||||
+ domain + "\"");
|
+ domain + "\"");
|
||||||
@ -418,7 +420,7 @@ public class SAMv3Handler extends SAMv1Handler
|
|||||||
}
|
}
|
||||||
if (streamForwardingSocket)
|
if (streamForwardingSocket)
|
||||||
{
|
{
|
||||||
if (this.streamSession!=null) {
|
if (this.getStreamSession()!=null) {
|
||||||
try {
|
try {
|
||||||
this.streamSession.stopForwardingIncoming();
|
this.streamSession.stopForwardingIncoming();
|
||||||
} catch (SAMException e) {
|
} catch (SAMException e) {
|
||||||
@ -464,7 +466,7 @@ public class SAMv3Handler extends SAMv1Handler
|
|||||||
try{
|
try{
|
||||||
if (opcode.equals("CREATE")) {
|
if (opcode.equals("CREATE")) {
|
||||||
if ((this.getRawSession()!= null) || (this.getDatagramSession() != null)
|
if ((this.getRawSession()!= null) || (this.getDatagramSession() != null)
|
||||||
|| (streamSession != null)) {
|
|| (this.getStreamSession() != null)) {
|
||||||
_log.debug("Trying to create a session, but one still exists");
|
_log.debug("Trying to create a session, but one still exists");
|
||||||
return writeString("SESSION STATUS RESULT=I2P_ERROR MESSAGE=\"Session already exists\"\n");
|
return writeString("SESSION STATUS RESULT=I2P_ERROR MESSAGE=\"Session already exists\"\n");
|
||||||
}
|
}
|
||||||
@ -761,7 +763,7 @@ public class SAMv3Handler extends SAMv1Handler
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void notifyStreamIncomingConnection(Destination d) throws IOException {
|
public void notifyStreamIncomingConnection(Destination d) throws IOException {
|
||||||
if (streamSession == null) {
|
if (getStreamSession() == null) {
|
||||||
_log.error("BUG! Received stream connection, but session is null!");
|
_log.error("BUG! Received stream connection, but session is null!");
|
||||||
throw new NullPointerException("BUG! STREAM session is null!");
|
throw new NullPointerException("BUG! STREAM session is null!");
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user