mirror of
https://github.com/lwch/natpass.git
synced 2024-04-21 12:41:54 +00:00
修正本地发送数据的idx问题
This commit is contained in:
@@ -61,5 +61,4 @@ func shellCreate(conn *pool.Conn, msg *network.Msg) {
|
||||
}
|
||||
conn.SendShellCreatedOK(msg.GetFrom(), msg.GetFromIdx(), msg.GetLinkId())
|
||||
lk.Forward()
|
||||
lk.OnWork <- struct{}{}
|
||||
}
|
||||
|
||||
@@ -23,15 +23,6 @@ func (link *Link) remoteRead() {
|
||||
}
|
||||
link.targetIdx = msg.GetFromIdx()
|
||||
switch msg.GetXType() {
|
||||
case network.Msg_shell_created:
|
||||
logging.Info("shell created")
|
||||
if msg.GetCrep().GetOk() {
|
||||
link.OnWork <- struct{}{}
|
||||
continue
|
||||
}
|
||||
logging.Error("create shell %s on tunnel %s failed, err=%s",
|
||||
link.id, link.parent.Name, msg.GetCrep().GetMsg())
|
||||
return
|
||||
case network.Msg_shell_resize:
|
||||
// TODO
|
||||
case network.Msg_shell_data:
|
||||
@@ -51,7 +42,6 @@ func (link *Link) remoteRead() {
|
||||
func (link *Link) localRead() {
|
||||
defer utils.Recover("localRead")
|
||||
defer link.Close()
|
||||
<-link.OnWork
|
||||
buf := make([]byte, 16*1024)
|
||||
for {
|
||||
n, err := link.stdout.Read(buf)
|
||||
|
||||
@@ -47,6 +47,7 @@ func (shell *Shell) localForward(id string, local *websocket.Conn, remote *pool.
|
||||
shell.RLock()
|
||||
link := shell.links[id]
|
||||
shell.RUnlock()
|
||||
<-link.onWork
|
||||
for {
|
||||
_, data, err := local.ReadMessage()
|
||||
if err != nil {
|
||||
@@ -62,14 +63,24 @@ func (shell *Shell) localForward(id string, local *websocket.Conn, remote *pool.
|
||||
func (shell *Shell) remoteForward(id string, ch <-chan *network.Msg, local *websocket.Conn) {
|
||||
defer utils.Recover("remoteForward")
|
||||
defer local.Close()
|
||||
shell.RLock()
|
||||
link := shell.links[id]
|
||||
shell.RUnlock()
|
||||
for {
|
||||
msg := <-ch
|
||||
if msg == nil {
|
||||
return
|
||||
}
|
||||
link.SetTargetIdx(msg.GetFromIdx())
|
||||
switch msg.GetXType() {
|
||||
case network.Msg_shell_created:
|
||||
logging.Info("shell created")
|
||||
if msg.GetCrep().GetOk() {
|
||||
link.onWork <- struct{}{}
|
||||
continue
|
||||
}
|
||||
logging.Error("create shell %s on tunnel %s failed, err=%s",
|
||||
link.id, link.parent.Name, msg.GetScreated().GetMsg())
|
||||
return
|
||||
case network.Msg_shell_data:
|
||||
err := local.WriteMessage(websocket.TextMessage, msg.GetSdata().GetData())
|
||||
if err != nil {
|
||||
|
||||
@@ -14,7 +14,7 @@ type Link struct {
|
||||
target string // target id
|
||||
targetIdx uint32 // target idx
|
||||
remote *pool.Conn
|
||||
OnWork chan struct{}
|
||||
onWork chan struct{}
|
||||
// in remote
|
||||
pid int
|
||||
stdin io.WriteCloser
|
||||
@@ -31,7 +31,7 @@ func NewLink(parent *Shell, id, target string, remote *pool.Conn) *Link {
|
||||
id: id,
|
||||
target: target,
|
||||
remote: remote,
|
||||
OnWork: make(chan struct{}),
|
||||
onWork: make(chan struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user