Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add TLS support to gnet #435
feat: Add TLS support to gnet #435
Changes from 30 commits
697b56a
2e073d2
fe87eeb
7c5336a
3394893
40e9536
c7d0993
582f146
29768bc
ee43463
8e71e26
3e95281
af39088
492f83e
94ad7e8
43bf39f
76acc42
c377ece
d24fd00
3f21522
d13ead1
b1b7bc5
213300a
e054d94
2b05f32
5217a6a
f45a29f
d4ab072
a0bf9d9
369338e
0ccefca
37393e2
2705b62
bef64fa
25c4638
ccc7c28
d35e196
9a79add
f6206bb
9b98998
d25b6ab
9015fae
18c311d
e174dc7
ecdf787
6191b85
d78adc6
7de6c58
01c9175
2811c08
4cb0c79
b364de7
98b0001
e2cb32b
10bb4fe
e1a5a23
ee22f05
e860437
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you use
outboundBuffer
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
因为 tlsconn.Write 会透明加密 data,然后调用gnetConn.WriteTCP() -> gnetConn.write().
这样就可以直接往socket写数据,而不是copy到outboundbuffer,然后再写数据,性能更好。
在kernel tls开启的时候,可以做到zero-copy,因为内核直接透明加密。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
call stack
c.tlsconn.Write
->gnetConn.WriteTCP()
->gnetConn.write()
gnetConn.write()
会透明管理 outboundbufferThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this new method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tlsconn.Write() 内部最终会向 gnetConn 写数据,但是gnetConn 内部又有tlsconn 的指针,所以就会有一个死循环。
参照 https://github.com/0-haha/gnet_go_tls/blob/5728fd829790624e21452e217702b9c9964ded45/conn.go#L920-L940
因为tlsconn.Write()是把加密后的数据写到gnetconn,所以需要gnetConn暴露只写明文的API就是gnetConn.write()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么版本号不是 v1.20.2 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
版本号用 v1.20.2
go mod tidy
会报错为什么用v120 ?
go mod 不支持v1.x, 必须是int。为了支持多版本go,比如未来的v1.21,所以go 1.20的 go mod 链接用
github.com/0-haha/gnet_go_tls/v120
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你这种 go mod 版本号的用法太奇怪了,我理解并不需要在 go.mod 里加上 v120,后面的版本号通过 github release 和 tag 来管理就行了。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个是针对go 1.20的实现。
https://github.com/0-haha/gnet/blob/dev/pkg/tls/go120.go
针对不同go 版本用go:build 来区分编译的包
go-quic 是直接每个不同的go 版本一个git repo。你看一下他的import就知道了。
https://github.com/quic-go/quic-go/tree/master/internal/qtls
目前还没想到更好的办法在一个仓库里维护多个版本的办法
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@panjf2000 go mod 里面是准备一个go版本一个TLS库吗? 维护就只能fork + cherry pick了。
或者就是一个repo下两个文件夹,一个文件夹对应一个go版本
我就想到这两种方案,其他的试过了,但是使用的时候必须要在go mod里用replace ,直接跑go mod tidy 会报错。
你倾向哪个方案
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
go.mod 里改成 github.com/0-haha/gnet-tls-go1-20 v1.20.2-rc.1
resolved in new commits