48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package ssh
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"sync"
|
|
|
|
"github.com/Neur0toxine/sshpoke/internal/config"
|
|
"github.com/Neur0toxine/sshpoke/internal/model"
|
|
"github.com/Neur0toxine/sshpoke/internal/server/driver/iface"
|
|
"github.com/Neur0toxine/sshpoke/internal/server/driver/util"
|
|
"github.com/Neur0toxine/sshpoke/internal/server/proto/sshtun"
|
|
)
|
|
|
|
type SSH struct {
|
|
ctx context.Context
|
|
name string
|
|
params Params
|
|
sessions map[string]conn
|
|
wg sync.WaitGroup
|
|
}
|
|
|
|
type conn struct {
|
|
container model.Container
|
|
tun *sshtun.Tunnel
|
|
}
|
|
|
|
func New(ctx context.Context, name string, params config.DriverParams) (iface.Driver, error) {
|
|
drv := &SSH{ctx: ctx, name: name, sessions: make(map[string]conn)}
|
|
if err := util.UnmarshalParams(params, &drv.params); err != nil {
|
|
return nil, err
|
|
}
|
|
return drv, nil
|
|
}
|
|
|
|
func (d *SSH) Handle(event model.Event) error {
|
|
// TODO: Implement event handling & connections management.
|
|
return errors.New(d.name + " server handler is not implemented yet")
|
|
}
|
|
|
|
func (d *SSH) Driver() config.DriverType {
|
|
return config.DriverSSH
|
|
}
|
|
|
|
func (d *SSH) WaitForShutdown() {
|
|
d.wg.Wait()
|
|
}
|