Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion cmd/npc/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ import (
"C"
"ehang.io/nps/client"
"ehang.io/nps/lib/common"
"ehang.io/nps/lib/config"
"ehang.io/nps/lib/file"
"ehang.io/nps/lib/version"
"github.com/astaxie/beego/logs"
"strconv"
)

var cl *client.TRPClient
var (
cl *client.TRPClient
ls bool
)

//export StartClientByVerifyKey
func StartClientByVerifyKey(serverAddr, verifyKey, connType, proxyUrl *C.char) int {
Expand All @@ -21,8 +27,34 @@ func StartClientByVerifyKey(serverAddr, verifyKey, connType, proxyUrl *C.char) i
return 1
}

//export StartLocalServer
func StartLocalServer(serverAddr, verifyKey, connType, password, localType, localPortStr, target, proxyUrl *C.char) int {
ls = true
_ = logs.SetLogger("store")
var localPort int
localPort, _ = strconv.Atoi(C.GoString(localPortStr))
client.CloseLocalServer()
commonConfig := new(config.CommonConfig)
commonConfig.Server = C.GoString(serverAddr)
commonConfig.VKey = C.GoString(verifyKey)
commonConfig.Tp = C.GoString(connType)
commonConfig.ProxyUrl = C.GoString(proxyUrl)
localServer := new(config.LocalServer)
localServer.Type = C.GoString(localType)
localServer.Password = C.GoString(password)
localServer.Target = C.GoString(target)
localServer.Port = localPort
commonConfig.Client = new(file.Client)
commonConfig.Client.Cnf = new(file.Config)
client.StartLocalServer(localServer, commonConfig)
return 1
}

//export GetClientStatus
func GetClientStatus() int {
if ls && len(client.LocalServer) > 0 {
return 1
}
return client.NowStatus
}

Expand All @@ -31,6 +63,10 @@ func CloseClient() {
if cl != nil {
cl.Close()
}
if ls {
client.CloseLocalServer()
ls = false
}
}

//export Version
Expand Down
13 changes: 8 additions & 5 deletions docs/npc_sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
```
命令行模式启动客户端
从v0.26.10开始,此函数会阻塞,直到客户端退出返回,请自行管理是否重连
p0->连接地址
p1->vkey
p2->连接类型(tcp or udp)
p3->连接代理
serverAddr->连接地址
verifyKey->vkey
connType->连接类型(tcp or udp)
proxyUrl->连接代理

extern GoInt StartClientByVerifyKey(char* p0, char* p1, char* p2, char* p3);
extern GoInt StartClientByVerifyKey(char* serverAddr, char* verifyKey, char* connType, char* proxyUrl);

命令行模式启动本地P2P或私密连接
extern GoInt StartLocalServer(char* serverAddr, char* verifyKey, char* connType, char* password, char* localType, char* localPortStr, char* target, char* proxyUrl);

查看当前启动的客户端状态,在线为1,离线为0
extern GoInt GetClientStatus();
Expand Down