Exemplo n.º 1
0
Arquivo: main.go Projeto: jbitor/cli
func main() {
	loggerconfig.Use()

	if len(os.Args) != 2 {
		logger.Fatalf("Usage: %v INFOHASH < INFOHASH.peers", 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
	}

	peers := make([]net.TCPAddr, 0)
	dec := json.NewDecoder(os.Stdin)
	dec.Decode(&peers)
	logger.Info("Loaded peers: %v", peers)

	client := bittorrent.OpenClient()
	swarm := client.Swarm(infoHash)

	for _, peer := range peers {
		swarm.AddPeer(peer)
	}

	logger.Info("getting info")
	info := swarm.Info()
	logger.Info("got info: %v", info)

	torrentFileData, err := bencoding.Encode(bencoding.Dict{
		"info":          info,
		"announce-list": bencoding.List{},
		"nodes":         bencoding.List{},
	})
	if err != nil {
		logger.Fatalf("error encoding torrent file: %v:", err)
	}

	os.Stdout.Write(torrentFileData)
}
Exemplo n.º 2
0
Arquivo: main.go Projeto: jbitor/cli
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)
	}
}