Skip to content

Commit

Permalink
client short circuit replace support ListenerConfig too
Browse files Browse the repository at this point in the history
  • Loading branch information
wwqgtxx committed Oct 31, 2022
1 parent b9f9765 commit 0e9c375
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
11 changes: 11 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ func (c *client) SetClientImpl(impl common.ClientImpl) {
c.ClientImpl = impl
}

func (c *client) GetListenerConfig() any {
return c.listenerConfig
}

func (c *client) SetListenerConfig(cfg any) {
c.listenerConfig = cfg.(listener.Config)
c.listenerConfig.IsWebSocketListener = false
}

func (c *client) GetServerWSPath() string {
return c.serverWSPath
}
Expand Down Expand Up @@ -353,6 +362,8 @@ func StartClients() {
client.Addr(),
")")
newServer := _server.CloneWithNewAddress(client.Addr())
listenerConfig := client.GetListenerConfig()
newServer.SetListenerConfig(listenerConfig)
common.PortToServer[clientPort] = newServer
delete(common.PortToClient, clientPort) //It is safe in Golang!!!
continue
Expand Down
7 changes: 7 additions & 0 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
var PortToServer = make(map[string]Server)

type Server interface {
HasListenerConfig
Start()
Addr() string
CloneWithNewAddress(bindAddress string) Server
Expand All @@ -19,6 +20,7 @@ var PortToClient = make(map[string]Client)

type Client interface {
ClientImpl
HasListenerConfig
Start()
Addr() string
GetClientImpl() ClientImpl
Expand All @@ -38,3 +40,8 @@ type ClientConn interface {
TunnelTcp(tcp net.Conn)
TunnelWs(ws *websocket.Conn)
}

type HasListenerConfig interface {
GetListenerConfig() any
SetListenerConfig(cfg any)
}
9 changes: 9 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ func (s *server) CloneWithNewAddress(bindAddress string) common.Server {
return &ns
}

func (s *server) GetListenerConfig() any {
return s.listenerConfig
}

func (s *server) SetListenerConfig(cfg any) {
s.listenerConfig = cfg.(listener.Config)
s.listenerConfig.IsWebSocketListener = true
}

type ServerHandler http.Handler

type serverHandler struct {
Expand Down

0 comments on commit 0e9c375

Please sign in to comment.