feat: implement ready chanel to wait for established connection

This commit is contained in:
Patryk Hegenberg 2026-01-11 11:44:45 +01:00
parent 4ed6a61b1d
commit 5de9ff7961
3 changed files with 41 additions and 11 deletions

View file

@ -14,6 +14,11 @@ const (
serviceName = "workctl"
keySSHPassword = "ssh-password"
keyRDPPassword = "rdp-password"
PortLocalSSH = "2048"
PortLocalRDP = "6000"
PortRemoteSSH = "22"
PortRemoteRDP = "3389"
)
type Config struct {

View file

@ -28,7 +28,7 @@ func NewForwarder(client *ssh.Client, localPort, remotePort, remoteHost string)
}
}
func (f *Forwarder) Start(ctx context.Context) error {
func (f *Forwarder) Start(ctx context.Context, ready chan<- struct{}) error {
localAddr := "127.0.0.1:" + f.localPort
remoteAddr := net.JoinHostPort(f.remoteHost, f.remotePort)
@ -37,6 +37,10 @@ func (f *Forwarder) Start(ctx context.Context) error {
return fmt.Errorf("failed to listen on %s: %w", localAddr, err)
}
if ready != nil {
close(ready)
}
go func() {
<-ctx.Done()
listener.Close()