Skip to content

Instantly share code, notes, and snippets.

@bemasher
Created June 23, 2011 06:18
Show Gist options
  • Save bemasher/1042014 to your computer and use it in GitHub Desktop.
Save bemasher/1042014 to your computer and use it in GitHub Desktop.
The beginning to a bittorrent tracker implemented in Google's Go.
package main
import (
"http"
"io"
"log"
)
func AnnounceHandler(w http.ResponseWriter, req *http.Request) {
req.ParseForm()
// map[
// info_hash: [n¯¬3«ú¡Úô¶oëß]
// peer_id: [-UT3000->c-,Æ|yÔ]
// port: [53352]
// uploaded: [0]
// downloaded: [0]
// left: [106755969]
// compact: [1]
// no_peer_id: [1]
// event: [started]
// key: [3AD1F624]
// numwant: [200]
// corrupt: [0]
// ]
// info_hash := []byte(req.FormValue("info_hash"))
log.Println(req.Form)
io.WriteString(w, req.UserAgent)
}
func main() {
log.SetFlags(log.Lshortfile)
http.HandleFunc("/announce", AnnounceHandler)
err := http.ListenAndServe(":8000", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err.String())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment