Beispiel #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)
	}

}
Beispiel #2
0
func Factomd() {

	log.Print("//////////////////////// Copyright 2015 Factom Foundation")
	log.Print("//////////////////////// Use of this source code is governed by the MIT")
	log.Print("//////////////////////// license that can be found in the LICENSE file.")
	log.Printf("Go compiler version: %s\n", runtime.Version())
	log.Printf("Using build: %s\n", Build)

	if !isCompilerVersionOK() {
		for i := 0; i < 30; i++ {
			log.Println("!!! !!! !!! ERROR: unsupported compiler version !!! !!! !!!")
		}
		time.Sleep(3 * time.Second)
		os.Exit(1)
	}

	//  Go Optimizations...
	runtime.GOMAXPROCS(runtime.NumCPU())

	state0 := new(state.State)
	state0.SetLeaderTimestamp(primitives.NewTimestampFromMilliseconds(0))
	fmt.Println("len(Args)", len(os.Args))

	NetStart(state0)
}
Beispiel #3
0
func Follower(state interfaces.IState) {

	for {
		msg := <-state.FollowerInMsgQueue()
		if state.PrintType(msg.Type()) {
			log.Printf("%20s %s\n", "Follower:", msg.String())
		}
		msg.FollowerExecute(state)
	}

}
Beispiel #4
0
// a simple file/line trace function, with optional comment(s)
func Trace(params ...string) {
	log.Printf("##")

	if 0 < len(params) {
		for i := range params {
			log.Printf(" %s", params[i])
		}
		log.Printf(" #### ")
	} else {
		log.Printf(" ")
	}

	pc := make([]uintptr, 10) // at least 1 entry needed
	runtime.Callers(2, pc)
	f := runtime.FuncForPC(pc[0])
	file, line := f.FileLine(pc[0])

	tutc := time.Now().UTC()
	timestamp := tutc.Format("2006-01-02.15:04:05")

	log.Printf("TRACE: %s line %d %s file: %s\n", timestamp, line, f.Name(), file)
}
Beispiel #5
0
func main() {
	log.Print("//////////////////////// Copyright 2015 Factom Foundation")
	log.Print("//////////////////////// Use of this source code is governed by the MIT")
	log.Print("//////////////////////// license that can be found in the LICENSE file.")

	log.Printf("Go compiler version: %s\n", runtime.Version())
	log.Printf("Using build: %s\n", Build)

	if !isCompilerVersionOK() {
		for i := 0; i < 30; i++ {
			fmt.Println("!!! !!! !!! ERROR: unsupported compiler version !!! !!! !!!")
		}
		time.Sleep(3 * time.Second)
		os.Exit(1)
	}
	cfgFilename := ""

	state := new(state.State)
	state.Init(cfgFilename)

	runtime.GOMAXPROCS(runtime.NumCPU())
	if err := limits.SetLimits(); err != nil {
		os.Exit(1)
	}

	btcd.AddInterruptHandler(func() {
		log.Printf("Gracefully shutting down the database...")
		state.GetDB().(interfaces.IDatabase).Close()
	})

	log.Print("Starting server")
	server, _ := btcd.NewServer(state)

	btcd.AddInterruptHandler(func() {
		log.Printf("Gracefully shutting down the server...")
		server.Stop()
		server.WaitForShutdown()
	})
	server.Start()
	state.SetServer(server)

	//factomForkInit(server)
	go NetworkProcessor(state)
	go Timer(state)
	go Validator(state)
	go Leader(state)
	go Follower(state)
	go wsapi.Start(state)

	shutdownChannel := make(chan struct{})
	go func() {
		server.WaitForShutdown()
		log.Printf("Server shutdown complete")
		shutdownChannel <- struct{}{}
	}()

	// Wait for shutdown signal from either a graceful server stop or from
	// the interrupt handler.
	<-shutdownChannel
	log.Printf("Shutdown complete")
}