MCPcopy
hub / github.com/wavetermdev/waveterm / serverRunRouter

Function serverRunRouter

cmd/wsh/cmd/wshcmd-connserver.go:202–286  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

200}
201
202func serverRunRouter() error {
203 log.Printf("starting connserver router")
204 router := wshutil.NewWshRouter()
205 ConnServerWshRouter = router
206 termProxy := wshutil.MakeRpcProxy("connserver-term")
207 rawCh := make(chan []byte, wshutil.DefaultOutputChSize)
208 go func() {
209 defer func() {
210 panichandler.PanicHandler("serverRunRouter:Parse", recover())
211 }()
212 packetparser.Parse(os.Stdin, termProxy.FromRemoteCh, rawCh)
213 }()
214 go func() {
215 defer func() {
216 panichandler.PanicHandler("serverRunRouter:WritePackets", recover())
217 }()
218 for msg := range termProxy.ToRemoteCh {
219 packetparser.WritePacket(os.Stdout, msg)
220 }
221 }()
222 go func() {
223 defer func() {
224 panichandler.PanicHandler("serverRunRouter:drainRawCh", recover())
225 }()
226 defer func() {
227 log.Printf("stdin closed, shutting down")
228 wshutil.DoShutdown("", 0, true)
229 }()
230 for range rawCh {
231 // ignore
232 }
233 }()
234 router.RegisterUpstream(termProxy)
235
236 sockName := getRemoteDomainSocketName()
237
238 // setup the connserver rpc client first
239 client, bareRouteId, err := setupConnServerRpcClientWithRouter(router, sockName)
240 if err != nil {
241 return fmt.Errorf("error setting up connserver rpc client: %v", err)
242 }
243 wshfs.RpcClient = client
244 wshfs.RpcClientRouteId = bareRouteId
245
246 log.Printf("trying to get JWT public key")
247
248 // fetch and set JWT public key
249 jwtPublicKeyB64, err := wshclient.GetJwtPublicKeyCommand(client, nil)
250 if err != nil {
251 return fmt.Errorf("error getting jwt public key: %v", err)
252 }
253 jwtPublicKeyBytes, err := base64.StdEncoding.DecodeString(jwtPublicKeyB64)
254 if err != nil {
255 return fmt.Errorf("error decoding jwt public key: %v", err)
256 }
257 err = wavejwt.SetPublicKey(jwtPublicKeyBytes)
258 if err != nil {
259 return fmt.Errorf("error setting jwt public key: %v", err)

Callers 1

serverRunFunction · 0.85

Calls 15

RegisterUpstreamMethod · 0.95
NewWshRouterFunction · 0.92
MakeRpcProxyFunction · 0.92
PanicHandlerFunction · 0.92
ParseFunction · 0.92
WritePacketFunction · 0.92
DoShutdownFunction · 0.92
GetJwtPublicKeyCommandFunction · 0.92
SetPublicKeyFunction · 0.92
RunSysInfoLoopFunction · 0.92

Tested by

no test coverage detected