mivanac commented on a change in pull request #6063:
URL: https://github.com/apache/geode/pull/6063#discussion_r588139901



##########
File path: 
geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/Message.java
##########
@@ -1160,10 +1220,119 @@ public void receive() throws IOException {
   public void receive(ServerConnection sc, int maxMessageLength, Semaphore 
dataLimiter,
       Semaphore msgLimiter) throws IOException {
     this.serverConnection = sc;
+    if (sc.getSSLEngine() != null) {
+      setSslEngine(sc.getSSLEngine());
+    }
     this.maxIncomingMessageLength = maxMessageLength;
     this.dataLimiter = dataLimiter;
     this.messageLimiter = msgLimiter;
     receive();
   }
 
+  public void setSslEngine(NioSslEngine sslEngine) {
+    this.sslEngine = sslEngine;
+  }
+
+  private void readWrappedHeaders(ByteBuffer cb) throws IOException {
+    int bytesRead = this.socketChannel.read(cb);
+    if (bytesRead == -1) {
+      throw new EOFException(
+          "The connection has been reset while reading the header");
+    }
+    cb.flip();
+    try (final ByteBufferSharing outputSharing = sslEngine.unwrap(cb)) {
+      if (this.messageStats != null) {
+        
this.messageStats.incReceivedBytes(outputSharing.getBuffer().remaining());
+      }
+    }
+
+  }
+
+  private void readUnwrappedPayloadFields(int numParts, int readSecurePart, 
int bytesRemaining)
+      throws IOException {
+
+    final ByteBuffer cb = getCommBuffer();
+
+    ByteBuffer unwrapbuffer;
+    try (final ByteBufferSharing sharedBuffer = 
this.sslEngine.getUnwrappedBuffer()) {
+      unwrapbuffer = sharedBuffer.getBuffer();
+    }
+
+    for (int i = 0; i < numParts + readSecurePart
+        || readSecurePart == 1 && unwrapbuffer.remaining() > 0; i++) {
+      int bytesReadThisTime = readUnwrappedPartChunk(bytesRemaining);
+      bytesRemaining -= bytesReadThisTime;
+
+      Part part;
+
+      if (i < numParts) {
+        part = this.partsList[i];
+      } else {
+        part = this.securePart;
+      }
+
+      int partLen = unwrapbuffer.getInt();
+      byte partType = unwrapbuffer.get();
+      byte[] partBytes;
+
+      if (partLen > 0) {
+        partBytes = new byte[partLen];
+        int alreadyReadBytes = unwrapbuffer.remaining();
+        if (alreadyReadBytes > 0) {
+          if (partLen < alreadyReadBytes) {
+            alreadyReadBytes = partLen;
+          }
+          unwrapbuffer.get(partBytes, 0, alreadyReadBytes);
+        }
+
+        // now we need to read partLen - alreadyReadBytes off the wire
+        int off = alreadyReadBytes;
+        int remaining = partLen - off;
+
+        if (remaining > 0) {
+
+          this.sslEngine.ensureWrappedCapacity(remaining, cb,
+              BufferPool.BufferType.TRACKED_RECEIVER);

Review comment:
       I am not sure how to report this statistics. Do we report bytes that are 
read, or unwrapped?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to