Skip to content
This repository has been archived by the owner on Apr 27, 2020. It is now read-only.

Commit

Permalink
fix server block
Browse files Browse the repository at this point in the history
  • Loading branch information
IrineSistiana committed Feb 18, 2020
1 parent 27f4c2f commit 797be8d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
10 changes: 9 additions & 1 deletion internal/core/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,15 @@ func (client *Client) dialWSS() (net.Conn, error) {
}

func (client *Client) dialTLS() (net.Conn, error) {
return tls.DialWithDialer(client.netDialer, "tcp", client.conf.RemoteAddr, client.tlsConf)
conn, err := tls.DialWithDialer(client.netDialer, "tcp", client.conf.RemoteAddr, client.tlsConf)
if err != nil {
return nil, err
}
if err := conn.Handshake(); err != nil {
conn.Close()
return nil, err
}
return conn, nil
}

func (client *Client) newServerConn() (net.Conn, error) {
Expand Down
28 changes: 19 additions & 9 deletions internal/core/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,11 @@ func NewServer(c *ServerConfig) (*Server, error) {

func (server *Server) Start() error {
listenConfig := net.ListenConfig{Control: getControlFunc(server.tcpConfig)}
innerListener, err := listenConfig.Listen(context.Background(), "tcp", server.conf.BindAddr)
listener, err := listenConfig.Listen(context.Background(), "tcp", server.conf.BindAddr)
if err != nil {
return fmt.Errorf("tls inner Listener: %v", err)
}

listener := tls.NewListener(innerListener, server.tlsConf)
server.listenerLocker.Lock()
server.listener = listener
server.listenerLocker.Unlock()
Expand All @@ -146,17 +145,28 @@ func (server *Server) Start() error {
}
} else {
for {
leftConn, err := listener.Accept()
leftRawConn, err := listener.Accept()
if err != nil {
return fmt.Errorf("listener.Accept: %v", err)
}
server.log.Debugf("leftConn from %s accepted", leftConn.RemoteAddr())

if server.conf.EnableMux {
server.handleClientMuxConn(leftConn)
} else {
server.handleClientConn(leftConn)
}
go func() {
server.log.Debugf("leftConn from %s accepted", leftRawConn.RemoteAddr())

leftConn := tls.Server(leftRawConn, server.tlsConf)
defer leftConn.Close()
if err := leftConn.Handshake(); err != nil {
server.log.Errorf("leftConn tls handshake: %v", err)
return
}

if server.conf.EnableMux {
server.handleClientMuxConn(leftConn)
} else {
server.handleClientConn(leftConn)
}
}()

}
}
return nil
Expand Down

0 comments on commit 797be8d

Please sign in to comment.