Skip to content

Commit

Permalink
Merge pull request #466 from MortezaBashsiz/golang-fix
Browse files Browse the repository at this point in the history
fixed undefined type
  • Loading branch information
SonyaCore authored Apr 16, 2023
2 parents 425f52c + 7095be0 commit dd0de91
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
6 changes: 3 additions & 3 deletions golang/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
github.com/eiannone/keyboard v0.0.0-20220611211555-0d226195f203
github.com/spf13/cobra v1.6.1
github.com/spf13/cobra v1.7.0
github.com/xtls/xray-core v1.8.0
)

Expand All @@ -19,7 +19,7 @@ require (
github.com/google/btree v1.1.2 // indirect
github.com/google/pprof v0.0.0-20230228050547-1710fef4ab10 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/klauspost/compress v1.16.0 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/miekg/dns v1.1.51 // indirect
Expand All @@ -44,7 +44,7 @@ require (
golang.org/x/exp v0.0.0-20230307190834-24139beb5833 // indirect
golang.org/x/mod v0.9.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.7.0 // indirect
Expand Down
12 changes: 6 additions & 6 deletions golang/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWm
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
github.com/grpc-ecosystem/grpc-gateway v1.5.0/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw=
github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc=
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
Expand Down Expand Up @@ -175,8 +175,8 @@ github.com/shurcooL/users v0.0.0-20180125191416-49c67e49c537/go.mod h1:QJTqeLYED
github.com/shurcooL/webdavfs v0.0.0-20170829043945-18c3829fa133/go.mod h1:hKmq5kWdCj2z2KEozexVbfEZIWiTjhE0+UjmZgPqehw=
github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:UdhH50NIW0fCiwBSr0co2m7BnFLdv4fQTgdqdJTHFeE=
github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA=
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down Expand Up @@ -267,8 +267,8 @@ golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
Expand Down
22 changes: 9 additions & 13 deletions golang/scanner/scanner.go → golang/scanner/scan.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package scanner

import "C"
import (
config "CFScanner/configuration"
"CFScanner/logger"
"CFScanner/speedtest"
"CFScanner/utils"
"CFScanner/vpn"
"fmt"
"github.com/eiannone/keyboard"
"math"
"os"
"runtime"
"strconv"
"strings"
"sync"
"time"

"github.com/eiannone/keyboard"
)

var results [][]string
Expand All @@ -27,7 +27,7 @@ var (
uploadLatency float64
)

type Result struct {
type ScanResult struct {
IP string
Download struct {
Speed []float64
Expand All @@ -46,9 +46,9 @@ var (
)

// const WorkerCount = 48
func scanner(ip string, Config config.Configuration, Worker config.Worker) *Result {
func scanner(ip string, Config config.Configuration, Worker config.Worker) *ScanResult {

result := &Result{
result := &ScanResult{
IP: ip,
}

Expand All @@ -67,11 +67,7 @@ func scanner(ip string, Config config.Configuration, Worker config.Worker) *Resu
proxies = vpn.ProxyBind(listen, port)

// wait for port
waitPort := utils.WaitForPort(listen, port, time.Duration(5))

if waitPort != nil {
fmt.Errorf(waitPort.Error())
}
utils.WaitForPort(listen, port, time.Duration(5))

var err error
process = vpn.XRayInstance(xrayConfigPath)
Expand Down Expand Up @@ -142,7 +138,7 @@ func scanner(ip string, Config config.Configuration, Worker config.Worker) *Resu
return result
}

func uploader(ip string, Upload *config.Upload, proxies map[string]string, result *Result) (*Result, bool) {
func uploader(ip string, Upload *config.Upload, proxies map[string]string, result *ScanResult) (*ScanResult, bool) {
var err error
nBytes := Upload.MinUlSpeed * 1000 * Upload.MaxUlTime
uploadSpeed, uploadLatency, err = speedtest.UploadSpeedTest(int(nBytes), proxies,
Expand Down Expand Up @@ -188,7 +184,7 @@ func uploader(ip string, Upload *config.Upload, proxies map[string]string, resul
return nil, false
}

func downloader(ip string, Download *config.Download, proxies map[string]string, result *Result) (*Result, bool) {
func downloader(ip string, Download *config.Download, proxies map[string]string, result *ScanResult) (*ScanResult, bool) {
nBytes := Download.MinDlSpeed * 1000 * Download.MaxDlTime
var err error

Expand Down Expand Up @@ -312,7 +308,7 @@ func scan(Config *config.Configuration, worker *config.Worker, ip string) {
MeanUploadLatency: meanUploadLatency,
}
default:
cause := fmt.Errorf("Invalid writer type: %s\n", Config.Config.Writer)
cause := fmt.Errorf("invalid writer type: %s", Config.Config.Writer)
ld := logger.ScannerManage{
IP: "",
Status: logger.ErrorStatus,
Expand Down
4 changes: 2 additions & 2 deletions golang/scanner/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type Writer interface {
}

type CSV struct {
res *Result
res *ScanResult
IP string
DownloadMeanJitter float64
UploadMeanJitter float64
Expand All @@ -17,7 +17,7 @@ type CSV struct {
}

type JSON struct {
res *Result
res *ScanResult
IP string `json:"ip"`
DownloadMeanJitter float64 `json:"downloadMeanJitter"`
UploadMeanJitter float64 `json:"uploadMeanJitter"`
Expand Down

0 comments on commit dd0de91

Please sign in to comment.