mirror of https://github.com/ehang-io/nps
update sdk
parent
a602b11270
commit
daaf1f28e1
|
@ -42,9 +42,16 @@ func NewRPClient(svraddr string, vKey string, bridgeConnType string, proxyUrl st
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var NowStatus int
|
||||||
|
var CloseClient bool
|
||||||
//start
|
//start
|
||||||
func (s *TRPClient) Start() {
|
func (s *TRPClient) Start() {
|
||||||
retry:
|
retry:
|
||||||
|
NowStatus = 0
|
||||||
|
if CloseClient {
|
||||||
|
CloseClient = false
|
||||||
|
return
|
||||||
|
}
|
||||||
c, err := NewConn(s.bridgeConnType, s.vKey, s.svrAddr, common.WORK_MAIN, s.proxyUrl)
|
c, err := NewConn(s.bridgeConnType, s.vKey, s.svrAddr, common.WORK_MAIN, s.proxyUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logs.Error("The connection server failed and will be reconnected in five seconds, error", err.Error())
|
logs.Error("The connection server failed and will be reconnected in five seconds, error", err.Error())
|
||||||
|
@ -66,6 +73,7 @@ retry:
|
||||||
if s.cnf != nil && len(s.cnf.Healths) > 0 {
|
if s.cnf != nil && len(s.cnf.Healths) > 0 {
|
||||||
go heathCheck(s.cnf.Healths, s.signal)
|
go heathCheck(s.cnf.Healths, s.signal)
|
||||||
}
|
}
|
||||||
|
NowStatus = 1
|
||||||
//msg connection, eg udp
|
//msg connection, eg udp
|
||||||
s.handleMain()
|
s.handleMain()
|
||||||
}
|
}
|
||||||
|
@ -279,6 +287,7 @@ loop:
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *TRPClient) Close() {
|
func (s *TRPClient) Close() {
|
||||||
|
CloseClient = true
|
||||||
if s.tunnel != nil {
|
if s.tunnel != nil {
|
||||||
s.tunnel.Close()
|
s.tunnel.Close()
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,44 +6,31 @@ import (
|
||||||
"github.com/cnlh/nps/client"
|
"github.com/cnlh/nps/client"
|
||||||
"github.com/cnlh/nps/lib/common"
|
"github.com/cnlh/nps/lib/common"
|
||||||
"github.com/cnlh/nps/lib/version"
|
"github.com/cnlh/nps/lib/version"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var status int
|
|
||||||
var closeBefore int
|
|
||||||
var cl *client.TRPClient
|
var cl *client.TRPClient
|
||||||
|
|
||||||
//export StartClientByVerifyKey
|
//export StartClientByVerifyKey
|
||||||
func StartClientByVerifyKey(serverAddr, verifyKey, connType, proxyUrl *C.char) int {
|
func StartClientByVerifyKey(serverAddr, verifyKey, connType, proxyUrl *C.char) int {
|
||||||
logs.SetLogger("store")
|
logs.SetLogger("store")
|
||||||
if cl != nil {
|
if cl != nil {
|
||||||
closeBefore = 1
|
|
||||||
cl.Close()
|
cl.Close()
|
||||||
}
|
}
|
||||||
cl = client.NewRPClient(C.GoString(serverAddr), C.GoString(verifyKey), C.GoString(connType), C.GoString(proxyUrl), nil)
|
cl = client.NewRPClient(C.GoString(serverAddr), C.GoString(verifyKey), C.GoString(connType), C.GoString(proxyUrl), nil)
|
||||||
closeBefore = 0
|
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
cl.Start()
|
||||||
status = 1
|
return
|
||||||
cl.Start()
|
|
||||||
status = 0
|
|
||||||
if closeBefore == 1 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
time.Sleep(time.Second * 5)
|
|
||||||
}
|
|
||||||
}()
|
}()
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
//export GetClientStatus
|
//export GetClientStatus
|
||||||
func GetClientStatus() int {
|
func GetClientStatus() int {
|
||||||
return status
|
return client.NowStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
//export CloseClient
|
//export CloseClient
|
||||||
func CloseClient() {
|
func CloseClient() {
|
||||||
closeBefore = 1
|
|
||||||
cl.Close()
|
cl.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,6 +38,7 @@ func CloseClient() {
|
||||||
func Version() *C.char {
|
func Version() *C.char {
|
||||||
return C.CString(version.VERSION)
|
return C.CString(version.VERSION)
|
||||||
}
|
}
|
||||||
|
|
||||||
//export Logs
|
//export Logs
|
||||||
func Logs() *C.char {
|
func Logs() *C.char {
|
||||||
return C.CString(common.GetLogMsg())
|
return C.CString(common.GetLogMsg())
|
||||||
|
|
Loading…
Reference in New Issue