(c *conn, msg *nodev1.NodeMessage)
| 293 | } |
| 294 | |
| 295 | func (h *Hub) dispatch(c *conn, msg *nodev1.NodeMessage) { |
| 296 | h.metrics.markSeen(c.nodeID) |
| 297 | event := msg.GetEvent() |
| 298 | if event != "" { |
| 299 | // 优先派发到流订阅;命中则不再走 PushHandler。 |
| 300 | if id := msg.GetId(); id != "" { |
| 301 | if v, ok := c.streamSubs.Load(id); ok { |
| 302 | s := v.(*Stream) |
| 303 | s.deliver(StreamFrame{Event: event, Body: append([]byte(nil), msg.GetBody()...)}) |
| 304 | return |
| 305 | } |
| 306 | } |
| 307 | h.handleEvent(c, msg) |
| 308 | return |
| 309 | } |
| 310 | id := msg.GetId() |
| 311 | if id == "" { |
| 312 | // 既无 id 也无 event → 丢弃 |
| 313 | return |
| 314 | } |
| 315 | // 流终态:node 在流结束时回一条普通响应(Ok=true 或 Ok=false+Error) |
| 316 | if v, ok := c.streamSubs.Load(id); ok { |
| 317 | s := v.(*Stream) |
| 318 | var endErr error |
| 319 | if !msg.GetOk() { |
| 320 | es := msg.GetError() |
| 321 | if es == "" { |
| 322 | es = "node returned not-ok with empty error" |
| 323 | } |
| 324 | endErr = errors.New(es) |
| 325 | } |
| 326 | s.closeFromHub(endErr) |
| 327 | return |
| 328 | } |
| 329 | if v, ok := c.pending.Load(id); ok { |
| 330 | ch := v.(chan *nodev1.NodeMessage) |
| 331 | select { |
| 332 | case ch <- msg: |
| 333 | default: |
| 334 | // 通道已满(不应发生,buffer=1 且只投递一次) |
| 335 | } |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | func (h *Hub) handleEvent(c *conn, msg *nodev1.NodeMessage) { |
| 340 | body := msg.GetBody() |
no test coverage detected