summaryrefslogtreecommitdiffstats
path: root/hv-collector-domain/src/main/kotlin
diff options
context:
space:
mode:
authorPiotr Jaszczyk <piotr.jaszczyk@nokia.com>2018-10-05 09:02:06 +0200
committerPiotr Jaszczyk <piotr.jaszczyk@nokia.com>2018-10-05 09:02:06 +0200
commitffe57b5673af80942925eed5b8e793ce2cf750b1 (patch)
tree31c7ee54da63a127da20662c29a58147c5c4f2ce /hv-collector-domain/src/main/kotlin
parent7b178765c00751fd99399eec76f1006270ae41dd (diff)
Introduce configurable payload size limitation
Maximum payload size will be configurable (from command line parameter or environment variable). The default value is same as previous hardcoded value, ie. 1 MiB = 1024 * 1024 bytes. Change-Id: Iec83d8295252bac353d3794b13454fdbbc80ecc4 Issue-ID: DCAEGEN2-856 Signed-off-by: Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
Diffstat (limited to 'hv-collector-domain/src/main/kotlin')
-rw-r--r--hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/codec.kt9
-rw-r--r--hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/errors.kt5
-rw-r--r--hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/wire_frame.kt2
3 files changed, 7 insertions, 9 deletions
diff --git a/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/codec.kt b/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/codec.kt
index 4f867f13..f08ec178 100644
--- a/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/codec.kt
+++ b/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/codec.kt
@@ -24,7 +24,6 @@ import arrow.core.Left
import arrow.core.Right
import io.netty.buffer.ByteBuf
import io.netty.buffer.ByteBufAllocator
-import org.onap.dcae.collectors.veshv.domain.WireFrameMessage.Companion.MAX_PAYLOAD_SIZE
import org.onap.dcae.collectors.veshv.domain.WireFrameMessage.Companion.RESERVED_BYTE_COUNT
/**
@@ -52,7 +51,7 @@ class WireFrameEncoder(private val allocator: ByteBufAllocator = ByteBufAllocato
* @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
* @since June 2018
*/
-class WireFrameDecoder {
+class WireFrameDecoder(private val maxPayloadSizeBytes: Int) {
fun decodeFirst(byteBuf: ByteBuf): Either<WireFrameDecodingError, WireFrameMessage> =
when {
@@ -81,13 +80,13 @@ class WireFrameDecoder {
private fun parsePayloadFrame(byteBuf: ByteBuf): Either<WireFrameDecodingError, WireFrameMessage> {
val versionMajor = byteBuf.readUnsignedByte()
val versionMinor = byteBuf.readUnsignedByte()
- byteBuf.skipBytes(RESERVED_BYTE_COUNT) // reserved
+ byteBuf.skipBytes(RESERVED_BYTE_COUNT)
val payloadTypeRaw = byteBuf.readUnsignedByte()
val payloadSize = byteBuf.readInt()
- if (payloadSize > MAX_PAYLOAD_SIZE) {
+ if (payloadSize > maxPayloadSizeBytes) {
byteBuf.resetReaderIndex()
- return Left(PayloadSizeExceeded)
+ return Left(PayloadSizeExceeded(maxPayloadSizeBytes))
}
if (byteBuf.readableBytes() < payloadSize) {
diff --git a/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/errors.kt b/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/errors.kt
index dfadc5b8..0d55cebb 100644
--- a/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/errors.kt
+++ b/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/errors.kt
@@ -19,8 +19,6 @@
*/
package org.onap.dcae.collectors.veshv.domain
-import org.onap.dcae.collectors.veshv.domain.WireFrameMessage.Companion.MAX_PAYLOAD_SIZE
-
/**
* @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
* @since June 2018
@@ -38,7 +36,8 @@ class InvalidWireFrameMarker(actualMarker: Short) : InvalidWireFrame(
.format(WireFrameMessage.MARKER_BYTE, actualMarker)
)
-object PayloadSizeExceeded : InvalidWireFrame("payload size exceeds the limit ($MAX_PAYLOAD_SIZE bytes)")
+class PayloadSizeExceeded(maxPayloadSizeBytes: Int) :
+ InvalidWireFrame("payload size exceeds the limit ($maxPayloadSizeBytes bytes)")
// Missing bytes errors
diff --git a/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/wire_frame.kt b/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/wire_frame.kt
index 036888e1..5fdc5afe 100644
--- a/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/wire_frame.kt
+++ b/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/wire_frame.kt
@@ -70,6 +70,6 @@ data class WireFrameMessage(val payload: ByteData,
RESERVED_BYTE_COUNT * java.lang.Byte.BYTES + // reserved bytes
1 * java.lang.Integer.BYTES // payload length
- const val MAX_PAYLOAD_SIZE = 1024 * 1024
+ const val DEFAULT_MAX_PAYLOAD_SIZE_BYTES = 1024 * 1024
}
}