You've already forked torrent-client
mirror of
https://github.com/veggiedefender/torrent-client.git
synced 2025-11-06 09:29:16 +02:00
Check infohash in handshake
This commit is contained in:
@@ -2,6 +2,7 @@ package p2p
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net"
|
||||
"strconv"
|
||||
@@ -39,6 +40,9 @@ func completeHandshake(conn net.Conn, r *bufio.Reader, infohash, peerID [20]byte
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !bytes.Equal(res.InfoHash[:], infohash[:]) {
|
||||
return nil, fmt.Errorf("Expected infohash %x but got %x", res.InfoHash, infohash)
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user