mirror of https://github.com/ehang-io/nps
SDK中增加创建本地P2P和私密连接的接口
parent
2b68fbdc13
commit
207d6dff48
|
@ -4,11 +4,17 @@ import (
|
||||||
"C"
|
"C"
|
||||||
"ehang.io/nps/client"
|
"ehang.io/nps/client"
|
||||||
"ehang.io/nps/lib/common"
|
"ehang.io/nps/lib/common"
|
||||||
|
"ehang.io/nps/lib/config"
|
||||||
|
"ehang.io/nps/lib/file"
|
||||||
"ehang.io/nps/lib/version"
|
"ehang.io/nps/lib/version"
|
||||||
"github.com/astaxie/beego/logs"
|
"github.com/astaxie/beego/logs"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
var cl *client.TRPClient
|
var (
|
||||||
|
cl *client.TRPClient
|
||||||
|
ls bool
|
||||||
|
)
|
||||||
|
|
||||||
//export StartClientByVerifyKey
|
//export StartClientByVerifyKey
|
||||||
func StartClientByVerifyKey(serverAddr, verifyKey, connType, proxyUrl *C.char) int {
|
func StartClientByVerifyKey(serverAddr, verifyKey, connType, proxyUrl *C.char) int {
|
||||||
|
@ -21,8 +27,34 @@ func StartClientByVerifyKey(serverAddr, verifyKey, connType, proxyUrl *C.char) i
|
||||||
return 1
|
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
|
//export GetClientStatus
|
||||||
func GetClientStatus() int {
|
func GetClientStatus() int {
|
||||||
|
if ls && len(client.LocalServer) > 0 {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
return client.NowStatus
|
return client.NowStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,6 +63,10 @@ func CloseClient() {
|
||||||
if cl != nil {
|
if cl != nil {
|
||||||
cl.Close()
|
cl.Close()
|
||||||
}
|
}
|
||||||
|
if ls {
|
||||||
|
client.CloseLocalServer()
|
||||||
|
ls = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//export Version
|
//export Version
|
||||||
|
|
|
@ -3,12 +3,15 @@
|
||||||
```
|
```
|
||||||
命令行模式启动客户端
|
命令行模式启动客户端
|
||||||
从v0.26.10开始,此函数会阻塞,直到客户端退出返回,请自行管理是否重连
|
从v0.26.10开始,此函数会阻塞,直到客户端退出返回,请自行管理是否重连
|
||||||
p0->连接地址
|
serverAddr->连接地址
|
||||||
p1->vkey
|
verifyKey->vkey
|
||||||
p2->连接类型(tcp or udp)
|
connType->连接类型(tcp or udp)
|
||||||
p3->连接代理
|
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
|
查看当前启动的客户端状态,在线为1,离线为0
|
||||||
extern GoInt GetClientStatus();
|
extern GoInt GetClientStatus();
|
||||||
|
|
Loading…
Reference in New Issue