sendWireBytes() a rate limited writer of outbound bytes to the wire wraps a proto.Message into a universal Envelope, then converts to bytes and sends them across the wire without violating the data flow rate limits message may be a Packet, a Ping or a Pong
(message proto.Message, m *limiter.Monitor)
| 402 | // sends them across the wire without violating the data flow rate limits |
| 403 | // message may be a Packet, a Ping or a Pong |
| 404 | func (c *MultiConn) sendWireBytes(message proto.Message, m *limiter.Monitor) { |
| 405 | defer lib.TimeTrack(c.log, time.Now(), time.Second) |
| 406 | // convert the proto.Message into a proto.Any |
| 407 | a, err := lib.NewAny(message) |
| 408 | if err != nil { |
| 409 | c.Error(err) |
| 410 | } |
| 411 | // restrict the instantaneous data flow to rate bytes per second |
| 412 | // Limit() request maxPacketSize bytes from the limiter and the limiter |
| 413 | // will block the execution until at or below the desired rate of flow |
| 414 | m.Limit(int(maxPacketSize), int64(dataFlowRatePerS), true) |
| 415 | //defer lib.TimeTrack(c.log, time.Now()) |
| 416 | // send the proto message wrapped in an Envelope over the wire |
| 417 | lenM, err := sendProtoMsg(c.conn, &Envelope{Payload: a}) |
| 418 | if err != nil { |
| 419 | c.Error(err) |
| 420 | } |
| 421 | // update the rate limiter with how many bytes were written |
| 422 | m.Update(lenM) |
| 423 | } |
| 424 | |
| 425 | // PacketWithTiming wraps a Packet with timing information for metrics |
| 426 | type PacketWithTiming struct { |
no test coverage detected