예제 #1
0
func (s *Server) handleUDPFlowPacket() {
	s.conn.SetDeadline(time.Now().Add(200 * time.Millisecond))
	data := make([]byte, 4096)

	for s.running.Load() == true {
		n, _, err := s.conn.ReadFromUDP(data)
		if err != nil {
			if err.(net.Error).Timeout() == true {
				s.conn.SetDeadline(time.Now().Add(200 * time.Millisecond))
				continue
			}
			if s.running.Load() == false {
				return
			}
			logging.GetLogger().Errorf("Error while reading: %s", err.Error())
			return
		}

		f, err := flow.FromData(data[0:n])
		if err != nil {
			logging.GetLogger().Errorf("Error while parsing flow: %s", err.Error())
		}

		s.AnalyzeFlows([]*flow.Flow{f})
	}
}
예제 #2
0
파일: server.go 프로젝트: mestery/skydive
func (s *Server) handleUDPFlowPacket() {
	data := make([]byte, 4096)

	for {
		n, _, err := s.Conn.ReadFromUDP(data)
		if err != nil {
			if !s.Stopping {
				logging.GetLogger().Error("Error while reading: %s", err.Error())
			}
			return
		}

		f, err := flow.FromData(data[0:n])
		if err != nil {
			logging.GetLogger().Error("Error while parsing flow: %s", err.Error())
		}

		s.AnalyzeFlows([]*flow.Flow{f})
	}
}
예제 #3
0
func handleMessage(conn net.Conn, analyzer *analyzer.Analyzer) {
	logging.GetLogger().Info("New connection from: %s", conn.RemoteAddr().String())

	defer conn.Close()
	data := make([]byte, 4096)

	for {
		n, err := conn.Read(data)
		if err != nil {
			logging.GetLogger().Error("Error while reading: %s", err.Error())
			return
		}

		f, err := flow.FromData(data[0:n])
		if err != nil {
			logging.GetLogger().Error("Error while parsing flow: %s", err.Error())
		}

		analyzer.AnalyzeFlows([]*flow.Flow{f})
	}
}