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

perf: 发布机使用自身的网关 #230

Merged
merged 1 commit into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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