(fourByteBuf []byte)
| 567 | } |
| 568 | |
| 569 | func (c *rawConnection) readHeader(fourByteBuf []byte) (*bep.Header, error) { |
| 570 | // First comes a 2 byte header length |
| 571 | |
| 572 | if _, err := io.ReadFull(c.cr, fourByteBuf[:2]); err != nil { |
| 573 | return nil, fmt.Errorf("reading length: %w", err) |
| 574 | } |
| 575 | hdrLen := int16(binary.BigEndian.Uint16(fourByteBuf)) |
| 576 | if hdrLen < 0 { |
| 577 | return nil, fmt.Errorf("negative header length %d", hdrLen) |
| 578 | } |
| 579 | |
| 580 | // Then comes the header |
| 581 | |
| 582 | buf := BufferPool.Get(int(hdrLen)) |
| 583 | defer BufferPool.Put(buf) |
| 584 | |
| 585 | if _, err := io.ReadFull(c.cr, buf); err != nil { |
| 586 | return nil, fmt.Errorf("reading header: %w", err) |
| 587 | } |
| 588 | |
| 589 | var hdr bep.Header |
| 590 | err := proto.Unmarshal(buf, &hdr) |
| 591 | if err != nil { |
| 592 | return nil, fmt.Errorf("unmarshalling header: %w", err) |
| 593 | } |
| 594 | |
| 595 | metricDeviceRecvDecompressedBytes.WithLabelValues(c.idString).Add(float64(2 + len(buf))) |
| 596 | |
| 597 | return &hdr, nil |
| 598 | } |
| 599 | |
| 600 | func (c *rawConnection) handleIndex(im *Index) error { |
| 601 | l.Debugf("Index(%v, %v, %d file)", c.deviceID, im.Folder, len(im.Files)) |
no test coverage detected