// EncodeResponse groups all of the peer-requested data into a nice bencoded
// string that we respond with.
func EncodeResponse(ipport []string, data *AnnounceData) (resp string) {
	ret := ""
	completeCount := len(redisPeerStore.GetKeyVal(nil, data.InfoHash))
	incompleteCount := len(redisPeerStore.GetKeyVal(nil, data.InfoHash))
	ret += bencode.EncodeKV("complete", bencode.EncodeInt(completeCount))

	ret += bencode.EncodeKV("incomplete", bencode.EncodeInt(incompleteCount))
	if data.Compact || !data.Compact {
		ipstr := string(CompactAllPeers(ipport))
		ret += bencode.EncodeKV("peers", ipstr)
	} else {
		return bencode.EncodePeerList(ipport)
	}

	return fmt.Sprintf("d%se", ret)
}
func formatScrapeResponse(torrent *schemas.Torrent) string {
	subdir := fmt.Sprintf("d%s%s%s%s%s%se",
		bencode.EncodeByteString("complete"),
		bencode.EncodeInt(int(torrent.Seeders)),

		bencode.EncodeByteString("downloaded"),
		bencode.EncodeInt(int(torrent.Downloaded)),

		bencode.EncodeByteString("incomplete"),
		bencode.EncodeInt(int(torrent.Leechers)),
	)

	fileList := bencode.EncodeKV(
		bencode.EncodeByteString(torrent.InfoHash),
		subdir,
	)

	return fmt.Sprintf("d%se", fileList)
}
func createFailureMessage(msg string) string {
	return fmt.Sprintf("d%se", bencode.EncodeKV("failure reason", msg))
}