diff --git a/pom.xml b/pom.xml index a9a86cbb..f0da9ba2 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ org.red5 red5-parent - 1.0.7-SNAPSHOT + 1.0.7-M6 4.0.0 red5-server-common diff --git a/src/main/java/org/red5/server/net/rtmp/RTMPConnection.java b/src/main/java/org/red5/server/net/rtmp/RTMPConnection.java index 252b4b90..325de078 100755 --- a/src/main/java/org/red5/server/net/rtmp/RTMPConnection.java +++ b/src/main/java/org/red5/server/net/rtmp/RTMPConnection.java @@ -287,7 +287,7 @@ public abstract class RTMPConnection extends BaseConnection implements IStreamCa /** * Maximum time in milliseconds to wait for a valid handshake. */ - private int maxHandshakeTimeout = 5000; + private int maxHandshakeTimeout = 10000; /** * Maximum time in milliseconds allowed to process received message diff --git a/src/main/java/org/red5/server/net/rtmp/RTMPHandshake.java b/src/main/java/org/red5/server/net/rtmp/RTMPHandshake.java index 99d72174..c8b3babe 100644 --- a/src/main/java/org/red5/server/net/rtmp/RTMPHandshake.java +++ b/src/main/java/org/red5/server/net/rtmp/RTMPHandshake.java @@ -39,6 +39,7 @@ import javax.crypto.spec.SecretKeySpec; import org.apache.commons.codec.binary.Hex; +import org.apache.mina.core.buffer.IoBuffer; import org.bouncycastle.crypto.engines.BlowfishEngine; import org.bouncycastle.crypto.params.KeyParameter; import org.bouncycastle.jce.provider.BouncyCastleProvider; @@ -179,6 +180,9 @@ public abstract class RTMPHandshake implements IHandshake { // start as an fp of at least version 9.0.115.0 protected boolean fp9Handshake = true; + // buffer for incoming data + protected IoBuffer buffer; + static { //get security provider Security.addProvider(new BouncyCastleProvider()); @@ -196,6 +200,9 @@ public RTMPHandshake(byte handshakeType) { log.trace("Use fp9 handshake? {}", fp9Handshake); // create our handshake bytes createHandshakeBytes(); + // instance a buffer to handle fragmenting + buffer = IoBuffer.allocate(Constants.HANDSHAKE_SIZE); + buffer.setAutoExpand(true); } /** @@ -662,4 +669,55 @@ public byte[] getSwfVerificationBytes() { return swfVerificationBytes; } + /** + * Returns the buffer size. + * + * @return buffer remaining + */ + public int getBufferSize() { + return buffer.limit() - buffer.remaining(); + } + + /** + * Add a byte array to the buffer. + * + * @param in incoming bytes + */ + public void addBuffer(byte[] in) { + buffer.put(in); + } + + /** + * Add a IoBuffer to the buffer. + * + * @param in incoming IoBuffer + */ + public void addBuffer(IoBuffer in) { + byte[] tmp = new byte[in.remaining()]; + in.get(tmp); + buffer.put(tmp); + } + + /** + * Returns buffered IoBuffer itself. + * + * @return IoBuffer + */ + public IoBuffer getBufferAsIoBuffer() { + return buffer.flip(); + } + + /** + * Returns buffered byte array. + * + * @return bytes + */ + public byte[] getBuffer() { + buffer.flip(); + byte[] tmp = new byte[buffer.remaining()]; + buffer.get(tmp); + buffer.clear(); + return tmp; + } + }