예제 #1
0
// Download and add the blocklist.
func (c *Client) addBlocklist() {
	if c.Client.IPBlockList() != nil {
		log.Printf("Found blocklist")
		return
	}

	var err error
	blocklistPath := c.Client.ConfigDir() + "/blocklist"

	// Download blocklist.
	log.Printf("Downloading blocklist")
	fileName, err := downloadFile(torrentBlockListURL)
	if err != nil {
		log.Printf("Error downloading blocklist: %s\n", err)
		return
	}

	// Ungzip file.
	in, err := os.Open(fileName)
	if err != nil {
		log.Printf("Error extracting blocklist: %s\n", err)
		return
	}
	defer func() {
		if err := in.Close(); err != nil {
			log.Printf("Error closing the blocklist gzip file: %s", err)
		}
	}()
	reader, err := gzip.NewReader(in)

	// Write to {configdir}/blocklist
	out, err := os.Create(blocklistPath)
	if err != nil {
		log.Printf("Error writing blocklist: %s\n", err)
		return
	}
	defer func() {
		if err := out.Close(); err != nil {
			log.Printf("Error writing the blocklist file: %s", err)
		}
	}()
	_, err = io.Copy(out, reader)
	if err != nil {
		log.Printf("Error writing the blocklist file: %s", err)
		return
	}

	// Add to the blocklist.
	blocklistReader, err := os.Open(blocklistPath)
	blocklist, err := iplist.NewFromReader(blocklistReader)
	if err != nil {
		log.Printf("Error reading blocklist: %s", err)
		return
	}
	log.Printf("Setting blocklist.\nFound %d ranges\n", blocklist.NumRanges())
	c.Client.SetIPBlockList(blocklist)
}
예제 #2
0
파일: main.go 프로젝트: jakop345/torrent
func main() {
	tagflag.Parse(nil)
	l, err := iplist.NewFromReader(os.Stdin)
	if err != nil {
		missinggo.Fatal(err)
	}
	wb := bufio.NewWriter(os.Stdout)
	defer wb.Flush()
	err = l.WritePacked(wb)
	if err != nil {
		missinggo.Fatal(err)
	}
}
예제 #3
0
// Download and add the blocklist.
func (c *Client) addBlocklist() {
	var err error
	blocklistPath := os.TempDir() + "/go-peerflix-blocklist.gz"

	if _, err = os.Stat(blocklistPath); os.IsNotExist(err) {
		err = downloadBlockList(blocklistPath)
	}

	if err != nil {
		log.Printf("Error downloading blocklist: %s", err)
		return
	}

	// Load blocklist.
	blocklistReader, err := os.Open(blocklistPath)
	if err != nil {
		log.Printf("Error opening blocklist: %s", err)
		return
	}

	// Extract file.
	gzipReader, err := gzip.NewReader(blocklistReader)
	if err != nil {
		log.Printf("Error extracting blocklist: %s", err)
		return
	}

	// Read as iplist.
	blocklist, err := iplist.NewFromReader(gzipReader)
	if err != nil {
		log.Printf("Error reading blocklist: %s", err)
		return
	}

	log.Printf("Setting blocklist.\nFound %d ranges\n", blocklist.NumRanges())
	c.Client.SetIPBlockList(blocklist)
}