Skip to content

Golang proxy selection using roulette-wheel selection via stochastic acceptance

License

Notifications You must be signed in to change notification settings

calvernaz/http-proxy-roulette

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Proxy Roulette

This is a toy example of an implementation of the roulette-wheel selection via stochastic acceptance in Golang and http.RoundTripper for proxy selection. In other words it selects a random proxy from a set in O(1) time but also adds a rank function for increase/decrease probability depending on the proxy state.

Example

roulette := &roundtripper.ProxyRoulette{
	Proxies: proxies,
	Step:    15,
}

rt := &roundtripper.ProxyRoundTripper{
	ProxySelector: roulette,
	Tr: &http.Transport{
		DialContext: (&net.Dialer{
			Timeout:   30 * time.Second,
			KeepAlive: 30 * time.Second,
		}).DialContext,
		TLSHandshakeTimeout: 10 * time.Second,
		DisableKeepAlives:   false,
		MaxIdleConnsPerHost: 1,
	},
}

var client = &http.Client{
	Transport: rt,
	Timeout:   30 * time.Second,
}

for i := 0; i < 50; i++ {
	req, _ := http.NewRequest("GET", "https://remote.site", nil)
	resp, err := client.Do(req)
	if err != nil {
		continue
	}

	if _, err := ioutil.ReadAll(resp.Body); err != nil {
		panic(err)
	}
}

About

Golang proxy selection using roulette-wheel selection via stochastic acceptance

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages