From 4a4b04bec36196199d1c28cd9e838bb3370b9119 Mon Sep 17 00:00:00 2001 From: akwizgran Date: Wed, 26 Apr 2023 17:10:23 +0100 Subject: [PATCH] Rename version constant. --- .../bramble/contact/HandshakeConstants.java | 2 +- .../bramble/contact/HandshakeManagerImpl.java | 13 +++++++------ .../bramble/contact/HandshakeManagerImplTest.java | 14 +++++++------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/bramble-core/src/main/java/org/briarproject/bramble/contact/HandshakeConstants.java b/bramble-core/src/main/java/org/briarproject/bramble/contact/HandshakeConstants.java index 41f665897..45470f5b8 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/contact/HandshakeConstants.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/contact/HandshakeConstants.java @@ -7,7 +7,7 @@ interface HandshakeConstants { /** * 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. diff --git a/bramble-core/src/main/java/org/briarproject/bramble/contact/HandshakeManagerImpl.java b/bramble-core/src/main/java/org/briarproject/bramble/contact/HandshakeManagerImpl.java index 2fd434c5c..496fdc482 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/contact/HandshakeManagerImpl.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/contact/HandshakeManagerImpl.java @@ -36,8 +36,8 @@ import static java.util.Arrays.asList; import static java.util.Collections.singletonList; 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.PROTOCOL_MAJOR_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_MINOR_VERSION; 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 private static final RecordPredicate IGNORE = r -> - r.getProtocolVersion() == PROTOCOL_VERSION && + r.getProtocolVersion() == PROTOCOL_MAJOR_VERSION && !isKnownRecordType(r.getRecordType()); private static boolean isKnownRecordType(byte type) { @@ -146,7 +146,7 @@ class HandshakeManagerImpl implements HandshakeManager { } 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())); w.flush(); } @@ -205,7 +205,7 @@ class HandshakeManagerImpl implements HandshakeManager { } 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)); w.flush(); } @@ -219,7 +219,8 @@ class HandshakeManagerImpl implements HandshakeManager { } 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})); w.flush(); } @@ -228,7 +229,7 @@ class HandshakeManagerImpl implements HandshakeManager { throws IOException { // Accept records with current protocol version, expected types only RecordPredicate accept = rec -> - rec.getProtocolVersion() == PROTOCOL_VERSION && + rec.getProtocolVersion() == PROTOCOL_MAJOR_VERSION && expectedTypes.contains(rec.getRecordType()); Record rec = r.readRecord(accept, IGNORE); if (rec == null) throw new EOFException(); diff --git a/bramble-core/src/test/java/org/briarproject/bramble/contact/HandshakeManagerImplTest.java b/bramble-core/src/test/java/org/briarproject/bramble/contact/HandshakeManagerImplTest.java index 7349f1be5..9597d486b 100644 --- a/bramble-core/src/test/java/org/briarproject/bramble/contact/HandshakeManagerImplTest.java +++ b/bramble-core/src/test/java/org/briarproject/bramble/contact/HandshakeManagerImplTest.java @@ -32,8 +32,8 @@ import java.io.OutputStream; import java.util.Arrays; 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_VERSION; 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_PROOF_OF_OWNERSHIP; @@ -209,25 +209,25 @@ public class HandshakeManagerImplTest extends BrambleMockTestCase { } private void expectSendMinorVersion() throws Exception { - expectWriteRecord(new Record(PROTOCOL_VERSION, + expectWriteRecord(new Record(PROTOCOL_MAJOR_VERSION, RECORD_TYPE_MINOR_VERSION, new byte[] {PROTOCOL_MINOR_VERSION})); } private void expectReceiveMinorVersion() throws Exception { - expectReadRecord(new Record(PROTOCOL_VERSION, + expectReadRecord(new Record(PROTOCOL_MAJOR_VERSION, RECORD_TYPE_MINOR_VERSION, new byte[] {PROTOCOL_MINOR_VERSION})); } private void expectSendKey() throws Exception { - expectWriteRecord(new Record(PROTOCOL_VERSION, + expectWriteRecord(new Record(PROTOCOL_MAJOR_VERSION, RECORD_TYPE_EPHEMERAL_PUBLIC_KEY, ourEphemeralPublicKey.getEncoded())); } private void expectReceiveKey() throws Exception { - expectReadRecord(new Record(PROTOCOL_VERSION, + expectReadRecord(new Record(PROTOCOL_MAJOR_VERSION, RECORD_TYPE_EPHEMERAL_PUBLIC_KEY, theirEphemeralPublicKey.getEncoded())); } @@ -258,12 +258,12 @@ public class HandshakeManagerImplTest extends BrambleMockTestCase { } private void expectSendProof() throws Exception { - expectWriteRecord(new Record(PROTOCOL_VERSION, + expectWriteRecord(new Record(PROTOCOL_MAJOR_VERSION, RECORD_TYPE_PROOF_OF_OWNERSHIP, ourProof)); } private void expectReceiveProof() throws Exception { - expectReadRecord(new Record(PROTOCOL_VERSION, + expectReadRecord(new Record(PROTOCOL_MAJOR_VERSION, RECORD_TYPE_PROOF_OF_OWNERSHIP, theirProof)); }