github.com/igggame/nebulas-go@v2.1.0+incompatible/nbre/benchmark/ipc/grpc/server.go (about)

     1  // Copyright (C) 2018 go-nebulas authors
     2  //
     3  // This file is part of the go-nebulas library.
     4  //
     5  // the go-nebulas library is free software: you can redistribute it and/or modify
     6  // it under the terms of the GNU General Public License as published by
     7  // the Free Software Foundation, either version 3 of the License, or
     8  // (at your option) any later version.
     9  //
    10  // the go-nebulas library is distributed in the hope that it will be useful,
    11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  // GNU General Public License for more details.
    14  //
    15  // You should have received a copy of the GNU General Public License
    16  // along with the go-nebulas library.  If not, see <http://www.gnu.org/licenses/>.
    17  //
    18  
    19  package main
    20  
    21  import (
    22  	"log"
    23  	"net"
    24  
    25  	"github.com/nebulasio/go-nebulas/nbre/benchmark/ipc/grpc/pb"
    26  	"golang.org/x/net/context"
    27  	"google.golang.org/grpc"
    28  )
    29  
    30  const (
    31  	IPCAddress = "127.0.0.1:8696"
    32  )
    33  
    34  func main() {
    35  	server := NewServer()
    36  
    37  	listener, err := net.Listen("tcp", IPCAddress)
    38  	if err != nil {
    39  		panic("Failed to listen " + IPCAddress + " for ipc server")
    40  	}
    41  
    42  	if err := server.Serve(listener); err != nil {
    43  		panic("Failed to start ipc server")
    44  	}
    45  	server.Stop()
    46  	log.Println("GRPC server stoped.")
    47  }
    48  
    49  func NewServer() *grpc.Server {
    50  	maxSize := 64 * 1024 * 1024
    51  	rpc := grpc.NewServer(grpc.MaxRecvMsgSize(maxSize))
    52  	server := &BenchmarkService{}
    53  	ipcpb.RegisterBenchmarkServiceServer(rpc, server)
    54  	return rpc
    55  }
    56  
    57  type BenchmarkService struct {
    58  }
    59  
    60  func (s *BenchmarkService) Transfer(ctx context.Context, req *ipcpb.Benchmark) (*ipcpb.Benchmark, error) {
    61  	return &ipcpb.Benchmark{Data: req.Data}, nil
    62  }