diff --git a/orderer/sample_clients/bd_counter/broadcast.go b/orderer/sample_clients/bd_counter/broadcast.go deleted file mode 100644 index b255d8b836c..00000000000 --- a/orderer/sample_clients/bd_counter/broadcast.go +++ /dev/null @@ -1,92 +0,0 @@ -/* -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 ( - "fmt" - "io" - "strconv" - - "github.com/hyperledger/fabric/orderer/common/bootstrap/provisional" - cb "github.com/hyperledger/fabric/protos/common" - ab "github.com/hyperledger/fabric/protos/orderer" - - "github.com/golang/protobuf/proto" - context "golang.org/x/net/context" -) - -func (c *clientImpl) broadcast() { - var count int - message := &cb.Envelope{} // Has a Data field - tokenChan := make(chan struct{}, c.config.count) - - stream, err := c.rpc.Broadcast(context.Background()) - if err != nil { - panic(fmt.Errorf("Failed to invoke broadcast RPC: %v", err)) - } - - go c.recvBroadcastReplies(stream) - - for { - select { - case <-c.signalChan: - err = stream.CloseSend() - if err != nil { - panic(fmt.Errorf("Failed to close the broadcast stream: %v", err)) - } - logger.Info("Client shutting down") - return - case tokenChan <- struct{}{}: - payload, err := proto.Marshal(&cb.Payload{ - Header: &cb.Header{ - ChainHeader: &cb.ChainHeader{ - ChainID: provisional.TestChainID, - }, - }, - Data: []byte(strconv.Itoa(count)), - }) - if err != nil { - panic(err) - } - message.Payload = payload - err = stream.Send(message) - if err != nil { - logger.Info("Failed to send broadcast message to orderer:", err) - } - logger.Debugf("Sent broadcast message \"%v\" to orderer\n", message) - count++ - } - } -} - -func (c *clientImpl) recvBroadcastReplies(stream ab.AtomicBroadcast_BroadcastClient) { - var count int - for { - reply, err := stream.Recv() - if err == io.EOF { - return - } - if err != nil { - panic(fmt.Errorf("Failed to receive a broadcast reply from orderer: %v", err)) - } - count++ - logger.Info("Broadcast reply from orderer:", reply.Status.String()) - if count >= c.config.count { - close(c.signalChan) - } - } -} diff --git a/orderer/sample_clients/bd_counter/deliver.go b/orderer/sample_clients/bd_counter/deliver.go deleted file mode 100644 index 914e2b8cd9e..00000000000 --- a/orderer/sample_clients/bd_counter/deliver.go +++ /dev/null @@ -1,107 +0,0 @@ -/* -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 ( - "fmt" - "io" - "log" - - "github.com/hyperledger/fabric/orderer/common/bootstrap/provisional" - ab "github.com/hyperledger/fabric/protos/orderer" - context "golang.org/x/net/context" -) - -func (c *clientImpl) deliver() { - updateSeek := &ab.DeliverUpdate{ - Type: &ab.DeliverUpdate_Seek{ - Seek: &ab.SeekInfo{ - WindowSize: uint64(c.config.window), - ChainID: provisional.TestChainID, - }, - }, - } - - switch c.config.seek { - case -2: - updateSeek.GetSeek().Start = ab.SeekInfo_OLDEST - case -1: - updateSeek.GetSeek().Start = ab.SeekInfo_NEWEST - default: - updateSeek.GetSeek().Start = ab.SeekInfo_SPECIFIED - updateSeek.GetSeek().SpecifiedNumber = uint64(c.config.seek) - } - - stream, err := c.rpc.Deliver(context.Background()) - if err != nil { - panic(fmt.Errorf("Failed to invoke deliver RPC: %v", err)) - } - - go c.recvDeliverReplies(stream) - - err = stream.Send(updateSeek) - if err != nil { - log.Println("Failed to send seek update to orderer: ", err) - } - logger.Debugf("Sent seek message (start: %v, number: %v, window: %v) to orderer\n", - updateSeek.GetSeek().Start, updateSeek.GetSeek().SpecifiedNumber, updateSeek.GetSeek().WindowSize) - - for range c.signalChan { - err = stream.CloseSend() - if err != nil { - panic(fmt.Errorf("Failed to close the deliver stream: %v", err)) - } - logger.Info("Client shutting down") - return - } -} - -func (c *clientImpl) recvDeliverReplies(stream ab.AtomicBroadcast_DeliverClient) { - var count int - updateAck := &ab.DeliverUpdate{ - Type: &ab.DeliverUpdate_Acknowledgement{ - Acknowledgement: &ab.Acknowledgement{}, // Has a Number field - }, - } - - for { - reply, err := stream.Recv() - if err == io.EOF { - return - } - if err != nil { - panic(err) - } - - switch t := reply.GetType().(type) { - case *ab.DeliverResponse_Block: - logger.Infof("Deliver reply from orderer: block %v, payload %v, prevHash %v", - t.Block.Header.Number, t.Block.Data.Data, t.Block.Header.PreviousHash) - count++ - if (count > 0) && (count%c.config.ack == 0) { - updateAck.GetAcknowledgement().Number = t.Block.Header.Number - err = stream.Send(updateAck) - if err != nil { - logger.Info("Failed to send ACK update to orderer: ", err) - } - logger.Debugf("Sent ACK for block %d", t.Block.Header.Number) - } - case *ab.DeliverResponse_Error: - logger.Info("Deliver reply from orderer:", t.Error.String()) - } - } -} diff --git a/orderer/sample_clients/bd_counter/main.go b/orderer/sample_clients/bd_counter/main.go deleted file mode 100644 index 379c55d4bb9..00000000000 --- a/orderer/sample_clients/bd_counter/main.go +++ /dev/null @@ -1,94 +0,0 @@ -/* -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" - "os" - "os/signal" - "strings" - - ab "github.com/hyperledger/fabric/protos/orderer" - logging "github.com/op/go-logging" - "google.golang.org/grpc" -) - -const pkgName = "orderer/bd_counter" - -var logger *logging.Logger - -type configImpl struct { - logLevel logging.Level - rpc, server string - count, seek, window, ack int -} - -type clientImpl struct { - config configImpl - rpc ab.AtomicBroadcastClient - signalChan chan os.Signal -} - -func main() { - var loglevel string - client := &clientImpl{} - - backend := logging.NewLogBackend(os.Stderr, "", 0) - logging.SetBackend(backend) - formatter := logging.MustStringFormatter("[%{time:15:04:05}] %{shortfile:18s}: %{color}[%{level:-5s}]%{color:reset} %{message}") - logging.SetFormatter(formatter) - logger = logging.MustGetLogger(pkgName) - - flag.StringVar(&client.config.rpc, "rpc", "broadcast", - "The RPC that this client is requesting.") - flag.StringVar(&client.config.server, "server", - "127.0.0.1:7050", "The RPC server to connect to.") - flag.IntVar(&client.config.count, "count", 100, - "When in broadcast mode, how many messages to send.") - flag.StringVar(&loglevel, "loglevel", "info", - "The logging level. (Suggested values: info, debug)") - flag.IntVar(&client.config.seek, "seek", -2, - "When in deliver mode, the number of the first block that should be delivered (-2 for oldest available, -1 for newest).") - flag.IntVar(&client.config.window, "window", 10, - "When in deliver mode, how many blocks can the server send without acknowledgement.") - flag.IntVar(&client.config.ack, "ack", 7, - "When in deliver mode, send acknowledgment per this many blocks received.") - flag.Parse() // TODO Validate user input (e.g. ack should be =< window) - - client.config.logLevel, _ = logging.LogLevel(strings.ToUpper(loglevel)) - logging.SetLevel(client.config.logLevel, logger.Module) - - // Trap SIGINT to trigger a shutdown - // We must use a buffered channel or risk missing the signal - // if we're not ready to receive when the signal is sent. - client.signalChan = make(chan os.Signal, 1) - signal.Notify(client.signalChan, os.Interrupt) - - conn, err := grpc.Dial(client.config.server, grpc.WithInsecure()) - if err != nil { - logger.Fatalf("Client did not connect to %s: %v", client.config.server, err) - } - defer conn.Close() - client.rpc = ab.NewAtomicBroadcastClient(conn) - - switch client.config.rpc { - case "broadcast": - client.broadcast() - case "deliver": - client.deliver() - } -}