func (server *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	requestEntry := logrus.WithField("http_client", r.RemoteAddr)
	requestEntry.Debug("http connection accepted")
	leftWSConn, err := server.upgrader.Upgrade(w, r, nil)
	if err != nil {
		requestEntry.Errorf("upgrade http request, %v", err)
		return
	}
	leftConn := wrapWebSocketConn(leftWSConn)
	switch leftWSConn.Subprotocol() {
	case websocketSubprotocolSmuxON:
		server.handleClientMuxConn(leftConn, requestEntry)
	case websocketSubprotocolSmuxOFF:
		server.handleClientConn(leftConn, requestEntry)
	default:
		if server.conf.EnableMux {
			server.handleClientMuxConn(leftConn, requestEntry)
		} else {
			server.handleClientConn(leftConn, requestEntry)
		}
	}
}
ServeHTTP implements http.Handler interface
package core
import (
	"context"
	"crypto/ecdsa"
	"crypto/elliptic"
	"crypto/rand"
	"crypto/tls"
	"crypto/x509"
	"crypto/x509/pkix"
	"encoding/pem"
	"errors"
	"fmt"
	"math/big"
	"net"
	"net/http"
	"sync"
	"time"
	mathRand "math/rand"
	"github.com/gorilla/websocket"
	"github.com/sirupsen/logrus"
	"github.com/xtaci/smux"
)
type Server struct {
	conf *ServerConfig
	tlsConf   *tls.Config
	tcpConfig *tcpConfig
	upgrader websocket.Upgrader
	netDialer *net.Dialer
	listenerLocker sync.Mutex
	listener       net.Listener
	smuxConfig *smux.Config
	log *logrus.Logger
	testDialDst func() (net.Conn, error)
}
func NewServer(c *ServerConfig) (*Server, error) {
	server := new(Server)
	if len(c.BindAddr) == 0 {
		return nil, errors.New("need bind address")
	}
	if len(c.DstAddr) == 0 {
		return nil, errors.New("need destination server address")
	}
	if c.Timeout <= 0 {
		return nil, errors.New("timeout value must at least 1 sec")
	}
	server.log = logrus.New()
	if c.Verbose {
		server.log.SetLevel(logrus.DebugLevel)
	} else {
		server.log.SetLevel(logrus.ErrorLevel)
	}
	server.conf = c
	server.tcpConfig = &tcpConfig{tfo: c.EnableTFO}
	if server.conf.DisableTLS == false {
		server.tlsConf = new(tls.Config)
		if len(c.Cert) == 0 && len(c.Key) == 0 {  
			cers, err := generateCertificate(server.conf.ServerName)
			if err != nil {
				return nil, fmt.Errorf("generate certificate: %v", err)
			}
			server.log.Print("WARNING: you are using a self-signed certificate")
			server.tlsConf.Certificates = cers
		} else {
			cer, err := tls.LoadX509KeyPair(c.Cert, c.Key)  
			if err != nil {
				return nil, fmt.Errorf("failed to load key and cert, %v", err)
			}
			server.tlsConf.Certificates = []tls.Certificate{cer}
		}
	}
	server.netDialer = &net.Dialer{
		Control: getControlFunc(server.tcpConfig),
		Timeout: defaultHandShakeTimeout,
	}
	server.upgrader = websocket.Upgrader{
		HandshakeTimeout: defaultHandShakeTimeout,
		ReadBufferSize:   0,  
		WriteBufferSize:  0,
		Subprotocols: []string{websocketSubprotocolSmuxON, websocketSubprotocolSmuxOFF},
	}
	server.smuxConfig = defaultSmuxConfig()
	return server, nil
}
func (server *Server) Start() error {
	var l net.Listener
	var err error
	if server.conf.BindUnix {
		l, err = listenUnix(server.conf.BindAddr)
	} else {
		listenConfig := net.ListenConfig{Control: getControlFunc(server.tcpConfig)}
		l, err = listenConfig.Listen(context.Background(), "tcp", server.conf.BindAddr)
	}
	if err != nil {
		return fmt.Errorf("listener.Listen: %v", err)
	}
	defer l.Close()
	return server.ActiveAndServe(l)
}
func (server *Server) ActiveAndServe(l net.Listener) error {
	if !server.conf.DisableTLS {
		l = tls.NewListener(l, server.tlsConf)
	}
	server.listenerLocker.Lock()
	server.listener = l
	server.listenerLocker.Unlock()
	server.log.Printf("plugin listen at %s", l.Addr())
	if server.conf.EnableWSS {
		httpMux := http.NewServeMux()
		httpMux.Handle(server.conf.WSSPath, server)
		err := http.Serve(server.listener, httpMux)
		if err != nil {
			return fmt.Errorf("http.Serve: %v", err)
		}
	} else {
		for {
			leftConn, err := l.Accept()
			if err != nil {
				return fmt.Errorf("listener.Accept: %v", err)
			}
			go func() {
				defer leftConn.Close()
				requestEntry := logrus.WithField("client", leftConn.RemoteAddr())
				requestEntry.Debug("connection accepted")
				if tlsConn, ok := leftConn.(*tls.Conn); ok {
					if err := tlsConn.Handshake(); err != nil {
						requestEntry.Errorf("tls handshake: %v", err)
						return
					}
				}
				if server.conf.EnableMux {
					server.handleClientMuxConn(leftConn, requestEntry)
				} else {
					server.handleClientConn(leftConn, requestEntry)
				}
			}()
		}
	}
	return nil
}
func (server *Server) Close() error {
	server.listenerLocker.Lock()
	defer server.listenerLocker.Unlock()
	if server.listener != nil {
		return server.listener.Close()
	}
	return nil
}
func (server *Server) handleClientConn(leftConn net.Conn, requestEntry *logrus.Entry) {
	rightConn, err := server.dialDst()
	if err != nil {
		requestEntry.Errorf("dial dst, %v", err)
		return
	}
	defer rightConn.Close()
	err = openTunnel(rightConn, leftConn, server.conf.Timeout)
	if err != nil {
		requestEntry.Errorf("openTunnel, %v", err)
	}
}
func (server *Server) handleClientMuxConn(leftConn net.Conn, requestEntry *logrus.Entry) {
	handleClientMuxConn(server.smuxConfig, defaultSmuxMaxStream, leftConn, server.handleClientConn, requestEntry)
}