Logger *zap.SugaredLogger
PrivateChats map[uint32]*PrivateChat
NextGuestID *uint16
- TrackerPassID []byte
+ TrackerPassID [4]byte
Stats *Stats
APIListener net.Listener
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))
}
// 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
}
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)
)
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 {
return concat.Slices(
[]byte{0x00, 0x01},
- tr.Port,
+ tr.Port[:],
userCount,
[]byte{0x00, 0x00},
tr.PassID,
func TestTrackerRegistration_Payload(t *testing.T) {
type fields struct {
- Port []byte
+ Port [2]byte
UserCount int
PassID []byte
Name string
{
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",