Oct 12

源码: Psiphon 3 Tunnel Core 项目
编译:
原项目中关于编译说的比较简单笼统,这里详细说下。
首先确认 Go 编译环境已经安装好,可以参考 Tomatoware ARM 下建立 Go 编译环境 一文。
然后要下载一些依赖及源程序:
go get -u -v github.com/Psiphon-Inc/bolt
go get -u -v github.com/Psiphon-Inc/dns
go get -u -v github.com/Psiphon-Inc/goptlib
go get -u -v github.com/Psiphon-Inc/goregen
go get -u -v github.com/Psiphon-Inc/ratelimit
go get -u -v github.com/Psiphon-Inc/crypto/nacl/box
go get -u -v github.com/Psiphon-Inc/crypto/nacl/secretbox
go get -u -v github.com/Psiphon-Inc/crypto/ssh
go get -u -v github.com/Psiphon-Inc/goarista/monotime
go get -u -v github.com/Psiphon-Inc/goselect
go get -u -v github.com/Psiphon-Inc/sss
go get -u -v github.com/Psiphon-Inc/gocapability/capability
go get -u -v github.com/Psiphon-Inc/m3u8
go get -u -v github.com/Psiphon-Labs/psiphon-tunnel-core

写个编译脚本:

#!/bin/sh

WORKDIR=$(pwd)

cd src/github.com/Psiphon-Labs/psiphon-tunnel-core

BUILDDATE=$(date --iso-8601=seconds)
BUILDREPO=$(git config --get remote.origin.url)
BUILDREV=$(git rev-parse --short HEAD)
GOVERSION=$(go version | perl -ne '/go version (.*?) / && print $1')
DEPENDENCIES=$(echo -n "{" && go list -f '{{range $dep := .Deps}}
{{printf "%sn" $dep}}{{end}}' | xargs go list -f '{{if not .Standard}}
{{.ImportPath}}{{end}}' | xargs -I pkg bash -c 'cd $GOPATH/src/pkg
 && echo -n "\"pkg\":\"$(git rev-parse --short HEAD)\","' | sed 's/,$/}/')

LDFLAGS="
-X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common.buildDate=$BUILDDATE 
-X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common.buildRepo=$BUILDREPO 
-X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common.buildRev=$BUILDREV 
-X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common.goVersion=$GOVERSION 
-X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common.dependencies=$DEPENDENCIES 
"

cd ConsoleClient && go build -ldflags "${LDFLAGS}"
mv -f ./ConsoleClient ${WORKDIR}/bin/psiphon-tunnel-core-$BUILDREV
cd ${WORKDIR}
strip bin/psiphon-tunnel-core-$BUILDREV
upx -9 bin/psiphon-tunnel-core-$BUILDREV

bin/psiphon-tunnel-core-$BUILDREV

命令行运行:
./psiphon-tunnel-core -config ./psiphon.config -serverList ./server_list.dat -listenInterface br0 -formatNotices

psiphon.config 以及 server_list.dat 文件可以从 Windows 版本的 Psiphon3 (赛风3) 安装版本中提取。
运行结果:
psiphon-tunnel-core: Starting psiphon-tunnel-core...
2016-10-12T02:52:38Z BuildInfo {"buildDate":"2016-09-27T16:28:36+08:00","buildRepo":"https://github.com/Psiphon-Labs/psiphon-tunnel-core","buildRev":"31dad76","goVersion":"go1.6","gomobileVersion":"go1.6"}
2016-10-12T02:52:38Z AvailableEgressRegions {"regions":["CA","DE","GB","IN","JP","NL","SG","US"]}
2016-10-12T02:52:38Z ListeningSocksProxyPort {"port":7788}
2016-10-12T02:52:38Z ListeningHttpProxyPort {"port":8788}
2016-10-12T02:52:38Z ImpairedProtocolClassification {"classification":{}}
2016-10-12T02:52:38Z CandidateServers {"count":153,"protocol":"","region":""}
2016-10-12T02:52:42Z Homepage {"url":"http://www.psiphontoday.com/zh/index_desktop.html?client_region=CN"}
2016-10-12T02:52:42Z ClientUpgradeAvailable {"version":"116"}
2016-10-12T02:52:42Z Tunnels {"count":1}

出现 Tunnels {"count":1} 字样就表示连接服务器成功了。

新版编译出错:
# github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/tls
/mnt/data/compile/go/src/github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/tls/tls.go:106: undefined: deadlineTimeout

修改:

if !dialer.Deadline.IsZero() {
  		deadlineTimeout := dialer.Deadline.Sub(time.Now())
  		if timeout == 0 || deadlineTimeout < timeout {
  			timeout = deadlineTimeout
  		}
  	}

参考: https://github.com/golang/go/issues/14595

点击显示引用框
引用本文,复制粘贴...