diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-04-14 15:57:32 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-04-14 15:57:32 +0700 |
commit | f34a9e00ed839663297c4d9ee48ef01e734d05f8 (patch) | |
tree | 50cb9ed9ac08aab57ad4227a36597349ebc0c6fd /crypto/src/tls/DtlsRecordLayer.cs | |
parent | RFC 9146: Add simple record callback for testing purposes (diff) | |
download | BouncyCastle.NET-ed25519-f34a9e00ed839663297c4d9ee48ef01e734d05f8.tar.xz |
Add and use DtlsRecordCallback
Diffstat (limited to 'crypto/src/tls/DtlsRecordLayer.cs')
-rw-r--r-- | crypto/src/tls/DtlsRecordLayer.cs | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/crypto/src/tls/DtlsRecordLayer.cs b/crypto/src/tls/DtlsRecordLayer.cs index 82fc3db64..a61688cb0 100644 --- a/crypto/src/tls/DtlsRecordLayer.cs +++ b/crypto/src/tls/DtlsRecordLayer.cs @@ -278,7 +278,7 @@ namespace Org.BouncyCastle.Tls } /// <exception cref="IOException"/> - internal int Receive(byte[] buf, int off, int len, int waitMillis, Action recordCallback) + internal int Receive(byte[] buf, int off, int len, int waitMillis, DtlsRecordCallback recordCallback) { #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER return Receive(buf.AsSpan(off, len), waitMillis, recordCallback); @@ -348,7 +348,7 @@ namespace Org.BouncyCastle.Tls } /// <exception cref="IOException"/> - internal int ReceivePending(byte[] buf, int off, int len, Action recordCallback) + internal int ReceivePending(byte[] buf, int off, int len, DtlsRecordCallback recordCallback) { #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER return ReceivePending(buf.AsSpan(off, len), recordCallback); @@ -380,7 +380,7 @@ namespace Org.BouncyCastle.Tls } /// <exception cref="IOException"/> - internal int Receive(Span<byte> buffer, int waitMillis, Action recordCallback) + internal int Receive(Span<byte> buffer, int waitMillis, DtlsRecordCallback recordCallback) { long currentTimeMillis = DateTimeUtilities.CurrentUnixMs(); @@ -446,7 +446,7 @@ namespace Org.BouncyCastle.Tls } /// <exception cref="IOException"/> - internal int ReceivePending(Span<byte> buffer, Action recordCallback) + internal int ReceivePending(Span<byte> buffer, DtlsRecordCallback recordCallback) { if (m_recordQueue.Available > 0) { @@ -677,9 +677,10 @@ namespace Org.BouncyCastle.Tls // TODO Include 'currentTimeMillis' as an argument, use with Timeout, resetHeartbeat /// <exception cref="IOException"/> #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER - private int ProcessRecord(int received, byte[] record, Span<byte> buffer, Action recordCallback) + private int ProcessRecord(int received, byte[] record, Span<byte> buffer, DtlsRecordCallback recordCallback) #else - private int ProcessRecord(int received, byte[] record, byte[] buf, int off, int len, Action recordCallback) + private int ProcessRecord(int received, byte[] record, byte[] buf, int off, int len, + DtlsRecordCallback recordCallback) #endif { // NOTE: received < 0 (timeout) is covered by this first case @@ -823,13 +824,19 @@ namespace Org.BouncyCastle.Tls */ if (recordCallback != null) { - // TODO Make the callback more general than just peer address update - if (ContentType.tls12_cid == recordType && - isLatestConfirmed && - recordEpoch == m_readEpoch) + var flags = DtlsRecordFlags.None; + + if (recordEpoch == m_readEpoch && isLatestConfirmed) + { + flags |= DtlsRecordFlags.IsNewest; + } + + if (ContentType.tls12_cid == recordType) { - recordCallback(); + flags |= DtlsRecordFlags.UsesConnectionID; } + + recordCallback(flags); } switch (decoded.contentType) |