Пример #1
0
func (c *ControlChannel) HandleMessage(handledNode *Node, msg []byte) (interface{}, error) {
	switch messages.GetMessageType(msg) {
	/*
		case messages.MsgCreateChannelControlMessage:
			channelID := handledNode.AddControlChannel()
			return channelID, nil
	*/
	case messages.MsgAddRouteControlMessage:
		fmt.Println("adding route")
		var m1 messages.AddRouteControlMessage
		err := messages.Deserialize(msg, &m1)
		if err != nil {
			panic(err)
		}
		routeRule := RouteRule{
			m1.IncomingTransportId,
			m1.OutgoingTransportId,
			m1.IncomingRouteId,
			m1.OutgoingRouteId,
		}
		return nil, handledNode.addRoute(&routeRule)

	case messages.MsgRemoveRouteControlMessage:
		fmt.Println("removing route")
		var m1 messages.RemoveRouteControlMessage
		messages.Deserialize(msg, &m1)
		routeId := m1.RouteId
		return nil, handledNode.removeRoute(routeId)
	}

	return nil, errors.New("Unknown message type")
}
Пример #2
0
func (self *Transport) receiveAck(msg []byte) {
	var m3 messages.TransportDatagramACK
	err := messages.Deserialize(msg, &m3)
	if err != nil {
		fmt.Println("incorrect ACK message")
	} else {
		lowestSequence := m3.LowestSequence
		if lowestSequence > self.PacketsConfirmed {
			self.PacketsConfirmed = lowestSequence
		}
		fmt.Printf("transport %d sent %d packets and got %d acks\n", self.Id, self.PacketsSent, self.PacketsConfirmed)
	}
}
Пример #3
0
func (self *Transport) receiveIncoming() {
	seed := time.Now().UnixNano()
	rand.Seed(seed)
	for msg := range self.IncomingChannel {
		if self.Status == DISCONNECTED {
			break
		}
		//process our incoming messages
		fmt.Printf("\ntransport with id %d gets message %d\n\n", self.Id, msg)

		switch messages.GetMessageType(msg) {

		//OutRouteMessage is the only message coming in to transports from node
		//Node -> Transport message
		case messages.MsgOutRouteMessage:

			var m1 messages.OutRouteMessage
			err := messages.Deserialize(msg, &m1)
			if err != nil {
				panic(err)
			}
			self.sendTransportDatagramTransfer(&m1)

		//Transport -> Transport messag
		case messages.MsgTransportDatagramTransfer:

			var m2 messages.TransportDatagramTransfer
			err := messages.Deserialize(msg, &m2)
			if err != nil {
				panic(err)
			}
			self.sendAck(&msg, &m2)

		default:
			fmt.Println("incorrect message type for transport input")
		}
	}
}
Пример #4
0
func (self *Node) HandleIncomingTransportMessages() {
	for msg := range self.IncomingChannel {
		fmt.Printf("\nnode with id %d accepting a message with type %d\n\n", self.Id, messages.GetMessageType(msg))
		//process our incoming messages
		switch messages.GetMessageType(msg) {
		//InRouteMessage is the only message coming in to node from transports
		case messages.MsgInRouteMessage:
			var m1 messages.InRouteMessage
			messages.Deserialize(msg, &m1)
			fmt.Println("InRouteMessage", m1)
			self.HandleInRouteMessage(m1)
		default:
			fmt.Println("wrong type", messages.GetMessageType(msg))
		}
	}
}