Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

阿里云上接受不到数据, 通过日志分析绝大多数错误是decode #41

Open
ghost opened this issue Mar 27, 2018 · 0 comments

Comments

@ghost
Copy link

ghost commented Mar 27, 2018

我在krpc.go里添加了一些日志

func handle(dht *DHT, pkt packet) {
	if len(dht.workerTokens) == dht.PacketWorkerLimit {

		fmt.Println("return from len(dht.workerTokens) == dht.PacketWorkerLimit")
		return
	}

	dht.workerTokens <- struct{}{}

	go func() {
		defer func() {
			<-dht.workerTokens
		}()

		if dht.blackList.in(pkt.raddr.IP.String(), pkt.raddr.Port) {

			fmt.Println("return from dht.blackList.in(pkt.raddr.IP.String(), pkt.raddr.Port)")
			return
		}

		data, err := Decode(pkt.data)
		if err != nil {

			fmt.Print("return from data, err := Decode(pkt.data)")
			fmt.Println(err)
			return
		}

		response, err := parseMessage(data)
		if err != nil {

			fmt.Print("return from response, err := parseMessage(data)")
			fmt.Println(err)
			return
		}

		if f, ok := handlers[response["y"].(string)]; ok {
			f(dht, pkt.raddr, response)
		}
	}()
}

然后用如下命令进行日志过滤


grep "Got a response" nohup_dht.logs | wc -l
grep "return from data, err := Decode(pkt.data)" nohup_dht.logs | wc -l
grep "return from response, err := parseMessage(data)" nohup_dht.logs | wc -l
grep "return from dht.blackList.in(pkt.raddr.IP.String(), pkt.raddr.Port)" nohup_dht.logs| wc -l  

得到结果如下

0
620
10
22

运行了俩分钟绝大多数都是decode error

return from data, err := Decode(pkt.data)invalid bencode when decode item

一条有用的数据都没拿到.

请问是解码有问题吗?

PS, 是通过在mac上编译出的linux版本, 编译命令

CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/exec_linux_dht src/main/main.go

centos版本

NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

mac上go env信息

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/xxx/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/xxx/godht:/usr/local/go/bin"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.10/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.10/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/_b/_xrkt7216glfsz7z989ss7zm0000gn/T/go-build666755492=/tmp/go-build -gno-record-gcc-switches -fno-common"
@ghost ghost changed the title 阿里云上接受不到数据, 请分析一下我打印的日志 阿里云上接受不到数据, 通过日志分析绝大多数错误是decode Mar 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants