Exemple #1
0
func NetworkProcessor(state interfaces.IState) {

netloop:
	for {

		// This loop looks at the input queues and the invalid queues and
		// Handles messages as they come in.   If nothing is read, it sleeps
		// for 500 milliseconds.  Note you only sleep if both queues test
		// to be empty.

		select {
		case msg, ok := <-state.NetworkInMsgQueue():
			if ok {
				//log.Printf("NetworkIn: %s\n", spew.Sdump(msg))
				if state.PrintType(msg.Type()) {
					log.Printf("Ignored: NetworkIn: %s\n", msg.String())
				}
				state.InMsgQueue() <- msg
				continue netloop
			}
		default:
		}

		select {
		case msg, ok := <-state.NetworkOutMsgQueue():
			if ok {
				var _ = msg
				//log.Printf("NetworkOut: %s\n", msg.String())
				if state.PrintType(msg.Type()) {
					log.Printf("Ignored: NetworkOut: %s\n", msg.String())
				}
				switch msg.(type) {
				case *messages.EOM:
					msgeom := msg.(*messages.EOM)
					server := state.GetServer().(*btcd.Server)
					server.BroadcastMessage(msgeom)

				default:
				}

				continue netloop
			}
		default:
		}

		select {
		case msg, ok := <-state.NetworkInvalidMsgQueue():
			if ok {
				var _ = msg
				if state.PrintType(msg.Type()) {
					log.Printf("%20s %s\n", "Invalid:", msg.String())
				}
				continue netloop
			}
		default:
		}
		time.Sleep(time.Duration(500) * time.Millisecond)
	}

}