Skip to content

Commit 5e38458

Browse files
authored
Fixed using the wrong protocol version (#28)
fixed using the wrong protocol version
1 parent 71444e6 commit 5e38458

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

api/src/main/java/club/minnced/discord/jdave/DaveSessionImpl.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,14 @@ public static DaveSessionImpl create(@Nullable String authSessionId) {
2424
MemorySegment authSessionIdSegment =
2525
authSessionId != null ? local.allocateFrom(authSessionId) : MemorySegment.NULL;
2626
MemorySegment session = LibDaveSessionBinding.createSession(MemorySegment.NULL, authSessionIdSegment);
27-
return new DaveSessionImpl(session);
27+
28+
DaveSessionImpl result = new DaveSessionImpl(session);
29+
// this part of memory is not initialized by libdave
30+
// until we call #initialize or #reset meaning it just
31+
// has a random value of whatever was there before making
32+
// it very confusing to debug
33+
result.setProtocolVersion((short) -1);
34+
return result;
2835
}
2936
}
3037

api/src/main/java/club/minnced/discord/jdave/manager/DaveSessionManager.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public synchronized void onMLSPrepareCommitTransition(int transitionId, @NonNull
229229
prepareProtocolTransition(transitionId, session.getProtocolVersion());
230230
} else {
231231
sendInvalidCommitWelcome(transitionId);
232-
handleDaveProtocolInit(transitionId);
232+
handleDaveProtocolInit(session.getProtocolVersion());
233233
}
234234
}
235235
}
@@ -247,7 +247,7 @@ public synchronized void onMLSWelcome(int transitionId, @NonNull ByteBuffer welc
247247
prepareProtocolTransition(transitionId, session.getProtocolVersion());
248248
} else {
249249
sendInvalidCommitWelcome(transitionId);
250-
handleDaveProtocolInit(transitionId);
250+
handleDaveProtocolInit(session.getProtocolVersion());
251251
}
252252
}
253253

@@ -292,9 +292,10 @@ private void prepareProtocolTransition(int transitionId, int protocolVersion) {
292292
encryptor.processTransition(protocolVersion);
293293
} else {
294294
preparedTransitions.put(transitionId, protocolVersion);
295-
currentProtocolVersion = protocolVersion;
296295
callbacks.sendDaveProtocolReadyForTransition(transitionId);
297296
}
297+
298+
currentProtocolVersion = protocolVersion;
298299
}
299300

300301
private void executeProtocolTransition(int transitionId) {

0 commit comments

Comments
 (0)