in agent/session/plugin/client/client.go [292:349]
func (c *Client) ProcessStatusDataChannel(payload []byte) error {
if c.verbosemode {
log.GetLogger().Infoln("read status data: ", payload)
}
code, err := bytesToIntU(payload[0:1])
if err == nil {
if code == 2 { //建立连接失败
log.GetLogger().Errorln("connect failed code 2")
c.Output.Write(payload)
return errors.New("Failed to connect. code 2")
} else if code == 5 { //关闭连接
errorCode := string(payload[1:])
tipStr := errorCode
log.GetLogger().Errorln("connect failed code 5")
switch errorCode {
case EXIT:
tipStr = fmt.Sprint(EXIT, ": session closed.")
break
case AGENT_TIMEOUT:
tipStr = fmt.Sprint(AGENT_TIMEOUT, ": session closed for agent timeout.")
break
case INIT_CHANNEL_FAILED:
tipStr = fmt.Sprint(INIT_CHANNEL_FAILED, ": session closed for init channel failed")
break
case OPEN_CHANNEL_FAILED:
tipStr = fmt.Sprint(OPEN_CHANNEL_FAILED, ": session closed for open channel failed.")
break
case SESSIONID_DUPLICATED:
tipStr = fmt.Sprint(SESSIONID_DUPLICATED, ": session closed for sessionId is duplicated.")
break
case PROCESS_DATA_ERROR:
tipStr = fmt.Sprint(PROCESS_DATA_ERROR, ": session closed for error while process data.")
break
case OPEN_PTY_FAILED:
tipStr = fmt.Sprint(OPEN_PTY_FAILED, ": session closed for open pty failed.")
break
case FLOW_EXCEED_LIMIT:
tipStr = fmt.Sprint(FLOW_EXCEED_LIMIT, ": session closed for the flow exceeds limit.")
break
}
log.GetLogger().Errorln("connect failed code 5:", tipStr)
fmt.Println(tipStr)
return errors.New("Connection closed. code 5")
} else if code == 3 {
} else if code == 7 { // 设置client的发送速率
speed, err := bytesToIntU(payload[1:]) // speed 单位是 bps
if speed != 0 {
if err != nil {
return err
}
c.sendInterval = 1000 / (speed / 8 / sendPackageSize)
log.GetLogger().Infof("Set send speed, speed[%d]bps sendInterval[%d]ms\n", speed, c.sendInterval)
}
}
}
return nil
}