Skip to content

Commit

Permalink
Merge pull request #13 from Kuucheen/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Kuucheen committed Apr 3, 2024
2 parents d936400 + ae9b728 commit b8d523f
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 16 deletions.
6 changes: 3 additions & 3 deletions charm/threadPhase/displayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ var (

func RunBars() {
items := []list.Item{
item{"ip:port", ""},
item{title: "type://ip:port", desc: ""},
item{title: "ip:port"},
item{title: "type://ip:port"},
item{title: "ip:port;ms"},
}

m := model{
Expand Down Expand Up @@ -104,7 +105,6 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if msg.String() == "q" {
threadPhase = false
helper.StopThreads()

}
} else {
switch msg.String() {
Expand Down
18 changes: 9 additions & 9 deletions helper/CheckerHelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ func GetProxyLevel(html string) int {

}

func Request(proxy *Proxy) (string, int) {
func Request(proxy *Proxy) (string, int, error) {
return RequestCustom(proxy, common.FastestJudge)
}

// RequestCustom makes a request to the provided siteUrl with the provided proxy
func RequestCustom(proxy *Proxy, siteUrl string) (string, int) {
func RequestCustom(proxy *Proxy, siteUrl string) (string, int, error) {
//Errors would destroy the whole display while checking
log.SetOutput(io.Discard)

proxyURL, err := url.Parse(GetTypeName() + "://" + proxy.Full)
if err != nil {
return "Error parsing proxy URL", -1
return "Error parsing proxy URL", -1, err
}

var transport *http.Transport
Expand All @@ -56,7 +56,7 @@ func RequestCustom(proxy *Proxy, siteUrl string) (string, int) {
//udp doesn't work for some reason
dialer, err := proxy2.SOCKS5("tcp", proxy.Full, nil, proxy2.Direct)
if err != nil {
return "Error creating SOCKS dialer", -1
return "Error creating SOCKS dialer", -1, err
}
transport = &http.Transport{
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
Expand All @@ -72,27 +72,27 @@ func RequestCustom(proxy *Proxy, siteUrl string) (string, int) {

req, err := http.NewRequest("GET", siteUrl, nil)
if err != nil {
return "Error creating HTTP request", -1
return "Error creating HTTP request", -1, err
}

req.Header.Set("Connection", "close")

resp, err := client.Do(req)
if err != nil {
return "Error making HTTP request", -1
return "Error making HTTP request", -1, err
}

status := resp.StatusCode

resBody, err := io.ReadAll(resp.Body)
if err != nil {
return "Error reading response body", -1
return "Error reading response body", -1, err
}

err = resp.Body.Close()
if err != nil {
return "Error closing Body", -1
return "Error closing Body", -1, err
}

return string(resBody), status
return string(resBody), status, nil
}
9 changes: 9 additions & 0 deletions helper/FileHelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"regexp"
"sort"
)

var ProxySum float64
Expand All @@ -12,6 +13,11 @@ func Write(proxies map[int][]*Proxy, style int, banCheck bool) string {
pType := GetTypeName()

for _, proxyLevel := range proxies {

sort.Slice(proxyLevel, func(i, j int) bool {
return proxyLevel[i].time < proxyLevel[j].time
})

filtered := ""

if banCheck {
Expand All @@ -29,6 +35,9 @@ func Write(proxies map[int][]*Proxy, style int, banCheck bool) string {
proxyString = proxy.Full
case 1:
proxyString = fmt.Sprintf("%s://%s", pType, proxy.Full)

case 2:
proxyString = fmt.Sprintf("%s;%d", proxy.Full, proxy.time)
}

_, err := fmt.Fprintln(f, proxyString)
Expand Down
1 change: 1 addition & 0 deletions helper/ProxyHelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Proxy struct {
Full string
Level int
checks int
time int //in ms
}

var (
Expand Down
21 changes: 17 additions & 4 deletions helper/threadHelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
var (
proxyQueue = ProxyQueue{}
ProxyMap = make(map[int][]*Proxy)
ProxyMapFiltered = make(map[int][]*Proxy)
ProxyMapFiltered = make(map[int][]*Proxy) //ProxyMapFiltered is for Banchecked proxies
ProxyCountMap = make(map[int]int)
stop = false
Invalid int32
Expand Down Expand Up @@ -94,7 +94,16 @@ func check(proxy *Proxy) {
cpmCounter.mu.Unlock()

for proxy.checks <= retries {
body, status := Request(proxy)

timeStart := time.Now()
body, status, err := Request(proxy)
timeEnd := time.Now()

proxy.time = int(timeEnd.Sub(timeStart).Milliseconds())

if err != nil {
status = -1
}

if status >= 400 || status == -1 {
proxy.checks++
Expand All @@ -121,10 +130,14 @@ func check(proxy *Proxy) {

//Ban check for websites
if responded {
//Extra if because of performance
//Extra if because of performance (else)
if common.DoBanCheck() {
for i := 0; i < retries; i++ {
body, status := RequestCustom(proxy, common.GetConfig().Bancheck)
body, status, err := RequestCustom(proxy, common.GetConfig().Bancheck)

if err != nil {
status = -1
}

if !(status >= 400) && status != -1 {
keywords := common.GetConfig().Keywords
Expand Down

0 comments on commit b8d523f

Please sign in to comment.