You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2023/07/29 12:46:34 UTC

[dubbo] branch 3.2 updated: Disable QoS as Port Unification protocol (#12813)

This is an automated email from the ASF dual-hosted git repository.

albumenj pushed a commit to branch 3.2
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.2 by this push:
     new 2e04208405 Disable QoS as Port Unification protocol (#12813)
2e04208405 is described below

commit 2e04208405927c95de0e4c9c373041d2da867235
Author: Albumen Kevin <jh...@gmail.com>
AuthorDate: Sat Jul 29 20:46:28 2023 +0800

    Disable QoS as Port Unification protocol (#12813)
---
 .../dubbo/qos/protocol/QosProtocolWrapper.java     |   6 --
 .../java/org/apache/dubbo/qos/pu/QosDetector.java  |  56 ------------
 .../org/apache/dubbo/qos/pu/QosHTTP1Detector.java  |  39 --------
 .../org/apache/dubbo/qos/pu/QosWireProtocol.java   |  63 -------------
 .../org/apache/dubbo/qos/pu/TelnetDetector.java    | 100 ---------------------
 .../org.apache.dubbo.remoting.api.WireProtocol     |   1 -
 .../apache/dubbo/qos/pu/QosWireProtocolTest.java   |  41 ---------
 7 files changed, 306 deletions(-)

diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/protocol/QosProtocolWrapper.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/protocol/QosProtocolWrapper.java
index 127fa8bb42..a06b246ab4 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/protocol/QosProtocolWrapper.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/protocol/QosProtocolWrapper.java
@@ -23,9 +23,7 @@ import org.apache.dubbo.common.logger.LoggerFactory;
 import org.apache.dubbo.common.utils.StringUtils;
 import org.apache.dubbo.qos.api.PermissionLevel;
 import org.apache.dubbo.qos.common.QosConstants;
-import org.apache.dubbo.qos.pu.QosWireProtocol;
 import org.apache.dubbo.qos.server.Server;
-import org.apache.dubbo.remoting.api.WireProtocol;
 import org.apache.dubbo.rpc.Exporter;
 import org.apache.dubbo.rpc.Invoker;
 import org.apache.dubbo.rpc.Protocol;
@@ -104,10 +102,6 @@ public class QosProtocolWrapper implements Protocol, ScopeModelAware {
             }
 
             boolean qosEnable = url.getParameter(QOS_ENABLE, true);
-            WireProtocol qosWireProtocol = frameworkModel.getExtensionLoader(WireProtocol.class).getExtension("qos");
-            if (qosWireProtocol != null) {
-                ((QosWireProtocol) qosWireProtocol).setQosEnable(qosEnable);
-            }
             if (!qosEnable) {
                 logger.info("qos won't be started because it is disabled. " +
                     "Please check dubbo.application.qos.enable is configured either in system property, " +
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/pu/QosDetector.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/pu/QosDetector.java
deleted file mode 100644
index 6a91405352..0000000000
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/pu/QosDetector.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.qos.pu;
-
-import org.apache.dubbo.remoting.api.ProtocolDetector;
-import org.apache.dubbo.remoting.buffer.ChannelBuffer;
-import org.apache.dubbo.rpc.model.FrameworkModel;
-
-public class QosDetector implements ProtocolDetector {
-
-    private final QosHTTP1Detector qosHTTP1Detector = new QosHTTP1Detector();
-    private final TelnetDetector telnetDetector;
-    private boolean QosEnableFlag = true;
-
-    public void setQosEnableFlag(boolean qosEnableFlag) {
-        QosEnableFlag = qosEnableFlag;
-    }
-
-    public QosDetector(FrameworkModel frameworkModel) {
-        this.telnetDetector = new TelnetDetector(frameworkModel);
-    }
-
-    @Override
-    public Result detect(ChannelBuffer in) {
-        if(!QosEnableFlag) {
-            return Result.UNRECOGNIZED;
-        }
-        Result h1Res = qosHTTP1Detector.detect(in);
-        if(h1Res.equals(Result.RECOGNIZED)) {
-            return h1Res;
-        }
-        Result telRes = telnetDetector.detect(in);
-        if(telRes.equals(Result.RECOGNIZED)) {
-            return telRes;
-        }
-        if(h1Res.equals(Result.NEED_MORE_DATA) || telRes.equals(Result.NEED_MORE_DATA)) {
-            return Result.NEED_MORE_DATA;
-        }
-        return Result.UNRECOGNIZED;
-    }
-
-}
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/pu/QosHTTP1Detector.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/pu/QosHTTP1Detector.java
deleted file mode 100644
index 9a62b841b1..0000000000
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/pu/QosHTTP1Detector.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.qos.pu;
-
-import org.apache.dubbo.remoting.api.ProtocolDetector;
-import org.apache.dubbo.remoting.buffer.ChannelBuffer;
-
-public class QosHTTP1Detector implements ProtocolDetector {
-    private static boolean isHttp(int magic) {
-        return magic == 'G' || magic == 'P';
-    }
-
-    @Override
-    public Result detect(ChannelBuffer in) {
-        if (in.readableBytes() < 2) {
-            return Result.NEED_MORE_DATA;
-        }
-        final int magic = in.getByte(in.readerIndex());
-        // h2 starts with "PR"
-        if (isHttp(magic) && in.getByte(in.readerIndex()+1) != 'R' ){
-            return Result.RECOGNIZED;
-        }
-        return Result.UNRECOGNIZED;
-    }
-}
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/pu/QosWireProtocol.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/pu/QosWireProtocol.java
deleted file mode 100644
index 8d27679d6b..0000000000
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/pu/QosWireProtocol.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.qos.pu;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.extension.Activate;
-import org.apache.dubbo.common.utils.StringUtils;
-import org.apache.dubbo.qos.api.PermissionLevel;
-import org.apache.dubbo.qos.server.DubboLogo;
-import org.apache.dubbo.qos.api.QosConfiguration;
-import org.apache.dubbo.qos.server.handler.QosProcessHandler;
-import org.apache.dubbo.remoting.ChannelHandler;
-import org.apache.dubbo.remoting.api.AbstractWireProtocol;
-import org.apache.dubbo.remoting.api.pu.ChannelHandlerPretender;
-import org.apache.dubbo.remoting.api.pu.ChannelOperator;
-import org.apache.dubbo.rpc.model.FrameworkModel;
-import org.apache.dubbo.rpc.model.ScopeModelAware;
-
-import java.util.ArrayList;
-import java.util.List;
-
-@Activate
-public class QosWireProtocol extends AbstractWireProtocol implements ScopeModelAware {
-
-    public QosWireProtocol(FrameworkModel frameworkModel) {
-        super(new QosDetector(frameworkModel));
-    }
-
-    public void setQosEnable(boolean flag) {
-        ((QosDetector)this.detector()).setQosEnableFlag(flag);
-    }
-
-    @Override
-    public void configServerProtocolHandler(URL url, ChannelOperator operator) {
-        // add qosProcess handler
-        QosProcessHandler handler = new QosProcessHandler(url.getOrDefaultFrameworkModel(),
-            QosConfiguration.builder()
-                .welcome(DubboLogo.DUBBO)
-                .acceptForeignIp(false)
-                .acceptForeignIpWhitelist(StringUtils.EMPTY_STRING)
-                .anonymousAccessPermissionLevel(PermissionLevel.PUBLIC.name())
-                .build()
-        );
-        List<ChannelHandler> handlers = new ArrayList<>();
-        handlers.add(new ChannelHandlerPretender(handler));
-        operator.configChannelHandler(handlers);
-    }
-
-}
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/pu/TelnetDetector.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/pu/TelnetDetector.java
deleted file mode 100644
index d40f858377..0000000000
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/pu/TelnetDetector.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.qos.pu;
-
-import org.apache.dubbo.qos.api.BaseCommand;
-import org.apache.dubbo.qos.api.CommandContext;
-import org.apache.dubbo.qos.command.decoder.TelnetCommandDecoder;
-import org.apache.dubbo.remoting.api.ProtocolDetector;
-import org.apache.dubbo.remoting.buffer.ChannelBuffer;
-import org.apache.dubbo.remoting.buffer.ChannelBuffers;
-import org.apache.dubbo.remoting.buffer.HeapChannelBuffer;
-import org.apache.dubbo.rpc.model.FrameworkModel;
-
-import io.netty.util.CharsetUtil;
-
-import static java.lang.Math.min;
-
-
-public class TelnetDetector implements ProtocolDetector {
-
-    private final FrameworkModel frameworkModel;
-    private final int MaxSize = 2048;
-    private final ChannelBuffer AytPreface = new HeapChannelBuffer(new byte[]{(byte) 0xff, (byte) 0xf6});
-
-    public TelnetDetector(FrameworkModel frameworkModel) {
-        this.frameworkModel = frameworkModel;
-    }
-
-    @Override
-    public Result detect(ChannelBuffer in) {
-        if (in.readableBytes() >= MaxSize) {
-            return Result.UNRECOGNIZED;
-        }
-        Result resCommand = commandDetect(in);
-        if (resCommand.equals(Result.RECOGNIZED)) {
-            return resCommand;
-        }
-        Result resAyt = telnetAytDetect(in);
-        if (resAyt.equals(Result.RECOGNIZED)) {
-            return resAyt;
-        }
-        if (resAyt.equals(Result.UNRECOGNIZED) && resCommand.equals(Result.UNRECOGNIZED)) {
-            return Result.UNRECOGNIZED;
-        }
-        return Result.NEED_MORE_DATA;
-    }
-
-    private Result commandDetect(ChannelBuffer in) {
-        // detect if remote channel send a qos command to server
-        ChannelBuffer back = in.copy();
-        byte[] backBytes;
-        try {
-            backBytes = new byte[back.readableBytes()];
-            back.getBytes(back.readerIndex(), backBytes);
-        } finally {
-            back.release();
-        }
-
-        String s = new String(backBytes, CharsetUtil.UTF_8);
-        // trim /r/n to let parser work for input
-        s = s.trim();
-        CommandContext commandContext = TelnetCommandDecoder.decode(s);
-        if (frameworkModel.getExtensionLoader(BaseCommand.class).hasExtension(commandContext.getCommandName())) {
-            return Result.RECOGNIZED;
-        }
-        return Result.UNRECOGNIZED;
-    }
-
-    private Result telnetAytDetect(ChannelBuffer in) {
-        // detect if remote channel send a telnet ayt command to server
-        int prefaceLen = AytPreface.readableBytes();
-        int bytesRead = min(in.readableBytes(), prefaceLen);
-        if (bytesRead == 0 || !ChannelBuffers.prefixEquals(in, AytPreface, bytesRead)) {
-            return Result.UNRECOGNIZED;
-        }
-        if (bytesRead == prefaceLen) {
-            // we need to consume preface because it's not a qos command
-            // consume and remember to mark, pu server handler reset reader index
-            in.readBytes(AytPreface.readableBytes());
-            in.markReaderIndex();
-            return Result.RECOGNIZED;
-        }
-        return Result.NEED_MORE_DATA;
-    }
-
-}
diff --git a/dubbo-plugin/dubbo-qos/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.remoting.api.WireProtocol b/dubbo-plugin/dubbo-qos/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.remoting.api.WireProtocol
deleted file mode 100644
index cd4d62dd5c..0000000000
--- a/dubbo-plugin/dubbo-qos/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.remoting.api.WireProtocol
+++ /dev/null
@@ -1 +0,0 @@
-qos=org.apache.dubbo.qos.pu.QosWireProtocol
diff --git a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/pu/QosWireProtocolTest.java b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/pu/QosWireProtocolTest.java
deleted file mode 100644
index febeda154f..0000000000
--- a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/pu/QosWireProtocolTest.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.dubbo.qos.pu;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.remoting.api.pu.ChannelOperator;
-import org.apache.dubbo.rpc.model.FrameworkModel;
-
-import org.junit.jupiter.api.Test;
-
-import static org.mockito.ArgumentMatchers.anyList;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
-class QosWireProtocolTest {
-
-    @Test
-    void ShouldNotThrowExOnConfigServerProtocolHandler_GivenHappyPassConfig() {
-        final QosWireProtocol target = new QosWireProtocol(FrameworkModel.defaultModel());
-        final URL url = mock(URL.class);
-        final ChannelOperator channelOperator = mock(ChannelOperator.class);
-        target.configServerProtocolHandler(url, channelOperator);
-        verify(channelOperator).configChannelHandler(anyList());
-
-    }
-}