aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2022-06-07 16:00:29 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2022-06-07 16:00:29 -0700
commit40414f9295dd301f1c714bc3067392b7cc8f8427 (patch)
treef692f32a666eab5ea9f42a8b3aa0ad0cd22be6bb
parent041c2df698d4702816cf8472d212553d289a2c0c (diff)
Fix hardcoded port in tracker registration
-rw-r--r--hotline/server.go9
-rw-r--r--hotline/tracker.go12
-rw-r--r--hotline/tracker_test.go4
3 files changed, 12 insertions, 13 deletions
diff --git a/hotline/server.go b/hotline/server.go
index e6322e0..d5da458 100644
--- a/hotline/server.go
+++ b/hotline/server.go
@@ -44,7 +44,7 @@ type Server struct {
Logger *zap.SugaredLogger
PrivateChats map[uint32]*PrivateChat
NextGuestID *uint16
- TrackerPassID []byte
+ TrackerPassID [4]byte
Stats *Stats
APIListener net.Listener
@@ -187,7 +187,6 @@ func NewServer(configDir, netInterface string, netPort int, logger *zap.SugaredL
outbox: make(chan Transaction),
Stats: &Stats{StartTime: time.Now()},
ThreadedNews: &ThreadedNews{},
- TrackerPassID: make([]byte, 4),
}
ln, err := net.Listen("tcp", fmt.Sprintf("%s:%v", netInterface, netPort))
@@ -207,7 +206,7 @@ func NewServer(configDir, netInterface string, netPort int, logger *zap.SugaredL
}
// generate a new random passID for tracker registration
- if _, err := rand.Read(server.TrackerPassID); err != nil {
+ if _, err := rand.Read(server.TrackerPassID[:]); err != nil {
return nil, err
}
@@ -246,12 +245,12 @@ func NewServer(configDir, netInterface string, netPort int, logger *zap.SugaredL
go func() {
for {
tr := &TrackerRegistration{
- Port: []byte{0x15, 0x7c},
UserCount: server.userCount(),
- PassID: server.TrackerPassID,
+ PassID: server.TrackerPassID[:],
Name: server.Config.Name,
Description: server.Config.Description,
}
+ binary.BigEndian.PutUint16(tr.Port[:], uint16(server.Port))
for _, t := range server.Config.Trackers {
if err := register(t, tr); err != nil {
server.Logger.Errorw("unable to register with tracker %v", "error", err)
diff --git a/hotline/tracker.go b/hotline/tracker.go
index 2fc6004..63fb279 100644
--- a/hotline/tracker.go
+++ b/hotline/tracker.go
@@ -12,11 +12,11 @@ import (
)
type TrackerRegistration struct {
- Port []byte // Server listening port number
- UserCount int // Number of users connected to this particular server
- PassID []byte // Random number generated by the server
- Name string // Server name
- Description string // Description of the server
+ Port [2]byte // Server listening port number
+ UserCount int // Number of users connected to this particular server
+ PassID []byte // Random number generated by the server
+ Name string // Server name
+ Description string // Description of the server
}
func (tr *TrackerRegistration) Payload() []byte {
@@ -25,7 +25,7 @@ func (tr *TrackerRegistration) Payload() []byte {
return concat.Slices(
[]byte{0x00, 0x01},
- tr.Port,
+ tr.Port[:],
userCount,
[]byte{0x00, 0x00},
tr.PassID,
diff --git a/hotline/tracker_test.go b/hotline/tracker_test.go
index b904462..72d84ba 100644
--- a/hotline/tracker_test.go
+++ b/hotline/tracker_test.go
@@ -7,7 +7,7 @@ import (
func TestTrackerRegistration_Payload(t *testing.T) {
type fields struct {
- Port []byte
+ Port [2]byte
UserCount int
PassID []byte
Name string
@@ -21,7 +21,7 @@ func TestTrackerRegistration_Payload(t *testing.T) {
{
name: "returns expected payload bytes",
fields: fields{
- Port: []byte{0x00, 0x10},
+ Port: [2]byte{0x00, 0x10},
UserCount: 2,
PassID: []byte{0x00, 0x00, 0x00, 0x01},
Name: "Test Serv",