func main() { loggerconfig.Use() if len(os.Args) != 2 { logger.Fatalf("Usage: %v INFOHASH", os.Args[0]) return } weakrand.Seed(time.Now().UTC().UnixNano()) infoHash, err := bittorrent.BTIDFromHex(os.Args[1]) if err != nil { logger.Fatalf("Specified string was not a valid hex infohash [%v].", err) return } dhtClient, err := dht.OpenClient(".dht-peer", true) if err != nil { logger.Fatalf("Unable to open .dht-peer: %v", err) return } defer dhtClient.Close() search := dhtClient.GetPeers(infoHash) peers, err := search.AllPeers() if err != nil { logger.Fatalf("Unable to find peers: %v", err) } logger.Info("Found peers for %v:", infoHash) peerData, err := json.Marshal(peers) if err != nil { logger.Fatalf("?!?: %v", err) } os.Stdout.Write(peerData) }
func main() { loggerconfig.Use() if len(os.Args) == 0 { logger.Fatalf("Usage: %v", os.Args[0]) return } weakrand.Seed(time.Now().UTC().UnixNano()) dc, err := dht.OpenClient(".dht-peer", false) if err != nil { logger.Fatalf("Unable to open DHT client: %v", err) return } bc := bittorrent.OpenClient() wc, err := webclient.New(dc, bc) if err != nil { logger.Fatalf("Unable to create web interface: %v", err) return } err = wc.ListenAndServe() if err != nil { logger.Fatalf("Unable to serve web interface: %v", err) return } defer dc.Close() for { time.Sleep(60 * time.Second) } }