MCPcopy
hub / github.com/canopy-network/canopy / sendWireBytes

Method sendWireBytes

p2p/conn.go:404–423  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

402// sends them across the wire without violating the data flow rate limits
403// message may be a Packet, a Ping or a Pong
404func (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
426type PacketWithTiming struct {

Callers 2

sendPacketWithTimingMethod · 0.95
sendPacketMethod · 0.95

Calls 4

ErrorMethod · 0.95
TimeTrackFunction · 0.92
NewAnyFunction · 0.92
sendProtoMsgFunction · 0.85

Tested by

no test coverage detected