MCPcopy
hub / github.com/hashicorp/memberlist / IngestPacket

Method IngestPacket

net_transport.go:214–241  ·  view source on GitHub ↗

See IngestionAwareTransport.

(conn net.Conn, addr net.Addr, now time.Time, shouldClose bool)

Source from the content-addressed store, hash-verified

212
213// See IngestionAwareTransport.
214func (t *NetTransport) IngestPacket(conn net.Conn, addr net.Addr, now time.Time, shouldClose bool) error {
215 if shouldClose {
216 defer func() {
217 _ = conn.Close()
218 }()
219 }
220
221 // Copy everything from the stream into packet buffer.
222 var buf bytes.Buffer
223 if _, err := io.Copy(&buf, conn); err != nil {
224 return fmt.Errorf("failed to read packet: %v", err)
225 }
226
227 // Check the length - it needs to have at least one byte to be a proper
228 // message. This is checked elsewhere for writes coming in directly from
229 // the UDP socket.
230 if n := buf.Len(); n < 1 {
231 return fmt.Errorf("packet too short (%d bytes) %s", n, LogAddress(addr))
232 }
233
234 // Inject the packet.
235 t.packetCh <- &Packet{
236 Buf: buf.Bytes(),
237 From: addr,
238 Timestamp: now,
239 }
240 return nil
241}
242
243// See Transport.
244func (t *NetTransport) DialTimeout(addr string, timeout time.Duration) (net.Conn, error) {

Callers

nothing calls this directly

Calls 3

LogAddressFunction · 0.85
ErrorfMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected