Skip to content
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

能否支持自动匹配客户端版本 (version 1,2) #94

Open
josh-chan opened this issue Jan 12, 2023 · 2 comments
Open

能否支持自动匹配客户端版本 (version 1,2) #94

josh-chan opened this issue Jan 12, 2023 · 2 comments

Comments

@josh-chan
Copy link

看了一下代码,不是很有信心能改对:

--- a/session.go
+++ b/session.go
@@ -325,10 +325,11 @@ func (s *Session) recvLoop() {
                // read header first
                if _, err := io.ReadFull(s.conn, hdr[:]); err == nil {
                        atomic.StoreInt32(&s.dataReady, 1)
-                       if hdr.Version() != byte(s.config.Version) {
+                       if !(hdr.Version() == byte(1) || hdr.Version() == byte(2)) {
                                s.notifyProtoError(ErrInvalidProtocol)
                                return
                        }
+                       s.config.Version = int(hdr.Version())
                        sid := hdr.StreamID()
                        switch hdr.Cmd() {
                        case cmdNOP:

server 能否通过这样自动适配客户端的协议版本?
@xtaci

@xtaci
Copy link
Owner

xtaci commented Jan 13, 2023

嗯,貌似是可以的。

@josh-chan
Copy link
Author

嗯,貌似是可以的。

多谢,试了一下,真的可以。还有一个地方要改,保证每个 session 用独立的 Config:

--- a/mux.go
+++ b/mux.go
@@ -94,7 +94,8 @@ func Server(conn io.ReadWriteCloser, config *Config) (*Session, error) {
        if err := VerifyConfig(config); err != nil {
                return nil, err
        }
-       return newSession(config, conn, false), nil
- 
+       cloneConfig := *config
+       return newSession(&cloneConfig, conn, false), nil
 }

觉得就像是个 trick,等大佬更新。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants