1
0
mirror of https://github.com/veggiedefender/torrent-client.git synced 2025-11-06 09:29:16 +02:00

Implement handshake.New()

This commit is contained in:
Jesse Li
2019-12-24 11:05:22 -05:00
parent c20965ebf5
commit 415666a020
3 changed files with 22 additions and 5 deletions

View File

@@ -12,6 +12,15 @@ type Handshake struct {
PeerID [20]byte
}
// New creates a new handshake with the standard pstr
func New(infoHash, peerID [20]byte) *Handshake {
return &Handshake{
Pstr: "BitTorrent protocol",
InfoHash: infoHash,
PeerID: peerID,
}
}
// Serialize serializes the handshake to a buffer
func (h *Handshake) Serialize() []byte {
pstrlen := len(h.Pstr)