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

go-mips32 交叉编译go程序 编译kcptun例子 #79

Closed
hiboyhiboy opened this Issue Jul 30, 2016 · 18 comments

Comments

Projects
None yet
10 participants
@hiboyhiboy

hiboyhiboy commented Jul 30, 2016

# 一、交叉编译环境配置

来源网友博文: 极路由1s(mt7620a)OpenWrt交叉编译go程序

// 下载go-mips32源
git clone https://github.com/gomini/go-mips32.git
cd go-mips32/src

// 配置GO编译参数
export GOOS=linux
export GOARCH=mips32le

// 执行编译

./make.bash
cd ..

// 创建编译后文件存放文件夹
sudo mkdir /opt/mipsgo

// 复制
sudo cp -R * /opt/mipsgo

// 如果第一步无报错完成后再继续下一步操作,如果出现问题请Google修复,或更换系统,我用ubuntukylin-15.10编译成功。

# 二、编译kcptun

源码来源:https://github.com/xtaci/kcptun

// 创建程序目录
mkdir /opt/kcptun
cd /opt/kcptun

// go工程参数配置
export GOPATH=/opt/mipsgo/src/gocode
export GOOS=linux
export GOARCH=mips32le
export GOROOT=/opt/mipsgo
export PATH=/opt/mipsgo/bin:$PATH

// 提前下载kcptun的依赖库
go get -v golang.org/x/crypto/pbkdf2
go get -v github.com/xtaci/kcp-go
go get -v github.com/urfave/cli
go get -v github.com/hashicorp/yamux
go get -v github.com/golang/snappy
go get -v golang.org/x/net/ipv4

// 由于依赖库没mips32le,需要填坑
// go get -v golang.org/x/net/ipv4
// 运行以上命令时会提示报错:/golang.org/x/net/ipv4/icmp.go:34:2: error: use of undefined type 'sysICMPFilter'
// 参考补丁填坑:https://bugzilla.redhat.com/attachment.cgi?id=1147705&action=diff
// 填坑步骤:gen.go里面添加mips32le的判断。复制一个zsys_linux_mips64le.go文件,改名zsys_linux_mips32le.go
// zsys_linux_mips32.go和zsys_linux_mips32le.go文件里面的64字符也要修改。
// +build linux,mips32
// +build linux,mips32le

// 填坑完成后再运行一次:
go get -v golang.org/x/net/ipv4

// 下载kcptun
go get -v github.com/xtaci/kcptun/client
go get -v github.com/xtaci/kcptun/server

// 编译
VERSION=date -u +%Y%m%d
LDFLAGS="-X main.VERSION=$VERSION -s -w"
env CGO_ENABLED=0 GOOS=linux GOARCH=mips32le go build -ldflags "$LDFLAGS" -o client_linux_mips github.com/xtaci/kcptun/client
env CGO_ENABLED=0 GOOS=linux GOARCH=mips32le go build -ldflags "$LDFLAGS" -o server_linux_mips github.com/xtaci/kcptun/server

// 几秒后出现程序文件,编译成功。我们路由只需要用client。
// 毕竟路由不做server,server主程序要去github下载或参考以上步骤,改export GOARCH=amd64就能自己编译amd64版本。

# 三、部署服务

// kcptun服务端部署教程
// https://blog.kuoruan.com/102.html
// http://www.cmsky.com/kcptun/

// 服务器:
./server_linux_amd64 -t "服务器IP地址:8388" -l ":554" -key hiboy -mtu 1400 -sndwnd 2048 -rcvwnd 2048 --crypt none --mode fast2 --nocomp // 转发到服务器的本地8388端口
// crypt:xor/none都不算加密,通过参数 -nocomp 在两端同时设定以关闭压缩。key可以自定义

// kcptun配置客户端参考

// 客户端:
./client_linux_mips -r "服务器IP地址:554" -l ":8388" -key hiboy -mtu 1400 -sndwnd 256 -rcvwnd 2048 --crypt none --mode fast2 --nocomp -dscp 46 // 监听客户端的本地8388端口
// xor/none都不算加密,通过参数 -nocomp 在两端同时设定以关闭压缩。key可以自定义
// D1双核4线程可以添加 [--conn 4] 参数实现多线程下载

// Shadowsocks 客户端配置
// 在SS服务器新建服务端口:8388
// 路由SS配置服务器地址::127.0.0.1
// 路由SS配置服务器端口::8388
// 正确填写你的 Shadowsocks 密码,加密方式,协议和混淆方式。
// 两边都启动kcptun、启动SS,测试是否正确运行。

// 已经在华硕7620固件测试有效,稍后会集成到固件里面的。

sndwnd/rcvwnd 设定参考
sndwnd * mtu 不能超过上行带宽, rcvwnd * mtu 不能超过下行带宽
对延迟不敏感的情况,比如只用于数据传输,可以用MODE_FAST,20ms的内部时钟,默认值
对延迟敏感的情况,可以用FAST2模式,但必须严格注意第一条规则
更多说明移步:https://github.com/xtaci/kcptun

@xtaci xtaci added the enhancement label Jul 30, 2016

@hiboyhiboy

This comment has been minimized.

hiboyhiboy commented Jul 30, 2016

# 网友提供的更多编译方法:
docker search go-mips32
pull下来改成mips32le就可以用了

@xtaci

This comment has been minimized.

Owner

xtaci commented Jul 30, 2016

@yjbyf

This comment has been minimized.

yjbyf commented Aug 1, 2016

请问,我改了gen.go加了两个或判断,mip32和mip32le,ipv4和ipv6下2个文件都拷贝了,为什么还报错?
水平有限,请多指教,谢谢!

报错如下:
[mips@localhost gocode]$ vi src/golang.org/x/net/ipv4/gen.go
[mips@localhost gocode]$ env | grep GO
GOARCH=mips32le
GOROOT=/home/mips/go-mips32
GOOS=linux
GOPATH=/home/mips/gocode
[mips@localhost gocode]$ cp src/golang.org/x/net/ipv4/zsys_linux_mips64le.go src/golang.org/x/net/ipv4/zsys_linux_mips32le.go
[mips@localhost gocode]$ go get -v golang.org/x/net/ipv4
golang.org/x/net/ipv4

golang.org/x/net/ipv4

src/golang.org/x/net/ipv4/icmp.go:34: undefined: sysICMPFilter
[mips@localhost gocode]$

@bettermanbao

This comment has been minimized.

bettermanbao commented Aug 1, 2016

H大,你mt7620运行kcptun,不觉得性能不行吗?
我之前试过,性能比较糟糕。

@yjbyf

This comment has been minimized.

yjbyf commented Aug 1, 2016

你那个编译好的bin,在我的路由器上运行报错,我想试试自己编译看看

@hiboyhiboy

This comment has been minimized.

hiboyhiboy commented Aug 1, 2016

@bettermanbao 7620满载就20M左右,等其他人7621测试效果

@hiboyhiboy

This comment has been minimized.

hiboyhiboy commented Aug 1, 2016

@yjbyf 你第一步的环境编译有报错吧。
第一步无报错编译成功是这样的:这里看图 http://www.right.com.cn/forum/thread-190166-1-1.html

如果还是不行就去docker search go-mips32
pull下来改成mips32le用

@xtaci

This comment has been minimized.

Owner

xtaci commented Aug 1, 2016

golang.org/x/net/ipv4 这个库仅用于设置dscp,如果只是客户端用,可以考虑不设定dscp.

@TingyiChen

This comment has been minimized.

TingyiChen commented Aug 2, 2016

小米路由器mini,mt7620a,128m内存,运行kcptun打开网页就会崩溃,显示out of range.请问这是怎么回事?

@hiboyhiboy

This comment has been minimized.

hiboyhiboy commented Aug 6, 2016

zsys_linux_mips32.go和zsys_linux_mips32le.go文件里面的64字符也要修改 @yjbyf

// +build linux,mips32

// +build linux,mips32le

@yjbyf

This comment has been minimized.

yjbyf commented Aug 7, 2016

@hiboyhiboy 可以了,编译通过
不过路由器运行抛异常了,不过谢谢你了!!!

system type : Atheros AR9341 rev 3
machine : TP-LINK TL-WR841N/ND v8
processor : 0
cpu model : MIPS 74Kc V4.12

@TingyiChen

This comment has been minimized.

TingyiChen commented Aug 7, 2016

@yjbyf 关掉加密就不会报错

@xinghusp

This comment has been minimized.

xinghusp commented Aug 7, 2016

谢谢楼主……我用的也是这种方法,编译出来的代码无法在老内核的MIPS上用。。建立监听端口的地方就挂了。
最近发现如果用gccgo,就不会出问题。。然而gccgo编译不了kcpgo,头大中……

@xtaci xtaci closed this Aug 9, 2016

@fnscar

This comment has been minimized.

fnscar commented Oct 11, 2016

MT7621路由器运行时CPU占用率稳定在25%-30%,看起来很像是卡单线程了。YouTube连接速度也只有3000kbps。(用win客户端时在12000kbps以上)

@dfangboy

This comment has been minimized.

dfangboy commented Dec 7, 2016

有编译好这个吗。可以直接抛弃ss了
https://github.com/kcptunsocks/kcptun/tree/router
我自己编译了客户端可以连接。但是一访问就奔溃了。
服务端这里有编译好的https://github.com/clangcn/kcp-server
下面的是不是就是压缩的问题导致的?
2016/12/07 16:23:34 main.go:256: version: SELFBUILD
2016/12/07 16:23:36 main.go:292: listening on: [::]:1090
2016/12/07 16:23:36 main.go:293: encryption: salsa20
2016/12/07 16:23:36 main.go:294: nodelay parameters: 0 20 2 1
2016/12/07 16:23:36 main.go:295: remote address: XXX.XXX.XXX.XXX:XXX
2016/12/07 16:23:36 main.go:296: sndwnd: 128 rcvwnd: 256
2016/12/07 16:23:36 main.go:297: compression: true
2016/12/07 16:23:36 main.go:298: mtu: 1350
2016/12/07 16:23:36 main.go:299: datashard: 10 parityshard: 3
2016/12/07 16:23:36 main.go:300: acknodelay: false
2016/12/07 16:23:36 main.go:301: dscp: 0
2016/12/07 16:23:36 main.go:302: sockbuf: 4194304
2016/12/07 16:23:36 main.go:303: keepalive: 10
2016/12/07 16:23:36 main.go:304: conn: 1
2016/12/07 16:23:36 main.go:305: autoexpire: 0
2016/12/07 16:23:36 main.go:306: redir:
2016/12/07 16:23:52 trans.go:56: new socks5 conn by www.google.com.hk:80
panic: runtime error: slice bounds out of range

goroutine 13 [running]:
github.com/golang/snappy.encodeBlock(0x105c0013, 0x12ac9, 0x12ac9, 0x1058a000, 0x1d, 0x10000, 0x8fa14357)
/root/kcptun/src/github.com/golang/snappy/encode_other.go:175 +0x10c4
github.com/golang/snappy.Encode(0x105c0012, 0x12aca, 0x12aca, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
/root/kcptun/src/github.com/golang/snappy/encode.go:37 +0x370
github.com/golang/snappy.(*Writer).write(0x1053c6f0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
/root/kcptun/src/github.com/golang/snappy/encode.go:229 +0x280
github.com/golang/snappy.(*Writer).Flush(0x1053c6f0, 0x0, 0x0)
/root/kcptun/src/github.com/golang/snappy/encode.go:272 +0xb0
main.(*compStream).Write(0x10538880, 0x1061c000, 0x1d, 0x10008, 0x1d, 0x0, 0x0)
/root/kcptun/src/github.com/xtaci/kcptun/client/main.go:39 +0x88
github.com/xtaci/smux.(*Session).sendLoop(0x1050c1e0)
/root/kcptun/src/github.com/xtaci/smux/session.go:309 +0x5cc
created by github.com/xtaci/smux.newSession
/root/kcptun/src/github.com/xtaci/smux/session.go:78 +0x3d8

goroutine 1 [runnable]:
net.(*pollDesc).Wait(0x10530138, 0x72, 0x0, 0x0)
/root/go-mips32/src/net/fd_poll_runtime.go:84 +0x4c
net.(*pollDesc).WaitRead(0x10530138, 0x0, 0x0)
/root/go-mips32/src/net/fd_poll_runtime.go:89 +0x48
net.(*netFD).accept(0x10530100, 0x0, 0x775fda88, 0x1053868c)
/root/go-mips32/src/net/fd_unix.go:419 +0x3dc
net.(*TCPListener).AcceptTCP(0x1051c690, 0x1051c2c0, 0x0, 0x0)
/root/go-mips32/src/net/tcpsock_posix.go:234 +0x58
main.func·004(0x10500820, 0x0, 0x0)
/root/kcptun/src/github.com/xtaci/kcptun/client/main.go:361 +0x2638
github.com/urfave/cli.HandleAction(0x234288, 0x2e0b28, 0x10500820, 0x0, 0x0)
/root/kcptun/src/github.com/urfave/cli/app.go:485 +0x100
github.com/urfave/cli.(*App).Run(0x10564000, 0x1050a000, 0x3, 0x3, 0x0, 0x0)
/root/kcptun/src/github.com/urfave/cli/app.go:259 +0xba4
main.main()
/root/kcptun/src/github.com/xtaci/kcptun/client/main.go:392 +0x1418

goroutine 5 [syscall]:
os/signal.loop()
/root/go-mips32/src/os/signal/signal_unix.go:21 +0x30
created by os/signal.init·1
/root/go-mips32/src/os/signal/signal_unix.go:27 +0x58

goroutine 6 [chan receive]:
main.sigHandler()
/root/kcptun/src/github.com/xtaci/kcptun/client/signal.go:23 +0x150
created by main.init·1
/root/kcptun/src/github.com/xtaci/kcptun/client/signal.go:15 +0x48

goroutine 7 [select]:
github.com/xtaci/kcp-go.(*UDPSession).updateTask(0x10560080)
/root/kcptun/src/github.com/xtaci/kcp-go/sess.go:511 +0x33c
created by github.com/xtaci/kcp-go.newUDPSession
/root/kcptun/src/github.com/xtaci/kcp-go/sess.go:120 +0x534

goroutine 8 [select]:
github.com/xtaci/kcp-go.(*UDPSession).outputTask(0x10560080)
/root/kcptun/src/github.com/xtaci/kcp-go/sess.go:412 +0x1a60
created by github.com/xtaci/kcp-go.newUDPSession
/root/kcptun/src/github.com/xtaci/kcp-go/sess.go:121 +0x564

goroutine 9 [select]:
github.com/xtaci/kcp-go.(*UDPSession).readLoop(0x10560080)
/root/kcptun/src/github.com/xtaci/kcp-go/sess.go:630 +0x50c
created by github.com/xtaci/kcp-go.newUDPSession
/root/kcptun/src/github.com/xtaci/kcp-go/sess.go:123 +0x5a4

goroutine 11 [IO wait]:
net.(*pollDesc).Wait(0x10530df8, 0x72, 0x0, 0x0)
/root/go-mips32/src/net/fd_poll_runtime.go:84 +0x4c
net.(*pollDesc).WaitRead(0x10530df8, 0x0, 0x0)
/root/go-mips32/src/net/fd_poll_runtime.go:89 +0x48
net.(*netFD).readFrom(0x10530dc0, 0x10563800, 0x800, 0x800, 0x0, 0x0, 0x0, 0x775fda88, 0x105385a8)
/root/go-mips32/src/net/fd_unix.go:269 +0x418
net.(*UDPConn).ReadFromUDP(0x1051c3d8, 0x10563800, 0x800, 0x800, 0x0, 0x0, 0x0, 0x0)
/root/go-mips32/src/net/udpsock_posix.go:67 +0x108
net.(*UDPConn).ReadFrom(0x1051c3d8, 0x10563800, 0x800, 0x800, 0x0, 0x0, 0x0, 0x0, 0x0)
/root/go-mips32/src/net/udpsock_posix.go:82 +0x104
github.com/xtaci/kcp-go.(*UDPSession).receiver(0x10560080, 0x10530340)
/root/kcptun/src/github.com/xtaci/kcp-go/sess.go:611 +0x108
created by github.com/xtaci/kcp-go.(*UDPSession).readLoop
/root/kcptun/src/github.com/xtaci/kcp-go/sess.go:627 +0x84

goroutine 12 [select]:
github.com/xtaci/kcp-go.(*UDPSession).Read(0x10560080, 0x105ec000, 0x4, 0x12ace, 0x0, 0x0, 0x0)
/root/kcptun/src/github.com/xtaci/kcp-go/sess.go:184 +0x8d0
io.ReadAtLeast(0x775ff2c0, 0x10560080, 0x105ec000, 0x4, 0x12ace, 0x4, 0x0, 0x0, 0x0)
/root/go-mips32/src/io/io.go:298 +0x118
io.ReadFull(0x775ff2c0, 0x10560080, 0x105ec000, 0x4, 0x12ace, 0x0, 0x0, 0x0)
/root/go-mips32/src/io/io.go:316 +0x6c
github.com/golang/snappy.(*Reader).readFull(0x10530380, 0x105ec000, 0x4, 0x12ace, 0x1, 0x0)
/root/kcptun/src/github.com/golang/snappy/decode.go:108 +0x6c
github.com/golang/snappy.(*Reader).Read(0x10530380, 0x10600000, 0x8, 0x10008, 0x10500e60, 0x0, 0x0)
/root/kcptun/src/github.com/golang/snappy/decode.go:128 +0x1bc
main.(*compStream).Read(0x10538880, 0x10600000, 0x8, 0x10008, 0x2, 0x0, 0x0)
/root/kcptun/src/github.com/xtaci/kcptun/client/main.go:34 +0x5c
io.ReadAtLeast(0x775ff318, 0x10538880, 0x10600000, 0x8, 0x10008, 0x8, 0x0, 0x0, 0x0)
/root/go-mips32/src/io/io.go:298 +0x118
io.ReadFull(0x775ff318, 0x10538880, 0x10600000, 0x8, 0x10008, 0x775f0a14, 0x0, 0x0)
/root/go-mips32/src/io/io.go:316 +0x6c
github.com/xtaci/smux.(*Session).readFrame(0x1050c1e0, 0x10600000, 0x10008, 0x10008, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
/root/kcptun/src/github.com/xtaci/smux/session.go:194 +0x104
github.com/xtaci/smux.(*Session).recvLoop(0x1050c1e0)
/root/kcptun/src/github.com/xtaci/smux/session.go:229 +0x1d8
created by github.com/xtaci/smux.newSession
/root/kcptun/src/github.com/xtaci/smux/session.go:77 +0x3ac

goroutine 14 [select]:
github.com/xtaci/smux.(*Session).keepalive(0x1050c1e0)
/root/kcptun/src/github.com/xtaci/smux/session.go:277 +0x360
created by github.com/xtaci/smux.newSession
/root/kcptun/src/github.com/xtaci/smux/session.go:79 +0x404

goroutine 15 [select]:
main.scavenger(0x10530480)
/root/kcptun/src/github.com/xtaci/kcptun/client/main.go:409 +0x648
created by main.func·004
/root/kcptun/src/github.com/xtaci/kcptun/client/main.go:358 +0x2620

goroutine 16 [select]:
github.com/xtaci/smux.(*Stream).Write(0x1053a090, 0x10536143, 0x15, 0x12d, 0x0, 0x0, 0x0)
/root/kcptun/src/github.com/xtaci/smux/stream.go:111 +0x6c0
main.handleSocks5Client(0x775ff390, 0x1051c2b8, 0x775ff3b0, 0x1053a090, 0x0, 0x0)
/root/kcptun/src/github.com/xtaci/kcptun/client/trans.go:70 +0x7a0
created by main.func·004
/root/kcptun/src/github.com/xtaci/kcptun/client/main.go:388 +0x3104

goroutine 17 [runnable]:
net.(*pollDesc).Wait(0x10530a38, 0x72, 0x0, 0x0)
/root/go-mips32/src/net/fd_poll_runtime.go:84 +0x4c
net.(*pollDesc).WaitRead(0x10530a38, 0x0, 0x0)
/root/go-mips32/src/net/fd_poll_runtime.go:89 +0x48
net.(*netFD).Read(0x10530a00, 0x10536280, 0x107, 0x130, 0x0, 0x775fda88, 0x10538878)
/root/go-mips32/src/net/fd_unix.go:242 +0x3e0
net.(*conn).Read(0x1051c2c0, 0x10536280, 0x107, 0x130, 0x0, 0x0, 0x0)
/root/go-mips32/src/net/net.go:121 +0xf0
io.ReadAtLeast(0x775ff3d0, 0x1051c2c0, 0x10536280, 0x107, 0x130, 0x5, 0x0, 0x0, 0x0)
/root/go-mips32/src/io/io.go:298 +0x118
main.getRequest(0x10536280, 0x130, 0x130, 0x775ff390, 0x1051c2c0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
/root/kcptun/src/github.com/xtaci/kcptun/client/trans.go:138 +0xe4
main.handleSocks5Client(0x775ff390, 0x1051c2c0, 0x775ff3b0, 0x1053a1b0, 0x0, 0x0)
/root/kcptun/src/github.com/xtaci/kcptun/client/trans.go:55 +0x2cc
created by main.func·004
/root/kcptun/src/github.com/xtaci/kcptun/client/main.go:388 +0x3104

@wkingfly

This comment has been minimized.

wkingfly commented Dec 24, 2016

linksys Kirkwood内核是不是无解了……

@467815891a

This comment has been minimized.

467815891a commented Jan 6, 2017

@wkingfly 直接下载armv5的release就可以用了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment