func (h *HandShake) write(conn io.Writer) error {
	var b bytes.Buffer
	if err := writeBinary(&b, protoLen, proto, h); err != nil {
		panic(err)
	}
	_, err := conn.Write(b.Bytes())
	if err != nil {
		return fmt.Errorf("write: %s", err)
	}
	return nil
}
write sends write the bytes of h to conn.
package peer_wire
import (
	"bytes"
	"encoding/binary"
	"errors"
	"fmt"
	"io"
)
const protoLen byte = 19
var proto = [...]byte{
	'B', 'i', 't', 'T', 'o', 'r', 'r', 'e', 'n', 't',
	' ', 'p', 'r', 'o', 't', 'o', 'c', 'o', 'l',
}
type HandShake struct {
	Reserved Reserved
	InfoHash [20]byte
	PeerID   [20]byte
}
func (h *HandShake) Do(rw io.ReadWriter) (*HandShake, error) {
	switch {
	case h.InfoHash != [20]byte{}:
		return h.initiate(rw)
	default:
		return h.receipt(rw)
	}
}
func (h *HandShake) initiate(rw io.ReadWriter) (*HandShake, error) {
	var err error
	if err = h.write(rw); err != nil {
		return nil, fmt.Errorf("hs initiate: %s", err)
	}
	var _h *HandShake
	if _h, err = readHs(rw); err != nil {
		return nil, fmt.Errorf("hs initiate: %s", err)
	}
	if h.InfoHash != _h.InfoHash {
		return nil, fmt.Errorf("hs initiate:info_hash response of peer  doesn't match the client's")
	}
	return _h, nil
}
func (h *HandShake) receipt(rw io.ReadWriter) (*HandShake, error) {
	var err error
	var _h *HandShake
	if _h, err = readHsWithoutPeerID(rw); err != nil {
		return nil, fmt.Errorf("hs receipt: %s", err)
	}
	h.InfoHash = _h.InfoHash
	if err = h.write(rw); err != nil {
		return nil, fmt.Errorf("hs receipt: %s", err)
	}
	if err = _h.readPeerID(rw); err != nil {
		return nil, err
	}
	return _h, nil
}