merge: 合并代码
This commit is contained in:
@@ -51,16 +51,24 @@ var (
|
||||
CustomUriOmMmlInt = config.UriPrefix + "/omManagement/{apiVersion}/mml/{neType}/{neId}"
|
||||
)
|
||||
|
||||
var TIME_DELAY_AFTER_WRITE time.Duration = 200
|
||||
var TIME_DEAD_LINE time.Duration = 10
|
||||
var (
|
||||
TIME_DELAY_AFTER_WRITE time.Duration = 200
|
||||
TIME_DEAD_LINE time.Duration = 10
|
||||
WIN_ROW_SIZE byte = 100
|
||||
WIN_COL_SIZE byte = 100
|
||||
BUFFER_SIZE int = 65535
|
||||
)
|
||||
|
||||
func init() {
|
||||
func InitMML() {
|
||||
if config.GetYamlConfig().MML.Sleep != 0 {
|
||||
TIME_DELAY_AFTER_WRITE = time.Duration(config.GetYamlConfig().MML.Sleep)
|
||||
}
|
||||
if config.GetYamlConfig().MML.DeadLine != 0 {
|
||||
TIME_DEAD_LINE = time.Duration(config.GetYamlConfig().MML.DeadLine)
|
||||
}
|
||||
WIN_ROW_SIZE = config.GetYamlConfig().MML.SizeRow
|
||||
WIN_COL_SIZE = config.GetYamlConfig().MML.SizeCol
|
||||
BUFFER_SIZE = config.GetYamlConfig().MML.BufferSize
|
||||
}
|
||||
|
||||
func PostMML2ToNF(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -78,8 +86,7 @@ func PostMML2ToNF(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
var buf [20 * 1024]byte
|
||||
//buf := make([]byte, 0)
|
||||
buf := make([]byte, BUFFER_SIZE)
|
||||
var n int
|
||||
var mmlResult []string
|
||||
port2 := 5002
|
||||
@@ -90,6 +97,7 @@ func PostMML2ToNF(w http.ResponseWriter, r *http.Request) {
|
||||
if neInfo != nil {
|
||||
hostMML := fmt.Sprintf("%s:%d", neInfo.Ip, port2)
|
||||
conn, err := net.Dial("tcp", hostMML)
|
||||
//conn, err := net.Dial("tcp", hostMML)
|
||||
if err != nil {
|
||||
errMsg := fmt.Sprintf("Failed to dial %s: %v", hostMML, err)
|
||||
log.Error(errMsg)
|
||||
@@ -110,6 +118,9 @@ func PostMML2ToNF(w http.ResponseWriter, r *http.Request) {
|
||||
// services.ResponseWithJson(w, http.StatusOK, response)
|
||||
// return
|
||||
// }
|
||||
// 发送窗口大小设置命令
|
||||
conn.Write([]byte{255, 251, 31}) // 发送WILL WINDOW SIZE
|
||||
conn.Write([]byte{255, 250, 31, 0, WIN_ROW_SIZE, 0, WIN_COL_SIZE, 255, 240}) // 发送设置 WINDOW SIZE
|
||||
|
||||
conn.SetDeadline(time.Now().Add(TIME_DEAD_LINE * time.Second))
|
||||
loginStr := fmt.Sprintf("%s\n%s\n", config.GetYamlConfig().MML.User, config.GetYamlConfig().MML.Password)
|
||||
@@ -172,7 +183,7 @@ func PostMML2ToNF(w http.ResponseWriter, r *http.Request) {
|
||||
//re2 := regexp.MustCompile(`\x00`) // 匹配空字符
|
||||
re2 := regexp.MustCompile(`[\x00-\x08\x0B\x0C\x0E-\x1F\x7F\x1B]`) // 匹配空字符和包含␛的控制字符
|
||||
//re := regexp.MustCompile(`[\x00-\x1F\x7F]`)
|
||||
result := re1.ReplaceAllString(string(buf[0:n-len(neType)-2]), "")
|
||||
result := re1.ReplaceAllString(string(buf[0:n]), "")
|
||||
result = re2.ReplaceAllString(result, "")
|
||||
mmlResult = append(mmlResult, result)
|
||||
}
|
||||
@@ -186,11 +197,11 @@ func PostMML2ToNF(w http.ResponseWriter, r *http.Request) {
|
||||
func PostMMLToNF(w http.ResponseWriter, r *http.Request) {
|
||||
log.Debug("PostMMLToNF processing... ")
|
||||
|
||||
token, err := services.CheckExtValidRequest(w, r)
|
||||
if err != nil {
|
||||
log.Error("Request error:", err)
|
||||
return
|
||||
}
|
||||
// token, err := services.CheckExtValidRequest(w, r)
|
||||
// if err != nil {
|
||||
// log.Error("Request error:", err)
|
||||
// return
|
||||
// }
|
||||
// 经过测试,linux下,延时需要大于100ms
|
||||
// var TIME_DELAY_AFTER_WRITE time.Duration = 200
|
||||
// var TIME_DEAD_LINE time.Duration = 10
|
||||
@@ -214,8 +225,7 @@ func PostMMLToNF(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
log.Debug("neType:", neType, "neId", neId)
|
||||
|
||||
log.Debugf("token:%s, method:%s, managementType:%s dbname:%s, tbname:%s pack:%s",
|
||||
token, r.Method, module, neType, neId[0], pack)
|
||||
log.Debugf("method:%s, managementType:%s dbname:%s, tbname:%s pack:%s", r.Method, module, neType, neId[0], pack)
|
||||
|
||||
var buf [20 * 1024]byte
|
||||
//buf := make([]byte, 0)
|
||||
@@ -250,7 +260,7 @@ func PostMMLToNF(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
neInfo := new(dborm.NeInfo)
|
||||
neInfo, err = dborm.XormGetNeInfo(neType, neId[0])
|
||||
neInfo, err := dborm.XormGetNeInfo(neType, neId[0])
|
||||
if err != nil {
|
||||
log.Error("dborm.XormGetNeInfo is failed:", err)
|
||||
services.ResponseInternalServerError500DatabaseOperationFailed(w)
|
||||
@@ -631,11 +641,11 @@ func PostMMLToNF(w http.ResponseWriter, r *http.Request) {
|
||||
func PostMMLToOMC(w http.ResponseWriter, r *http.Request) {
|
||||
log.Debug("PostMMLToOMC processing... ")
|
||||
|
||||
token, err := services.CheckExtValidRequest(w, r)
|
||||
if err != nil {
|
||||
log.Error("Failed to CheckMmlValidRequest:", err)
|
||||
return
|
||||
}
|
||||
// token, err := services.CheckExtValidRequest(w, r)
|
||||
// if err != nil {
|
||||
// log.Error("Failed to CheckMmlValidRequest:", err)
|
||||
// return
|
||||
// }
|
||||
|
||||
params := r.URL.Query()
|
||||
neId := params["ne_id"]
|
||||
@@ -646,7 +656,7 @@ func PostMMLToOMC(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
neInfo := new(dborm.NeInfo)
|
||||
neInfo, err = dborm.XormGetNeInfo("OMC", neId[0])
|
||||
neInfo, err := dborm.XormGetNeInfo("OMC", neId[0])
|
||||
if err != nil {
|
||||
log.Error("dborm.XormGetNeInfo is failed:", err)
|
||||
services.ResponseInternalServerError500DatabaseOperationFailed(w)
|
||||
@@ -670,7 +680,7 @@ func PostMMLToOMC(w http.ResponseWriter, r *http.Request) {
|
||||
MmlHome: config.GetYamlConfig().MML.MmlHome,
|
||||
Limit: 50,
|
||||
User: "",
|
||||
SessionToken: token, // 旧token
|
||||
SessionToken: "", // 旧token
|
||||
Authorization: r.Header.Get(tokenConst.HEADER_KEY), // 请求Token
|
||||
HttpUri: hostUri,
|
||||
UserAgent: config.GetDefaultUserAgent(),
|
||||
|
||||
Reference in New Issue
Block a user