walklown commented on code in PR #14026:
URL: https://github.com/apache/dubbo/pull/14026#discussion_r1594912777


##########
dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyPortUnificationServerHandler.java:
##########
@@ -181,4 +153,48 @@ private boolean isSsl(ByteBuf buf) {
         }
         return false;
     }
+
+    private void detectProtocol(ChannelHandlerContext ctx, URL url, 
NettyChannel channel, ByteBuf in) {
+        Set<String> supportedProtocolNames = new HashSet<>(protocols.keySet());
+        supportedProtocolNames.retainAll(urlMapper.keySet());
+
+        for (final String name : supportedProtocolNames) {
+            WireProtocol protocol = protocols.get(name);
+            in.markReaderIndex();
+            ChannelBuffer buf = new NettyBackedChannelBuffer(in);
+            final ProtocolDetector.Result result = 
protocol.detector().detect(buf);
+            in.resetReaderIndex();
+            switch (result.flag()) {
+                case UNRECOGNIZED:
+                    continue;
+                case RECOGNIZED:
+                    ChannelHandler localHandler = 
this.handlerMapper.getOrDefault(name, handler);
+                    URL localURL = this.urlMapper.getOrDefault(name, url);
+                    channel.setUrl(localURL);
+                    NettyConfigOperator operator = new 
NettyConfigOperator(channel, localHandler);
+                    operator.setDetectResult(result);
+                    protocol.configServerProtocolHandler(url, operator);
+                    ctx.pipeline().remove(this);
+                case NEED_MORE_DATA:
+                    return;
+                default:
+                    return;
+            }
+        }
+        byte[] preface = new byte[in.readableBytes()];
+        in.readBytes(preface);
+        Set<String> supported =

Review Comment:
   Thanks for your guidance.
   But this is not a newly submitted code, all I did was separate it into a 
separate method for reuse. The record is submitted because the plug-in 
formatted it.
   And this place will only be reached in the exception case that the 
appropriate protocol is not matched. Is it really a good idea to cache it in 
advance?
   If we don't need to get the latest data, can I use 'protocols' directly? It 
comes from 'AbstractPortUnificationServer'.
   <img width="1023" alt="image" 
src="https://github.com/apache/dubbo/assets/22697462/91336556-4406-4727-905e-142da2aecd4f";>
   



-- 
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.

To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org
For additional commands, e-mail: notifications-h...@dubbo.apache.org

Reply via email to