mirror of
https://github.com/wavetermdev/backup.git
synced 2026-08-05 13:57:07 -07:00
Add Unix Domain Socket Listener when Establishing Connections (#243)
This makes it possible to send wsh commands from wsh on a remote session to wavesrv running locally. The exact behavior of running those commands isn't implemented, but the underlying interface is added here.
This commit is contained in:
@@ -11,7 +11,6 @@ import (
|
||||
"reflect"
|
||||
|
||||
"github.com/wavetermdev/thenextwave/pkg/ijson"
|
||||
"github.com/wavetermdev/thenextwave/pkg/shellexec"
|
||||
"github.com/wavetermdev/thenextwave/pkg/waveobj"
|
||||
"github.com/wavetermdev/thenextwave/pkg/wstore"
|
||||
)
|
||||
@@ -180,10 +179,10 @@ type CommandBlockRestartData struct {
|
||||
}
|
||||
|
||||
type CommandBlockInputData struct {
|
||||
BlockId string `json:"blockid" wshcontext:"BlockId"`
|
||||
InputData64 string `json:"inputdata64,omitempty"`
|
||||
SigName string `json:"signame,omitempty"`
|
||||
TermSize *shellexec.TermSize `json:"termsize,omitempty"`
|
||||
BlockId string `json:"blockid" wshcontext:"BlockId"`
|
||||
InputData64 string `json:"inputdata64,omitempty"`
|
||||
SigName string `json:"signame,omitempty"`
|
||||
TermSize *wstore.TermSize `json:"termsize,omitempty"`
|
||||
}
|
||||
|
||||
type CommandFileData struct {
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
package wshserver
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net"
|
||||
"sync"
|
||||
|
||||
"github.com/wavetermdev/thenextwave/pkg/wshrpc"
|
||||
@@ -17,44 +15,6 @@ const (
|
||||
DefaultInputChSize = 32
|
||||
)
|
||||
|
||||
func handleDomainSocketClient(conn net.Conn) {
|
||||
proxy := wshutil.MakeRpcProxy()
|
||||
go func() {
|
||||
writeErr := wshutil.AdaptOutputChToStream(proxy.ToRemoteCh, conn)
|
||||
if writeErr != nil {
|
||||
log.Printf("error writing to domain socket: %v\n", writeErr)
|
||||
}
|
||||
}()
|
||||
go func() {
|
||||
// when input is closed, close the connection
|
||||
defer conn.Close()
|
||||
wshutil.AdaptStreamToMsgCh(conn, proxy.FromRemoteCh)
|
||||
}()
|
||||
rpcCtx, err := proxy.HandleAuthentication()
|
||||
if err != nil {
|
||||
conn.Close()
|
||||
log.Printf("error handling authentication: %v\n", err)
|
||||
return
|
||||
}
|
||||
// now that we're authenticated, set the ctx and attach to the router
|
||||
log.Printf("domain socket connection authenticated: %#v\n", rpcCtx)
|
||||
proxy.SetRpcContext(rpcCtx)
|
||||
wshutil.DefaultRouter.RegisterRoute("controller:"+rpcCtx.BlockId, proxy)
|
||||
}
|
||||
|
||||
func RunWshRpcOverListener(listener net.Listener) {
|
||||
defer log.Printf("domain socket listener shutting down\n")
|
||||
for {
|
||||
conn, err := listener.Accept()
|
||||
if err != nil {
|
||||
log.Printf("error accepting connection: %v\n", err)
|
||||
continue
|
||||
}
|
||||
log.Print("got domain socket connection\n")
|
||||
go handleDomainSocketClient(conn)
|
||||
}
|
||||
}
|
||||
|
||||
var waveSrvClient_Singleton *wshutil.WshRpc
|
||||
var waveSrvClient_Once = &sync.Once{}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user