func (link *Link) SendData(data []byte) {
	send := link.remote.SendShellData(link.target, link.targetIdx, link.id, data)
	link.sendBytes += send
	link.sendPacket++
}
SendData send data
package shell
import (
	"io"
	"natpass/code/client/pool"
	"natpass/code/network"
	"natpass/code/utils"
	"os"
	"github.com/lwch/logging"
	"golang.org/x/text/encoding/simplifiedchinese"
	"google.golang.org/protobuf/proto"
)
type Link struct {
	parent    *Shell
	id        string  
	target    string  
	targetIdx uint32  
	remote    *pool.Conn
	pid    int
	stdin  io.WriteCloser
	stdout io.ReadCloser
	sendBytes  uint64
	recvBytes  uint64
	sendPacket uint64
	recvPacket uint64
}
func NewLink(parent *Shell, id, target string, remote *pool.Conn) *Link {
	remote.AddLink(id)
	logging.Info("create shell %s for tunnel %s on connection %d",
		id, parent.Name, remote.Idx)
	return &Link{
		parent: parent,
		id:     id,
		target: target,
		remote: remote,
	}
}
func (link *Link) GetID() string {
	return link.id
}
func (link *Link) GetBytes() (uint64, uint64) {
	return link.recvBytes, link.sendBytes
}
func (link *Link) GetPackets() (uint64, uint64) {
	return link.recvPacket, link.sendPacket
}
func (link *Link) SetTargetIdx(idx uint32) {
	link.targetIdx = idx
}
func (link *Link) Close() {
	link.onClose()
	p, err := os.FindProcess(link.pid)
	if err == nil {
		p.Kill()
	}
	link.remote.SendDisconnect(link.target, link.targetIdx, link.id)
	link.parent.remove(link.id)
}
func (link *Link) Forward() {
	go link.remoteRead()
	go link.localRead()
}
func (link *Link) remoteRead() {
	defer utils.Recover("remoteRead")
	defer link.Close()
	ch := link.remote.ChanRead(link.id)
	for {
		msg := <-ch
		if msg == nil {
			return
		}
		data, _ := proto.Marshal(msg)
		link.recvBytes += uint64(len(data))
		link.recvPacket++
		link.targetIdx = msg.GetFromIdx()
		switch msg.GetXType() {
		case network.Msg_shell_resize:
			size := msg.GetSresize()
			link.resize(size.GetRows(), size.GetCols())
		case network.Msg_shell_data:
			_, err := link.stdin.Write(msg.GetSdata().GetData())
			if err != nil {
				logging.Error("write data on shell %s link %s failed, err=%v",
					link.parent.Name, link.id, err)
				return
			}
		case network.Msg_disconnect:
			logging.Info("shell %s link %s closed by remote", link.parent.Name, link.id)
			return
		}
	}
}
func (link *Link) localRead() {
	defer utils.Recover("localRead")
	defer link.Close()
	buf := make([]byte, 16*1024)
	for {
		n, err := link.stdout.Read(buf)
		if err != nil {
			logging.Error("read data on shell %s link %s failed, err=%v",
				link.parent.Name, link.id, err)
			return
		}
		if n == 0 {
			continue
		}
		var data []byte
		switch {
		case isUtf8(buf[:n]):
			data = buf[:n]
		case isGBK(buf[:n]):
			data, err = simplifiedchinese.GBK.NewDecoder().Bytes(buf[:n])
			if err != nil {
				logging.Error("transform gbk to utf8 failed: %v", err)
				continue
			}
		}
		logging.Debug("link %s on shell %s read from local %d bytes",
			link.id, link.parent.Name, n)
		send := link.remote.SendShellData(link.target, link.targetIdx, link.id, data)
		link.sendBytes += send
		link.sendPacket++
	}
}