|
1 | 1 | package com.ss.mqtt.broker.network.packet.in;
|
2 | 2 |
|
3 | 3 | import com.ss.mqtt.broker.model.ConnectReasonCode;
|
| 4 | +import com.ss.mqtt.broker.model.MqttPropertyConstants; |
4 | 5 | import com.ss.mqtt.broker.model.MqttVersion;
|
5 | 6 | import com.ss.mqtt.broker.model.PacketProperty;
|
6 | 7 | import com.ss.mqtt.broker.network.MqttConnection;
|
7 | 8 | import com.ss.mqtt.broker.network.packet.PacketType;
|
8 | 9 | import com.ss.rlib.common.util.NumberUtils;
|
9 | 10 | import lombok.Getter;
|
10 | 11 | import org.jetbrains.annotations.NotNull;
|
| 12 | +import org.jetbrains.annotations.Nullable; |
11 | 13 |
|
12 | 14 | import java.nio.ByteBuffer;
|
13 | 15 | import java.util.EnumSet;
|
@@ -96,6 +98,7 @@ public class ConnectInPacket extends MqttReadablePacket {
|
96 | 98 | The User Property is allowed to appear multiple times to represent multiple name, value pairs. The same
|
97 | 99 | name is allowed to appear more than once
|
98 | 100 | */
|
| 101 | + // FIXME to do supporting |
99 | 102 | PacketProperty.USER_PROPERTY,
|
100 | 103 | /*
|
101 | 104 | Followed by a UTF-8 Encoded String containing the name of the authentication method used for
|
@@ -190,9 +193,19 @@ public class ConnectInPacket extends MqttReadablePacket {
|
190 | 193 |
|
191 | 194 | private @Getter byte[] willPayload;
|
192 | 195 |
|
| 196 | + // properties |
| 197 | + private @Nullable @Getter String authenticationMethod; |
| 198 | + private @Nullable @Getter byte[] authenticationData; |
| 199 | + |
| 200 | + private @Getter long sessionExpiryInterval = MqttPropertyConstants.SESSION_EXPIRY_INTERVAL_DEFAULT; |
| 201 | + private @Getter int receiveMax = MqttPropertyConstants.RECEIVE_MAXIMUM_DEFAULT; |
| 202 | + private @Getter int maximumPacketSize = MqttPropertyConstants.MAXIMUM_PACKET_SIZE_DEFAULT; |
| 203 | + private @Getter int topicAliasMaximum = MqttPropertyConstants.TOPIC_ALIAS_MAXIMUM_DEFAULT; |
| 204 | + private @Getter boolean requestResponseInformation = false; |
| 205 | + private @Getter boolean requestProblemInformation = false; |
| 206 | + |
193 | 207 | private @Getter int keepAlive;
|
194 | 208 | private @Getter int willQos;
|
195 |
| - |
196 | 209 | private @Getter boolean willRetain;
|
197 | 210 | private @Getter boolean cleanStart;
|
198 | 211 |
|
@@ -291,16 +304,70 @@ protected void readImpl(@NotNull MqttConnection connection, @NotNull ByteBuffer
|
291 | 304 |
|
292 | 305 | @Override
|
293 | 306 | protected void applyProperty(@NotNull PacketProperty property, @NotNull byte[] value) {
|
294 |
| - super.applyProperty(property, value); |
| 307 | + switch (property) { |
| 308 | + case AUTHENTICATION_DATA: |
| 309 | + authenticationData = value; |
| 310 | + break; |
| 311 | + default: |
| 312 | + unexpectedProperty(property); |
| 313 | + return; |
| 314 | + } |
295 | 315 | }
|
296 | 316 |
|
297 | 317 | @Override
|
298 | 318 | protected void applyProperty(@NotNull PacketProperty property, @NotNull String value) {
|
299 |
| - super.applyProperty(property, value); |
| 319 | + switch (property) { |
| 320 | + case AUTHENTICATION_METHOD: |
| 321 | + authenticationMethod = value; |
| 322 | + break; |
| 323 | + default: |
| 324 | + unexpectedProperty(property); |
| 325 | + } |
300 | 326 | }
|
301 | 327 |
|
302 | 328 | @Override
|
303 | 329 | protected void applyProperty(@NotNull PacketProperty property, int value) {
|
304 |
| - super.applyProperty(property, value); |
| 330 | + switch (property) { |
| 331 | + case RECEIVE_MAXIMUM: |
| 332 | + receiveMax = NumberUtils.validate( |
| 333 | + value, |
| 334 | + MqttPropertyConstants.RECEIVE_MAXIMUM_MIN, |
| 335 | + MqttPropertyConstants.RECEIVE_MAXIMUM_MAX |
| 336 | + ); |
| 337 | + break; |
| 338 | + case TOPIC_ALIAS_MAXIMUM: |
| 339 | + topicAliasMaximum = value; |
| 340 | + break; |
| 341 | + case REQUEST_RESPONSE_INFORMATION: |
| 342 | + requestResponseInformation = value == 1; |
| 343 | + break; |
| 344 | + case REQUEST_PROBLEM_INFORMATION: |
| 345 | + requestProblemInformation = value == 1; |
| 346 | + break; |
| 347 | + default: |
| 348 | + unexpectedProperty(property); |
| 349 | + } |
| 350 | + } |
| 351 | + |
| 352 | + @Override |
| 353 | + protected void applyProperty(@NotNull PacketProperty property, long value) { |
| 354 | + switch (property) { |
| 355 | + case SESSION_EXPIRY_INTERVAL: |
| 356 | + sessionExpiryInterval = NumberUtils.validate( |
| 357 | + value, |
| 358 | + 0, |
| 359 | + MqttPropertyConstants.SESSION_EXPIRY_INTERVAL_INFINITY |
| 360 | + ); |
| 361 | + break; |
| 362 | + case MAXIMUM_PACKET_SIZE: |
| 363 | + maximumPacketSize = NumberUtils.validate( |
| 364 | + (int) value, |
| 365 | + MqttPropertyConstants.MAXIMUM_PACKET_SIZE_MIN, |
| 366 | + MqttPropertyConstants.MAXIMUM_PACKET_SIZE_MAX |
| 367 | + ); |
| 368 | + break; |
| 369 | + default: |
| 370 | + unexpectedProperty(property); |
| 371 | + } |
305 | 372 | }
|
306 | 373 | }
|
0 commit comments