parent
404e7f5821
commit
5866d96cb0
2 changed files with 8 additions and 2 deletions
|
@ -128,10 +128,15 @@ func (t *Frontend) ListenAndServe() error {
|
|||
defer t.wg.Done()
|
||||
defer pool.Put(buffer)
|
||||
|
||||
if ip := addr.IP.To4(); ip != nil {
|
||||
addr.IP = ip
|
||||
}
|
||||
|
||||
// Handle the request.
|
||||
start := time.Now()
|
||||
action, err := t.handleRequest(
|
||||
Request{buffer[:n], addr.IP},
|
||||
// Make sure the IP is copied, not referenced.
|
||||
Request{buffer[:n], append([]byte{}, addr.IP...)},
|
||||
ResponseWriter{t.socket, addr},
|
||||
)
|
||||
recordResponseDuration(action, err, time.Since(start))
|
||||
|
|
|
@ -80,7 +80,8 @@ func ParseAnnounce(r Request, allowIPSpoofing, v6 bool) (*bittorrent.AnnounceReq
|
|||
ip := r.IP
|
||||
ipbytes := r.Packet[84:ipEnd]
|
||||
if allowIPSpoofing {
|
||||
ip = net.IP(ipbytes)
|
||||
// Make sure the bytes are copied to a new slice.
|
||||
copy(ip, net.IP(ipbytes))
|
||||
}
|
||||
if !allowIPSpoofing && r.IP == nil {
|
||||
// We have no IP address to fallback on.
|
||||
|
|
Loading…
Reference in a new issue