Exemple #1
0
func serve(c flags) {
	if c.dataDir == "" {
		fmt.Fprintln(os.Stderr, "need data directory")
		os.Exit(1)
	}

	persist := persist.New(c.dataDir)
	config, err := RestoreConfig(persist)
	if err != nil {
		panic(err)
	}

	conn, err := connection.New(c.listenAddr, c.certFile, c.keyFile)
	if err != nil {
		fmt.Fprintln(os.Stderr, "Connection error.")
		panic(err)
	}
	s := &consensusStack{
		persist: nil,
	}

	localConf := localconfig.Load()
	localConf.General.OrdererType = provisional.ConsensusTypeSbft
	genesisBlock := provisional.New(localConf).GenesisBlock()

	_, ledger := fileledger.New(c.dataDir, genesisBlock)
	s.backend, err = backend.NewBackend(config.Peers, conn, ledger, persist)
	if err != nil {
		panic(err)
	}

	sbft, _ := pb.New(s.backend.GetMyId(), config.Consensus, s.backend)
	s.backend.SetReceiver(sbft)

	grpcServer := grpc.NewServer()
	lis, err := net.Listen("tcp", c.grpcAddr)
	if err != nil {
		panic(fmt.Sprintf("Failed to listen: %s", err))
	}
	broadcastab := backend.NewBackendAB(s.backend)
	ab.RegisterAtomicBroadcastServer(grpcServer, broadcastab)
	grpcServer.Serve(lis)

	// block forever
	select {}
}
func (env *fileLedgerTestFactory) New() (Factory, ReadWriter) {
	return fileledger.New(env.location, genesisBlock)
}
Exemple #3
0
func main() {
	conf := config.Load()

	// Start the profiling service if enabled.
	// The ListenAndServe() call does not return unless an error occurs.
	if conf.General.Profile.Enabled {
		go func() {
			logger.Infof("Starting Go pprof profiling service on %s", conf.General.Profile.Address)
			panic(fmt.Errorf("Go pprof service failed: %s", http.ListenAndServe(conf.General.Profile.Address, nil)))
		}()
	}

	grpcServer := grpc.NewServer()

	lis, err := net.Listen("tcp", fmt.Sprintf("%s:%d", conf.General.ListenAddress, conf.General.ListenPort))
	if err != nil {
		fmt.Println("Failed to listen:", err)
		return
	}

	var genesisBlock *cb.Block

	// Select the bootstrapping mechanism
	switch conf.General.GenesisMethod {
	case "provisional":
		genesisBlock = provisional.New(conf).GenesisBlock()
	default:
		panic(fmt.Errorf("Unknown genesis method %s", conf.General.GenesisMethod))
	}

	var lf rawledger.Factory
	switch conf.General.LedgerType {
	case "file":
		location := conf.FileLedger.Location
		if location == "" {
			var err error
			location, err = ioutil.TempDir("", conf.FileLedger.Prefix)
			if err != nil {
				panic(fmt.Errorf("Error creating temp dir: %s", err))
			}
		}
		lf, _ = fileledger.New(location, genesisBlock)
	case "ram":
		fallthrough
	default:
		lf, _ = ramledger.New(int(conf.RAMLedger.HistorySize), genesisBlock)
	}

	if conf.Kafka.Verbose {
		sarama.Logger = log.New(os.Stdout, "[sarama] ", log.Lshortfile)
	}

	consenters := make(map[string]multichain.Consenter)
	consenters["solo"] = solo.New(conf.General.BatchTimeout)
	consenters["kafka"] = kafka.New(conf.Kafka.Version, conf.Kafka.Retry)

	manager := multichain.NewManagerImpl(lf, consenters)

	server := NewServer(
		manager,
		int(conf.General.QueueSize),
		int(conf.General.MaxWindowSize),
	)

	ab.RegisterAtomicBroadcastServer(grpcServer, server)
	grpcServer.Serve(lis)
}