// udpMsg
package service

import (
	"encoding/json"
	"log"
	mu "mfw/util"
	"net"
)

var (
	UdpMsgThread = make(chan bool, 1)
	Udpclient    mu.UdpClient //udp对象

)

//udp调用信号
func ProcessUdpMsg(act byte, data []byte, ra *net.UDPAddr) {
	switch act {
	case mu.OP_TYPE_DATA: //上个节点的数据
		var mapInfo map[string]interface{}
		err := json.Unmarshal(data, &mapInfo)
		log.Println("err:", err, "mapInfo:", mapInfo)
		//todo
		UdpMsgThread <- true
		go func() {
			defer func() {
				<-UdpMsgThread
			}()
			//清洗数据操作
			DataClean(mapInfo)
		}()
	case mu.OP_NOOP: //下个节点回应
		ok := string(data)
		if ok != "" {
			log.Println("ok:", ok)
		}
	}
}
