1
0
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:
Jesse Li
2020-01-02 12:26:54 -05:00
parent b3ee9f4117
commit b3beb5ed2a

View File

@@ -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
}