Skip to content

Commit

Permalink
Adds a watermark to SCTP cookie
Browse files Browse the repository at this point in the history
reverts the order, ensuring that the AssociationListener's callbacks are called in a consistent order for the first inbound stream.
  • Loading branch information
steely-glint committed Mar 1, 2022
1 parent e7ae727 commit d29f9c2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
7 changes: 6 additions & 1 deletion src/main/java/pe/pi/sctp4j/sctp/Association.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public enum State {
AUTH // Assume DTLS will cover this for us if we never send ASCONF packets.
*/

public static int COOKIESIZE = 32;
public static int COOKIESIZE = 40;
private static long VALIDCOOKIELIFE = 60000;
/*
RTO.Initial - 3 seconds
Expand Down Expand Up @@ -633,6 +633,11 @@ protected Chunk[] inboundInit(InitChunk init) {
cookie.cookieData = new byte[Association.COOKIESIZE];
cookie.cookieTime = System.currentTimeMillis();
_random.nextBytes(cookie.cookieData);
byte[] watermark = " |pi.pe|".getBytes();
int wlen = Math.min(watermark.length, cookie.cookieData.length);
for (int w=0;w<wlen;w++){
cookie.cookieData[w] = watermark[w]; // tell google who we are.
}
iac.setCookie(cookie.cookieData);
_cookies.add(cookie);

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/pe/pi/sctp4j/sctp/SCTPStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,15 @@ int stashCap() {

public void setSCTPStreamListener(SCTPStreamListener sl) {
_sl = sl;
Log.debug("adding listener for "+this._label+" of "+sl.getClass().getName());
if (_earlyQueue != null) {
Log.debug("delivering early " + _earlyQueue.size() + " messages to "+sl.getClass().getSimpleName());
SCTPMessage e = null;
while (null != (e = _earlyQueue.poll())) {
e.deliver(_sl);
}
} else {
Log.debug("no early queue for "+_label);
}
}

Expand Down
3 changes: 0 additions & 3 deletions src/main/java/pe/pi/sctp4j/sctp/small/BlockingSCTPStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
import pe.pi.sctp4j.sctp.dataChannel.DECP.DCOpen;
import com.phono.srtplight.Log;
import java.util.concurrent.ExecutorService;
import java.util.logging.Level;
import java.util.logging.Logger;
import pe.pi.sctp4j.sctp.SCTPStreamListener;

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -896,8 +896,13 @@ public void onDisAssociated(Association a) {

@Override
public void onDCEPStream(SCTPStream s, String label, int type) throws Exception {
// we do this on the SCTPStream's thread.
_appAl.onDCEPStream(s, label, type);
if (_appAl != null) {_ex.execute(() -> {
try {
_appAl.onDCEPStream(s,label,type);
} catch (Exception ex) {
Log.warn("onDCEPStream threw exception "+ex.getMessage());
}
});}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public void onRawStream(SCTPStream s) {
@Test
public void testMakeMessage_String_BlockingSCTPStream() throws Exception {
System.out.println("---->makeMessage string");
//Log.setLevel(Log.VERB);
//Log.setLevel(Log.DEBUG);
final StringBuffer rightout = new StringBuffer();
final SCTPStreamListener rsl = new ASCTPStreamListener() {
@Override
Expand Down

0 comments on commit d29f9c2

Please sign in to comment.