Rename version constant.

This commit is contained in:
akwizgran
2023-04-26 17:10:23 +01:00
parent 462f57c966
commit 4a4b04bec3
3 changed files with 15 additions and 14 deletions

View File

@@ -7,7 +7,7 @@ interface HandshakeConstants {
/** /**
* The current major version of the handshake protocol. * The current major version of the handshake protocol.
*/ */
byte PROTOCOL_VERSION = 0; byte PROTOCOL_MAJOR_VERSION = 0;
/** /**
* The current minor version of the handshake protocol. * The current minor version of the handshake protocol.

View File

@@ -36,8 +36,8 @@ import static java.util.Arrays.asList;
import static java.util.Collections.singletonList; import static java.util.Collections.singletonList;
import static org.briarproject.bramble.api.crypto.CryptoConstants.MAX_AGREEMENT_PUBLIC_KEY_BYTES; import static org.briarproject.bramble.api.crypto.CryptoConstants.MAX_AGREEMENT_PUBLIC_KEY_BYTES;
import static org.briarproject.bramble.contact.HandshakeConstants.PROOF_BYTES; import static org.briarproject.bramble.contact.HandshakeConstants.PROOF_BYTES;
import static org.briarproject.bramble.contact.HandshakeConstants.PROTOCOL_MAJOR_VERSION;
import static org.briarproject.bramble.contact.HandshakeConstants.PROTOCOL_MINOR_VERSION; import static org.briarproject.bramble.contact.HandshakeConstants.PROTOCOL_MINOR_VERSION;
import static org.briarproject.bramble.contact.HandshakeConstants.PROTOCOL_VERSION;
import static org.briarproject.bramble.contact.HandshakeRecordTypes.RECORD_TYPE_EPHEMERAL_PUBLIC_KEY; import static org.briarproject.bramble.contact.HandshakeRecordTypes.RECORD_TYPE_EPHEMERAL_PUBLIC_KEY;
import static org.briarproject.bramble.contact.HandshakeRecordTypes.RECORD_TYPE_MINOR_VERSION; import static org.briarproject.bramble.contact.HandshakeRecordTypes.RECORD_TYPE_MINOR_VERSION;
import static org.briarproject.bramble.contact.HandshakeRecordTypes.RECORD_TYPE_PROOF_OF_OWNERSHIP; import static org.briarproject.bramble.contact.HandshakeRecordTypes.RECORD_TYPE_PROOF_OF_OWNERSHIP;
@@ -49,7 +49,7 @@ class HandshakeManagerImpl implements HandshakeManager {
// Ignore records with current protocol version, unknown record type // Ignore records with current protocol version, unknown record type
private static final RecordPredicate IGNORE = r -> private static final RecordPredicate IGNORE = r ->
r.getProtocolVersion() == PROTOCOL_VERSION && r.getProtocolVersion() == PROTOCOL_MAJOR_VERSION &&
!isKnownRecordType(r.getRecordType()); !isKnownRecordType(r.getRecordType());
private static boolean isKnownRecordType(byte type) { private static boolean isKnownRecordType(byte type) {
@@ -146,7 +146,7 @@ class HandshakeManagerImpl implements HandshakeManager {
} }
private void sendPublicKey(RecordWriter w, PublicKey k) throws IOException { private void sendPublicKey(RecordWriter w, PublicKey k) throws IOException {
w.writeRecord(new Record(PROTOCOL_VERSION, w.writeRecord(new Record(PROTOCOL_MAJOR_VERSION,
RECORD_TYPE_EPHEMERAL_PUBLIC_KEY, k.getEncoded())); RECORD_TYPE_EPHEMERAL_PUBLIC_KEY, k.getEncoded()));
w.flush(); w.flush();
} }
@@ -205,7 +205,7 @@ class HandshakeManagerImpl implements HandshakeManager {
} }
private void sendProof(RecordWriter w, byte[] proof) throws IOException { private void sendProof(RecordWriter w, byte[] proof) throws IOException {
w.writeRecord(new Record(PROTOCOL_VERSION, w.writeRecord(new Record(PROTOCOL_MAJOR_VERSION,
RECORD_TYPE_PROOF_OF_OWNERSHIP, proof)); RECORD_TYPE_PROOF_OF_OWNERSHIP, proof));
w.flush(); w.flush();
} }
@@ -219,7 +219,8 @@ class HandshakeManagerImpl implements HandshakeManager {
} }
private void sendMinorVersion(RecordWriter w) throws IOException { private void sendMinorVersion(RecordWriter w) throws IOException {
w.writeRecord(new Record(PROTOCOL_VERSION, RECORD_TYPE_MINOR_VERSION, w.writeRecord(new Record(PROTOCOL_MAJOR_VERSION,
RECORD_TYPE_MINOR_VERSION,
new byte[] {PROTOCOL_MINOR_VERSION})); new byte[] {PROTOCOL_MINOR_VERSION}));
w.flush(); w.flush();
} }
@@ -228,7 +229,7 @@ class HandshakeManagerImpl implements HandshakeManager {
throws IOException { throws IOException {
// Accept records with current protocol version, expected types only // Accept records with current protocol version, expected types only
RecordPredicate accept = rec -> RecordPredicate accept = rec ->
rec.getProtocolVersion() == PROTOCOL_VERSION && rec.getProtocolVersion() == PROTOCOL_MAJOR_VERSION &&
expectedTypes.contains(rec.getRecordType()); expectedTypes.contains(rec.getRecordType());
Record rec = r.readRecord(accept, IGNORE); Record rec = r.readRecord(accept, IGNORE);
if (rec == null) throw new EOFException(); if (rec == null) throw new EOFException();

View File

@@ -32,8 +32,8 @@ import java.io.OutputStream;
import java.util.Arrays; import java.util.Arrays;
import static org.briarproject.bramble.contact.HandshakeConstants.PROOF_BYTES; import static org.briarproject.bramble.contact.HandshakeConstants.PROOF_BYTES;
import static org.briarproject.bramble.contact.HandshakeConstants.PROTOCOL_MAJOR_VERSION;
import static org.briarproject.bramble.contact.HandshakeConstants.PROTOCOL_MINOR_VERSION; import static org.briarproject.bramble.contact.HandshakeConstants.PROTOCOL_MINOR_VERSION;
import static org.briarproject.bramble.contact.HandshakeConstants.PROTOCOL_VERSION;
import static org.briarproject.bramble.contact.HandshakeRecordTypes.RECORD_TYPE_EPHEMERAL_PUBLIC_KEY; import static org.briarproject.bramble.contact.HandshakeRecordTypes.RECORD_TYPE_EPHEMERAL_PUBLIC_KEY;
import static org.briarproject.bramble.contact.HandshakeRecordTypes.RECORD_TYPE_MINOR_VERSION; import static org.briarproject.bramble.contact.HandshakeRecordTypes.RECORD_TYPE_MINOR_VERSION;
import static org.briarproject.bramble.contact.HandshakeRecordTypes.RECORD_TYPE_PROOF_OF_OWNERSHIP; import static org.briarproject.bramble.contact.HandshakeRecordTypes.RECORD_TYPE_PROOF_OF_OWNERSHIP;
@@ -209,25 +209,25 @@ public class HandshakeManagerImplTest extends BrambleMockTestCase {
} }
private void expectSendMinorVersion() throws Exception { private void expectSendMinorVersion() throws Exception {
expectWriteRecord(new Record(PROTOCOL_VERSION, expectWriteRecord(new Record(PROTOCOL_MAJOR_VERSION,
RECORD_TYPE_MINOR_VERSION, RECORD_TYPE_MINOR_VERSION,
new byte[] {PROTOCOL_MINOR_VERSION})); new byte[] {PROTOCOL_MINOR_VERSION}));
} }
private void expectReceiveMinorVersion() throws Exception { private void expectReceiveMinorVersion() throws Exception {
expectReadRecord(new Record(PROTOCOL_VERSION, expectReadRecord(new Record(PROTOCOL_MAJOR_VERSION,
RECORD_TYPE_MINOR_VERSION, RECORD_TYPE_MINOR_VERSION,
new byte[] {PROTOCOL_MINOR_VERSION})); new byte[] {PROTOCOL_MINOR_VERSION}));
} }
private void expectSendKey() throws Exception { private void expectSendKey() throws Exception {
expectWriteRecord(new Record(PROTOCOL_VERSION, expectWriteRecord(new Record(PROTOCOL_MAJOR_VERSION,
RECORD_TYPE_EPHEMERAL_PUBLIC_KEY, RECORD_TYPE_EPHEMERAL_PUBLIC_KEY,
ourEphemeralPublicKey.getEncoded())); ourEphemeralPublicKey.getEncoded()));
} }
private void expectReceiveKey() throws Exception { private void expectReceiveKey() throws Exception {
expectReadRecord(new Record(PROTOCOL_VERSION, expectReadRecord(new Record(PROTOCOL_MAJOR_VERSION,
RECORD_TYPE_EPHEMERAL_PUBLIC_KEY, RECORD_TYPE_EPHEMERAL_PUBLIC_KEY,
theirEphemeralPublicKey.getEncoded())); theirEphemeralPublicKey.getEncoded()));
} }
@@ -258,12 +258,12 @@ public class HandshakeManagerImplTest extends BrambleMockTestCase {
} }
private void expectSendProof() throws Exception { private void expectSendProof() throws Exception {
expectWriteRecord(new Record(PROTOCOL_VERSION, expectWriteRecord(new Record(PROTOCOL_MAJOR_VERSION,
RECORD_TYPE_PROOF_OF_OWNERSHIP, ourProof)); RECORD_TYPE_PROOF_OF_OWNERSHIP, ourProof));
} }
private void expectReceiveProof() throws Exception { private void expectReceiveProof() throws Exception {
expectReadRecord(new Record(PROTOCOL_VERSION, expectReadRecord(new Record(PROTOCOL_MAJOR_VERSION,
RECORD_TYPE_PROOF_OF_OWNERSHIP, theirProof)); RECORD_TYPE_PROOF_OF_OWNERSHIP, theirProof));
} }