]> git.r.bdr.sh - rbdr/mobius/commitdiff
Fix hardcoded port in tracker registration
authorJeff Halter <redacted>
Tue, 7 Jun 2022 23:00:29 +0000 (16:00 -0700)
committerJeff Halter <redacted>
Tue, 7 Jun 2022 23:00:29 +0000 (16:00 -0700)
hotline/server.go
hotline/tracker.go
hotline/tracker_test.go

index e6322e04193db80676a76f9e9623dde8e80a4c6c..d5da45808e546bfb0b440fe866978c327b6d9098 100644 (file)
@@ -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)
index 2fc6004bb3b09410ad984163c3a01bedda62ccbb..63fb279bf29dc53a89c63a7c5e22d2958d613ce3 100644 (file)
@@ -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,
index b90446274fa70f28ba6088b956c44f37392941e3..72d84ba882bf614486ec51d74572492606efd72d 100644 (file)
@@ -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",