()
| 349 | } |
| 350 | |
| 351 | func (router *WshRouter) runServer() { |
| 352 | for input := range router.inputCh { |
| 353 | msgBytes := input.MsgBytes |
| 354 | var msg RpcMessage |
| 355 | err := json.Unmarshal(msgBytes, &msg) |
| 356 | if err != nil { |
| 357 | fmt.Println("error unmarshalling message: ", err) |
| 358 | continue |
| 359 | } |
| 360 | routeId := msg.Route |
| 361 | if msg.Command != "" { |
| 362 | // new comand, setup new rpc |
| 363 | ok := router.sendRoutedMessage(msgBytes, routeId, msg.Command, input.IngressLinkId) |
| 364 | if !ok { |
| 365 | router.handleNoRoute(msg, input.IngressLinkId) |
| 366 | continue |
| 367 | } |
| 368 | router.registerRouteInfo(msg.ReqId, input.IngressLinkId, routeId) |
| 369 | continue |
| 370 | } |
| 371 | // look at reqid or resid to route correctly |
| 372 | if msg.ReqId != "" { |
| 373 | routeInfo := router.getRouteInfo(msg.ReqId) |
| 374 | if routeInfo == nil { |
| 375 | // no route info, nothing to do |
| 376 | continue |
| 377 | } |
| 378 | // no need to check the return value here (noop if failed) |
| 379 | router.sendRoutedMessage(msgBytes, routeInfo.destRouteId, "", input.IngressLinkId) |
| 380 | continue |
| 381 | } else if msg.ResId != "" { |
| 382 | routeInfo := router.getRouteInfo(msg.ResId) |
| 383 | if routeInfo == nil { |
| 384 | // no route info, nothing to do |
| 385 | continue |
| 386 | } |
| 387 | router.sendMessageToLink(msgBytes, routeInfo.sourceLinkId, input.IngressLinkId) |
| 388 | if !msg.Cont { |
| 389 | router.unregisterRouteInfo(msg.ResId) |
| 390 | } |
| 391 | continue |
| 392 | } else { |
| 393 | // this is a bad message (no command, reqid, or resid) |
| 394 | continue |
| 395 | } |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | func (router *WshRouter) WaitForRegister(ctx context.Context, routeId string) error { |
| 400 | for { |
no test coverage detected