Skip to content

Commit 563a53f

Browse files
committed
handler.go: Actually check for DisableCookies field.
1 parent 9a29b7c commit 563a53f

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

conn.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func (conn *Conn) startTicking() {
149149
if before != 0 && acksLeft == 0 {
150150
conn.closeImmediately()
151151
}
152-
since := time.Since(time.Unix(unix, 0))
152+
since := t.Sub(time.Unix(unix, 0))
153153
if (acksLeft == 0 && since > time.Second) || since > time.Second*5 {
154154
conn.closeImmediately()
155155
}
@@ -342,7 +342,7 @@ func (conn *Conn) Latency() time.Duration {
342342
return time.Duration(conn.rtt.Load() / 2)
343343
}
344344

345-
// send encodes an encoding.BinaryMarshaler and sends it.
345+
// send encodes an encoding.BinaryMarshaler and writes it to the Conn.
346346
func (conn *Conn) send(pk encoding.BinaryMarshaler) error {
347347
b, _ := pk.MarshalBinary()
348348
_, err := conn.Write(b)

handler.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ func (h listenerConnectionHandler) close(conn *Conn) {
3737
// cookie calculates a cookie for the net.Addr passed. It is calculated as a
3838
// hash of the random cookie salt and the address.
3939
func (h listenerConnectionHandler) cookie(addr net.Addr) uint32 {
40+
if h.l.conf.DisableCookies {
41+
return 0
42+
}
4043
udp, _ := addr.(*net.UDPAddr)
4144
b := make([]byte, 6, 22)
4245
binary.LittleEndian.PutUint32(b, h.cookieSalt)
@@ -93,15 +96,15 @@ func (h listenerConnectionHandler) handleOpenConnectionRequest1(b []byte, addr n
9396
return fmt.Errorf("handle OPEN_CONNECTION_REQUEST_1: incompatible protocol version %v (listener protocol = %v)", pk.ClientProtocol, protocolVersion)
9497
}
9598

96-
data, _ := (&message.OpenConnectionReply1{ServerGUID: h.l.id, Cookie: h.cookie(addr), ServerHasSecurity: true, MTU: mtuSize}).MarshalBinary()
99+
data, _ := (&message.OpenConnectionReply1{ServerGUID: h.l.id, Cookie: h.cookie(addr), ServerHasSecurity: !h.l.conf.DisableCookies, MTU: mtuSize}).MarshalBinary()
97100
_, err := h.l.conn.WriteTo(data, addr)
98101
return err
99102
}
100103

101104
// handleOpenConnectionRequest2 handles an open connection request 2 packet
102105
// stored in buffer b, coming from an address.
103106
func (h listenerConnectionHandler) handleOpenConnectionRequest2(b []byte, addr net.Addr) error {
104-
pk := &message.OpenConnectionRequest2{ServerHasSecurity: true}
107+
pk := &message.OpenConnectionRequest2{ServerHasSecurity: !h.l.conf.DisableCookies}
105108
if err := pk.UnmarshalBinary(b); err != nil {
106109
return fmt.Errorf("read OPEN_CONNECTION_REQUEST_2: %w", err)
107110
}

0 commit comments

Comments
 (0)