Exemple #1
0
//	We receive the chart script from our parent, we have to handle the data and send it to children.
func (s *Server) HandleChartTransfer(socket net.Conn) {
	file, _ := os.Create("./resources/chart.html")

	log.Println("Begginning receiving chart")

	for {
		read := make([]byte, 4096)

		n, _ := socket.Read(read)

		if sip.ExtractType(string(read[:n])) == "END" {
			break
		}

		file.Write(read[:n])

		socket.Write([]byte("INF||"))
	}

	log.Println("Done receiving chart")

	file.Close()

	for i := 0; i < s.ChildNumber; i++ {
		SendChart(s.Children[i])
	}
}
Exemple #2
0
//	Determines how to react for a SIP message depending on its type.
func (s *Server) SIPMessageReaction(socket net.Conn, msg string) {
	log.Print("Message type: %s\n", sip.ExtractType(msg))
	switch sip.ExtractType(msg) {
	case "BLD", "REQ":
		sip.SendInfo(socket, msg)
		if s.Root != nil {
			s.HandleNewMachine(socket, msg)
		} else {
			s.TellParent(msg)
		}
	case "TRA":
		sip.SendInfo(socket, msg)
		s.HandleChartTransfer(socket)
	case "FND":
		sip.SendInfo(socket, msg)
		DataMap := sip.InterpreteData(sip.ExtractData(msg))

		if s.Address == DataMap["parent"] {
			s.AddChild(DataMap["child"])
			break
		}
		s.AskChildren(msg)
	}
}