Exemple #1
0
func forwardIncoming(incomingMsg chan<- def.Message, udpReceive <-chan udpMessage) {
	for {
		udpMessage := <-udpReceive
		var message def.Message

		if err := json.Unmarshal(udpMessage.data[:udpMessage.length], &message); err != nil {
			fmt.Printf("json.Unmarshal error: %s\n", err)
		}

		message.Addr = udpMessage.raddr
		incomingMsg <- message
	}
}
func DecodeAndForwardReception(ch_new_elev chan<- string, ch_received <-chan config.NetworkMessage, ch_incoming_msg chan<- config.Message, ch_main_alive chan<- bool) {
	for {
		received := <-ch_received
		if string(received.Data[:len(config.MESSAGE_PREFIX)]) != config.MESSAGE_PREFIX || received.Raddr == config.Laddr {
			continue
		}

		var msg config.Message
		err := json.Unmarshal(received.Data[len(config.MESSAGE_PREFIX):received.Length], &msg)
		if err != nil {
			log.Printf("UDP_DecodeAndForwardReception: json error: %s", err)
			continue
		}
		if msg.Msg_type == config.ACK {
			IncremementACKCounter(string(received.Data[len(config.MESSAGE_PREFIX)+14 : received.Length]))
		}
		msg.Raddr = received.Raddr
		ch_incoming_msg <- msg
	}
}