Exemplo n.º 1
0
func track(payload url.Values) {
	payload.Set("v", "1")
	payload.Set("tid", trackingID)
	payload.Set("cid", getClientId())
	payload.Set("aip", "1")

	req, err := http.NewRequest("HEAD", fmt.Sprintf(gaEndpoint, payload.Encode()), nil)
	if err != nil {
		return
	}
	req.Header.Set("User-Agent", util.UserAgent())
	httpClient.Do(req)
}
Exemplo n.º 2
0
func (s *BTService) configure() {
	settings := s.Session.Settings()

	s.log.Info("Setting Session settings...")

	settings.SetUser_agent(util.UserAgent())

	settings.SetRequest_timeout(2)
	settings.SetPeer_connect_timeout(2)
	settings.SetStrict_end_game_mode(true)
	settings.SetAnnounce_to_all_trackers(true)
	settings.SetAnnounce_to_all_tiers(true)
	settings.SetConnection_speed(500)

	if s.config.MaxDownloadRate > 0 {
		s.log.Info("Rate limiting download to %dkb/s", s.config.MaxDownloadRate/1024)
		settings.SetDownload_rate_limit(s.config.MaxDownloadRate)
	}
	if s.config.MaxUploadRate > 0 {
		s.log.Info("Rate limiting upload to %dkb/s", s.config.MaxUploadRate/1024)
		// If we have an upload rate, use the nicer bittyrant choker
		settings.SetChoking_algorithm(int(libtorrent.Session_settingsBittyrant_choker))
		settings.SetUpload_rate_limit(s.config.MaxUploadRate)
	}

	settings.SetPeer_tos(ipToSLowCost)
	settings.SetTorrent_connect_boost(500)
	settings.SetRate_limit_ip_overhead(true)
	settings.SetNo_atime_storage(true)
	settings.SetAnnounce_double_nat(true)
	settings.SetPrioritize_partial_pieces(false)
	settings.SetFree_torrent_hashes(true)
	settings.SetUse_parole_mode(true)

	// Make sure the disk cache is not swapped out (useful for slower devices)
	settings.SetLock_disk_cache(true)
	settings.SetDisk_cache_algorithm(libtorrent.Session_settingsLargest_contiguous)

	// Prioritize people starting downloads
	settings.SetSeed_choking_algorithm(int(libtorrent.Session_settingsFastest_upload))

	// copied from qBitorrent at
	// https://github.com/qbittorrent/qBittorrent/blob/master/src/qtlibtorrent/qbtsession.cpp
	settings.SetUpnp_ignore_nonrouters(true)
	settings.SetLazy_bitfields(true)
	settings.SetStop_tracker_timeout(1)
	settings.SetAuto_scrape_interval(1200)    // 20 minutes
	settings.SetAuto_scrape_min_interval(900) // 15 minutes
	settings.SetIgnore_limits_on_local_network(true)
	settings.SetRate_limit_utp(true)
	settings.SetMixed_mode_algorithm(int(libtorrent.Session_settingsPrefer_tcp))

	setPlatformSpecificSettings(settings)

	s.Session.Set_settings(settings)

	// Add all the libtorrent extensions
	s.Session.Add_extensions()

	s.log.Info("Setting Encryption settings...")
	encryptionSettings := libtorrent.NewPe_settings()
	defer libtorrent.DeletePe_settings(encryptionSettings)
	encryptionSettings.SetOut_enc_policy(byte(libtorrent.Pe_settingsForced))
	encryptionSettings.SetIn_enc_policy(byte(libtorrent.Pe_settingsForced))
	encryptionSettings.SetAllowed_enc_level(byte(libtorrent.Pe_settingsBoth))
	encryptionSettings.SetPrefer_rc4(true)
	s.Session.Set_pe_settings(encryptionSettings)

	if s.config.Proxy != nil {
		s.log.Info("Setting Proxy settings...")
		proxy := libtorrent.NewProxy_settings()
		defer libtorrent.DeleteProxy_settings(proxy)
		proxy.SetHostname(s.config.Proxy.Hostname)
		proxy.SetPort(uint16(s.config.Proxy.Port))
		proxy.SetUsername(s.config.Proxy.Username)
		proxy.SetPassword(s.config.Proxy.Password)
		proxy.SetXtype(byte(s.config.Proxy.Type))
		proxy.SetProxy_hostnames(true)
		proxy.SetProxy_peer_connections(true)
		s.Session.Set_proxy(proxy)
	}
}