apache / apache/dubbo

WireProtocol Wrappable

Open
#12,977 3 comments 0 reactions 0 assignees View on GitHub
component/sdk help wanted type/proposal
Dominant language
Java
Stars
41.6k
Forks
26.4k
Avg merge
15h 13m
Merged PRs (30d)
4

Description

- [x] I have searched the [issues](https://github.com/apache/dubbo/issues) of this repository and believe that this is not a duplicate.
- [x] I have searched the [release notes](https://github.com/apache/dubbo/releases) of this repository and believe that this is not a duplicate.

## Describe the feature

代码原因导致WireProtocl 无法被Wrapper机制封装.

### 背景
应用与应用之间有权限拦截的诉求, 身份认证这块采用了mTLS认证. 应用身份通过tls证书获取, 因此需要将TLS上下文里的身份信息传递到Protocol层. 目前对于Triple协议, 找到了WireProtocol作为切入点, 使用Wrapper机制覆写ChannelHandler配置逻辑.
```java
@Wrapper(mismatches = {"qos"})
public class WireProtocolWrapper implements WireProtocol {

}
```
项目测试时 发现此方法会导致NPE. 原因如下:
### 问题代码块
```java
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out)
throws Exception {
....
if (providerConnectionConfig != null && isSsl(in)) {
enableSsl(ctx, providerConnectionConfig);
} else {
for (final WireProtocol protocol : protocols) {
...
switch (result) {
case UNRECOGNIZED:
continue;
case RECOGNIZED:
// 这里通过getExtensionName获取protocolName. 由于我对WireProtocol进行了Wrapper, protocol#getClass返回的是WireProtocolWrapper类, 导致无法获取的protocolName为空.
String protocolName = url.getOrDefaultFrameworkModel().getExtensionLoader(WireProtocol.class)
.getExtensionName(protocol);
// 这里因为protocolName为空, 导致ConcurrentHashMap抛出NPE
hannelHandler localHandler = this.handlerMapper.getOrDefault(protocolName, handler);
....
}
}
....
}
}
```
### 建议:
1. 出于扩展性需要, 是不是可以对WireProtocol协议暴露getName方法, 改为WireProtocol#getName 获取ProtocolName.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.