aboutsummaryrefslogtreecommitdiff
path: root/peer/messages.go
diff options
context:
space:
mode:
Diffstat (limited to 'peer/messages.go')
-rw-r--r--peer/messages.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/peer/messages.go b/peer/messages.go
index a14de46..a6f2815 100644
--- a/peer/messages.go
+++ b/peer/messages.go
@@ -1,5 +1,7 @@
package peer
+import "io"
+
type Message int
const (
@@ -17,3 +19,19 @@ const (
)
const Proto = `BitTorrent protocol`
+
+type Handshake struct {
+ Proto string
+ Flags [8]byte
+ InfoHash [20]byte
+ PeerID [20]byte
+}
+
+func (h Handshake) Encode(w io.Writer) {
+ l := len(h.Proto)
+ w.Write([]byte{byte(l)})
+ w.Write([]byte(h.Proto))
+ w.Write(h.Flags[:])
+ w.Write(h.InfoHash[:])
+ w.Write(h.PeerID[:])
+}