MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / serverRunRouterDomainSocket

Function serverRunRouterDomainSocket

cmd/wsh/cmd/wshcmd-connserver.go:288–395  ·  view source on GitHub ↗
(jwtToken string)

Source from the content-addressed store, hash-verified

286}
287
288func serverRunRouterDomainSocket(jwtToken string) error {
289 log.Printf("starting connserver router (domain socket upstream)")
290
291 // extract socket name from JWT token (unverified - we're on the client side)
292 sockName, err := wshutil.ExtractUnverifiedSocketName(jwtToken)
293 if err != nil {
294 return fmt.Errorf("error extracting socket name from JWT: %v", err)
295 }
296
297 // connect to the forwarded domain socket
298 sockName = wavebase.ExpandHomeDirSafe(sockName)
299 conn, err := net.Dial("unix", sockName)
300 if err != nil {
301 return fmt.Errorf("error connecting to domain socket %s: %v", sockName, err)
302 }
303
304 // create router
305 router := wshutil.NewWshRouter()
306 ConnServerWshRouter = router
307
308 // create proxy for the domain socket connection
309 upstreamProxy := wshutil.MakeRpcProxy("connserver-upstream")
310
311 // goroutine to write to the domain socket
312 go func() {
313 defer func() {
314 panichandler.PanicHandler("serverRunRouterDomainSocket:WriteLoop", recover())
315 }()
316 writeErr := wshutil.AdaptOutputChToStream(upstreamProxy.ToRemoteCh, conn)
317 if writeErr != nil {
318 log.Printf("error writing to upstream domain socket: %v\n", writeErr)
319 }
320 }()
321
322 // goroutine to read from the domain socket
323 go func() {
324 defer func() {
325 panichandler.PanicHandler("serverRunRouterDomainSocket:ReadLoop", recover())
326 }()
327 defer func() {
328 log.Printf("upstream domain socket closed, shutting down")
329 wshutil.DoShutdown("", 0, true)
330 }()
331 wshutil.AdaptStreamToMsgCh(conn, upstreamProxy.FromRemoteCh, nil)
332 }()
333
334 // register the domain socket connection as upstream
335 router.RegisterUpstream(upstreamProxy)
336
337 // use the router's control RPC to authenticate with upstream
338 controlRpc := router.GetControlRpc()
339
340 // authenticate with the upstream router using the JWT
341 _, err = wshclient.AuthenticateCommand(controlRpc, jwtToken, &wshrpc.RpcOpts{Route: wshutil.ControlRootRoute})
342 if err != nil {
343 return fmt.Errorf("error authenticating with upstream: %v", err)
344 }
345 log.Printf("authenticated with upstream router")

Callers 1

serverRunFunction · 0.85

Calls 15

RegisterUpstreamMethod · 0.95
GetControlRpcMethod · 0.95
ExpandHomeDirSafeFunction · 0.92
NewWshRouterFunction · 0.92
MakeRpcProxyFunction · 0.92
PanicHandlerFunction · 0.92
AdaptOutputChToStreamFunction · 0.92
DoShutdownFunction · 0.92
AdaptStreamToMsgChFunction · 0.92
AuthenticateCommandFunction · 0.92
GetJwtPublicKeyCommandFunction · 0.92

Tested by

no test coverage detected