()
| 358 | } |
| 359 | |
| 360 | func (n *Nylon) flushIO() error { |
| 361 | for _, neigh := range n.RouterState.Neighbours { |
| 362 | // TODO, investigate effect of packet loss on control messages |
| 363 | best := neigh.BestEndpoint() |
| 364 | nio := n.GetNeighIO(neigh.Id) |
| 365 | if nio == nil { |
| 366 | continue |
| 367 | } |
| 368 | if best != nil && best.IsActive() { |
| 369 | peer := n.Device.LookupPeer(device.NoisePublicKey(n.GetNode(neigh.Id).PubKey)) |
| 370 | for { |
| 371 | bundle := &protocol.TransportBundle{} |
| 372 | tLength := 0 |
| 373 | |
| 374 | // we can coalesce messages, but we need to make sure we don't fragment our UDP packet |
| 375 | // if a single proto message is somehow larger than SafeMTU, we still send it, but it will get fragmented |
| 376 | |
| 377 | for seqR, _ := range nio.SeqnoReq { |
| 378 | prefixBytes, _ := seqR.Prefix.MarshalBinary() |
| 379 | req := &protocol.Ny{Type: &protocol.Ny_SeqnoRequestOp{ |
| 380 | SeqnoRequestOp: &protocol.Ny_SeqnoRequest{ |
| 381 | RouterId: string(seqR.NodeId), |
| 382 | Prefix: prefixBytes, |
| 383 | Seqno: uint32(nio.SeqnoReq[seqR].V1), |
| 384 | HopCount: uint32(nio.SeqnoReq[seqR].V2), |
| 385 | }, |
| 386 | }} |
| 387 | if tLength != 0 && tLength+proto.Size(req) >= n.SafeMTU { |
| 388 | goto send |
| 389 | } |
| 390 | delete(nio.SeqnoReq, seqR) |
| 391 | bundle.Packets = append(bundle.Packets, req) |
| 392 | tLength += proto.Size(req) |
| 393 | } |
| 394 | |
| 395 | for id, update := range nio.Updates { |
| 396 | req := &protocol.Ny{Type: &protocol.Ny_RouteOp{ |
| 397 | RouteOp: update, |
| 398 | }} |
| 399 | if tLength != 0 && tLength+proto.Size(req) >= n.SafeMTU { |
| 400 | goto send |
| 401 | } |
| 402 | delete(nio.Updates, id) |
| 403 | bundle.Packets = append(bundle.Packets, req) |
| 404 | tLength += proto.Size(req) |
| 405 | } |
| 406 | |
| 407 | for prefix := range nio.Acks { |
| 408 | prefixBytes, _ := prefix.MarshalBinary() |
| 409 | req := &protocol.Ny{Type: &protocol.Ny_AckRetractOp{ |
| 410 | AckRetractOp: &protocol.Ny_AckRetract{ |
| 411 | Prefix: prefixBytes, |
| 412 | }, |
| 413 | }} |
| 414 | if tLength != 0 && tLength+proto.Size(req) >= n.SafeMTU { |
| 415 | goto send |
| 416 | } |
| 417 | delete(nio.Acks, prefix) |
no test coverage detected