Skip to content

Commit

Permalink
Fixed fragmented handshake. Set version to M6
Browse files Browse the repository at this point in the history
  • Loading branch information
mondain committed Mar 4, 2016
1 parent 84b4a80 commit 8f42b5e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.red5</groupId>
<artifactId>red5-parent</artifactId>
<version>1.0.7-SNAPSHOT</version>
<version>1.0.7-M6</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>red5-server-common</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/red5/server/net/rtmp/RTMPConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
58 changes: 58 additions & 0 deletions src/main/java/org/red5/server/net/rtmp/RTMPHandshake.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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;
}

}

0 comments on commit 8f42b5e

Please sign in to comment.