aboutsummaryrefslogtreecommitdiff
path: root/hotline/tracker.go
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2024-06-17 13:50:28 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2024-06-17 13:50:28 -0700
commit45ca5d60383cbe270624c713b916da29af7ba88f (patch)
treea6f8b9ecf24837e8588390ae5bdf5fdef711fed9 /hotline/tracker.go
parent5954ccad9c87063231f3a8bb3e5d01675a9865ca (diff)
Fix io.Reader implementations and wrap more errors
Diffstat (limited to 'hotline/tracker.go')
-rw-r--r--hotline/tracker.go15
1 files changed, 13 insertions, 2 deletions
diff --git a/hotline/tracker.go b/hotline/tracker.go
index 6ee2a9f..8f8ddd1 100644
--- a/hotline/tracker.go
+++ b/hotline/tracker.go
@@ -18,6 +18,8 @@ type TrackerRegistration struct {
PassID [4]byte // Random number generated by the server
Name string // Server Name
Description string // Description of the server
+
+ readOffset int // Internal offset to track read progress
}
// Read implements io.Reader to write tracker registration payload bytes to slice
@@ -25,7 +27,7 @@ func (tr *TrackerRegistration) Read(p []byte) (int, error) {
userCount := make([]byte, 2)
binary.BigEndian.PutUint16(userCount, uint16(tr.UserCount))
- return copy(p, slices.Concat(
+ buf := slices.Concat(
[]byte{0x00, 0x01}, // Magic number, always 1
tr.Port[:],
userCount,
@@ -35,7 +37,16 @@ func (tr *TrackerRegistration) Read(p []byte) (int, error) {
[]byte(tr.Name),
[]byte{uint8(len(tr.Description))},
[]byte(tr.Description),
- )[:]), io.EOF
+ )
+
+ if tr.readOffset >= len(buf) {
+ return 0, io.EOF // All bytes have been read
+ }
+
+ n := copy(p, buf[tr.readOffset:])
+ tr.readOffset += n
+
+ return n, nil
}
func register(tracker string, tr *TrackerRegistration) error {