Skip to content

Commit

Permalink
perf: 发布机使用自身的网关
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeEirc committed Jul 27, 2023
1 parent 52646c8 commit 925789f
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 36 deletions.
20 changes: 0 additions & 20 deletions pkg/gateway/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const (
)

type DomainGateway struct {
Domain *model.Domain
DstAddr string // 10.0.0.1:3389

sshClient *gossh.Client
Expand Down Expand Up @@ -92,25 +91,6 @@ func (d *DomainGateway) getAvailableGateway() bool {
d.sshClient = sshClient
return true
}
if d.Domain == nil {
return false
}
for i := range d.Domain.Gateways {
gateway := d.Domain.Gateways[i]
if !gateway.Protocols.IsSupportProtocol("ssh") {
continue
}
logger.Info("Try ssh dial gateway ", gateway.Name)
sshClient, err := d.createGatewaySSHClient(&gateway)
if err != nil {
logger.Errorf("Failed ssh dial %s: %s", gateway.Name, err.Error())
continue
}
logger.Infof("Dial gateway %s success", gateway.Name)
d.sshClient = sshClient
d.SelectedGateway = &gateway
return true
}
return false
}
func (d *DomainGateway) createGatewaySSHClient(gateway *model.Gateway) (*gossh.Client, error) {
Expand Down
8 changes: 1 addition & 7 deletions pkg/jms-sdk-go/model/remote_app.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package model

type RemoteAppParameter struct {
Parameters string `json:"parameters"`
Program string `json:"program"`
WorkingDirectory string `json:"working_directory"`
}

type Applet struct {
Id string `json:"id"`
Name string `json:"name"`
Expand All @@ -16,7 +10,7 @@ type AppletOption struct {
Applet Applet `json:"applet"`
Host Asset `json:"host"`
Account Account `json:"account"`
Gateway Gateway `json:"gateway"`
Gateway *Gateway `json:"gateway"`
RemoteAppOption RemoteAppCommandOption `json:"remote_app_option"`
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/session/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ func (s *Server) CreatByToken(ctx *gin.Context, token string) (TunnelSession, er
opts = append(opts, WithAppletOption(appletOpt))
logger.Infof("Connect applet(%s) use host(%s) account (%s)", connectToken.Asset.String(),
appletOpt.Host.String(), appletOpt.Account.String())
// 连接发布机,不需要网关
opts = append(opts, WithGateway(nil))
// 连接发布机,需要使用发布机的网关
opts = append(opts, WithGateway(appletOptions.Gateway))
}
return s.Create(ctx, opts...)
}
Expand Down
1 change: 0 additions & 1 deletion pkg/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ type TunnelSession struct {
Platform *model.Platform `json:"platform"`
RemoteApp *model.Applet `json:"remote_app"`
Permission *model.Permission `json:"permission"`
Domain *model.Domain `json:"-"`
Gateway *model.Gateway `json:"-"`
TerminalConfig *model.TerminalConfig `json:"-"`
ExpireInfo model.ExpireInfo `json:"expire_info"`
Expand Down
8 changes: 2 additions & 6 deletions pkg/tunnel/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,11 @@ func (g *GuacamoleTunnelServer) Connect(ctx *gin.Context) {
for argName, argValue := range info.ExtraConfig() {
conf.SetParameter(argName, argValue)
}
// 设置网域网关,替换本地。 兼容云平台同步 配置网域,但网关配置为空的情况
if (tunnelSession.Domain != nil && len(tunnelSession.Domain.Gateways) != 0) ||
tunnelSession.Gateway != nil {
if tunnelSession.Gateway != nil {
dstAddr := net.JoinHostPort(conf.GetParameter(guacd.Hostname),
conf.GetParameter(guacd.Port))
domainGateway := gateway.DomainGateway{
Domain: tunnelSession.Domain,
DstAddr: dstAddr,

DstAddr: dstAddr,
SelectedGateway: tunnelSession.Gateway,
}
if err = domainGateway.Start(); err != nil {
Expand Down

0 comments on commit 925789f

Please sign in to comment.