<commit_before>/*
Copyright IBM Corp. 2016 All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

	http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
	"flag"
	"net"
	_ "net/http/pprof"
	"os"

	"github.com/hyperledger/fabric/orderer/common/bootstrap/provisional"
	localconfig "github.com/hyperledger/fabric/orderer/localconfig"
	"github.com/hyperledger/fabric/orderer/rawledger/fileledger"
	"github.com/hyperledger/fabric/orderer/sbft"
	"github.com/hyperledger/fabric/orderer/sbft/backend"
	"github.com/hyperledger/fabric/orderer/sbft/connection"
	"github.com/hyperledger/fabric/orderer/sbft/persist"
	pb "github.com/hyperledger/fabric/orderer/sbft/simplebft"
	ab "github.com/hyperledger/fabric/protos/orderer"
	"github.com/op/go-logging"
	"google.golang.org/grpc"
)

type consensusStack struct {
	persist *persist.Persist
	backend *backend.Backend
}

type flags struct {
	listenAddr    string
	grpcAddr      string
	telemetryAddr string
	certFile      string
	keyFile       string
	dataDir       string
	genesisFile   string
	verbose       string
	init          string
}

var logger = logging.MustGetLogger("orderer/main")

// TODO move to_test after integration with common components
func init() {
	logging.SetLevel(logging.DEBUG, "")
}

func main() {
	var c flags

	flag.StringVar(&c.init, "init", "", "initialized instance from pbft config `file`")
	flag.StringVar(&c.listenAddr, "addr", ":6100", "`addr`ess/port of service")
	flag.StringVar(&c.grpcAddr, "gaddr", ":7100", "`addr`ess/port of GRPC atomic broadcast server")
	flag.StringVar(&c.telemetryAddr, "telemetry", ":7100", "`addr`ess of telemetry/profiler")
	flag.StringVar(&c.certFile, "cert", "", "certificate `file`")
	flag.StringVar(&c.keyFile, "key", "", "key `file`")
	flag.StringVar(&c.dataDir, "data-dir", "", "data `dir`ectory")
	flag.StringVar(&c.genesisFile, "genesis-file", "", "`gen`esis block file")
	flag.StringVar(&c.verbose, "verbose", "info", "set verbosity `level` (critical, error, warning, notice, info, debug)")

	flag.Parse()

	level, err := logging.LogLevel(c.verbose)
	if err != nil {
		logger.Panicf("Failed to set loglevel: %s", err)
	}
	logging.SetLevel(level, "")

	if c.init != "" {<commit_msg>Add an initial Consenter interface skeleton to SBFT<commit_after>/*
Copyright IBM Corp. 2016 All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

	http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
	"flag"
	"net"
	_ "net/http/pprof"
	"os"

	"github.com/hyperledger/fabric/orderer/common/bootstrap/provisional"
	localconfig "github.com/hyperledger/fabric/orderer/localconfig"
	"github.com/hyperledger/fabric/orderer/multichain"
	"github.com/hyperledger/fabric/orderer/rawledger/fileledger"
	"github.com/hyperledger/fabric/orderer/sbft"
	"github.com/hyperledger/fabric/orderer/sbft/backend"
	"github.com/hyperledger/fabric/orderer/sbft/connection"
	"github.com/hyperledger/fabric/orderer/sbft/persist"
	pb "github.com/hyperledger/fabric/orderer/sbft/simplebft"
	cb "github.com/hyperledger/fabric/protos/common"
	ab "github.com/hyperledger/fabric/protos/orderer"
	"github.com/op/go-logging"
	"google.golang.org/grpc"
)

type consensusStack struct {
	persist *persist.Persist
	backend *backend.Backend
}

type flags struct {
	listenAddr    string
	grpcAddr      string
	telemetryAddr string
	certFile      string
	keyFile       string
	dataDir       string
	genesisFile   string
	verbose       string
	init          string
}

var logger = logging.MustGetLogger("orderer/main")

// TODO move to_test after integration with common components
func init() {
	logging.SetLevel(logging.DEBUG, "")
}

// Consenter interface implementation for new main application:
// This part is Work In Progress

type consenter struct{}

type chain struct {
	support multichain.ConsenterSupport
}

// New creates a new consenter for the SBFT consensus scheme.
// It accepts messages being delivered via Enqueue, orders them, and then
// uses the blockcutter to form the messages into blocks before writing to
// the given ledger.
func New() multichain.Consenter {
	return &consenter{}
}

// HandleChain creates/returns a reference to a Chain for the given set of support resources.
func (solo *consenter) HandleChain(support multichain.ConsenterSupport) (multichain.Chain, error) {
	return newChain(support), nil
}

func newChain(support multichain.ConsenterSupport) *chain {
	return &chain{
		support: support,
	}
}

// Chain interface implementation:

// TODO
// Start allocates whatever resources are needed for staying up to date with the chain
func (ch *chain) Start() {

}

// TODO
// Halt frees the resources which were allocated for this Chain
func (ch *chain) Halt() {

}

// TODO
// Enqueue accepts a message and returns true on acceptance, or false on shutdown
func (ch *chain) Enqueue(env *cb.Envelope) bool {
	return false
}

// The "old", SBFT only application:
func main() {
	var c flags

	flag.StringVar(&c.init, "init", "", "initialized instance from pbft config `file`")
	flag.StringVar(&c.listenAddr, "addr", ":6100", "`addr`ess/port of service")
	flag.StringVar(&c.grpcAddr, "gaddr", ":7100", "`addr`ess/port of GRPC atomic broadcast server")
	flag.StringVar(&c.telemetryAddr, "telemetry", ":7100", "`addr`ess of telemetry/profiler")
	flag.StringVar(&c.certFile, "cert", "", "certificate `file`")
	flag.StringVar(&c.keyFile, "key", "", "key `file`")
	flag.StringVar(&c.dataDir, "data-dir", "", "data `dir`ectory")
	flag.StringVar(&c.genesisFile, "genesis-file", "", "`gen`esis block file")
	flag.StringVar(&c.verbose, "verbose", "info", "set verbosity `level` (critical, error, warning, notice, info, debug)")

	flag.Parse()

	level, err := logging.LogLevel(c.verbose)
	if err != nil {
		logger.Panicf("Failed to set loglevel: %s", err)
	}
	logging.SetLevel(level, "")

	if c.init != "" {
{'fraction_non_alphanumeric': 0.12233009708737864, 'fraction_numerical': 0.00597460791635549, 'mean_word_length': 4.520197856553998, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7287993', 'n_tokens_mistral': 2218, 'n_tokens_neox': 2142, 'n_words': 624}