Skip to content

Commit

Permalink
(feat) new grpc protocol (#619)
Browse files Browse the repository at this point in the history
* (feat) new grpc protocol

* (fix) ci

* (fix) ci
  • Loading branch information
adwpc authored Nov 28, 2021
1 parent f9a5145 commit 83aac37
Show file tree
Hide file tree
Showing 27 changed files with 1,046 additions and 1,359 deletions.
18 changes: 0 additions & 18 deletions .github/workflows/build-grpc.yaml

This file was deleted.

26 changes: 0 additions & 26 deletions .github/workflows/docker-dev.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ go_init:
clean:
rm -rf bin

protos:
docker build -t protoc-builder ./cmd/signal/grpc/proto && docker run -v $(CURDIR):/workspace protoc-builder protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative cmd/signal/grpc/proto/sfu.proto


build_grpc: go_init
go build -o bin/sfu-grpc $(GO_LDFLAGS) ./cmd/signal/grpc/main.go
Expand Down
2 changes: 1 addition & 1 deletion cmd/signal/allrpc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func main() {
node := server.New(conf.Config, logger)

if gaddr != "" {
go node.ServeGRPC(gaddr)
go node.ServeGRPC(gaddr, cert, key)
}

if jaddr != "" {
Expand Down
27 changes: 3 additions & 24 deletions cmd/signal/allrpc/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,10 @@ import (
"github.com/go-logr/logr"
"github.com/pion/ion-sfu/pkg/middlewares/datachannel"

grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
pb "github.com/pion/ion-sfu/cmd/signal/grpc/proto"
grpcServer "github.com/pion/ion-sfu/cmd/signal/grpc/server"
"github.com/pion/ion-sfu/cmd/signal/grpc/server"
jsonrpcServer "github.com/pion/ion-sfu/cmd/signal/json-rpc/server"
"github.com/pion/ion-sfu/pkg/sfu"
"github.com/prometheus/client_golang/prometheus/promhttp"
"google.golang.org/grpc"
"google.golang.org/grpc/health"
"google.golang.org/grpc/health/grpc_health_v1"

// pprof
_ "net/http/pprof"
Expand Down Expand Up @@ -43,24 +38,8 @@ func New(c sfu.Config, logger logr.Logger) *Server { // Register default middlew
}

// ServeGRPC serve grpc
func (s *Server) ServeGRPC(gaddr string) error {
l, err := net.Listen("tcp", gaddr)
if err != nil {
return err
}

gs := grpc.NewServer(
grpc.StreamInterceptor(grpc_prometheus.StreamServerInterceptor),
)
pb.RegisterSFUServer(gs, grpcServer.NewServer(s.sfu))
grpc_health_v1.RegisterHealthServer(gs, health.NewServer())
s.logger.Info("GRPC Listening", "addr", gaddr)

if err := gs.Serve(l); err != nil {
s.logger.Error(err, "grpc server error")
return err
}
return nil
func (s *Server) ServeGRPC(gaddr, cert, key string) error {
return server.WrapperedGRPCWebServe(s.sfu, gaddr, cert, key)
}

// ServeJSONRPC serve jsonrpc
Expand Down
152 changes: 0 additions & 152 deletions cmd/signal/grpc/grpc-web/main.go

This file was deleted.

37 changes: 14 additions & 23 deletions cmd/signal/grpc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,13 @@ import (
_ "net/http/pprof"
"os"

"github.com/pion/ion-sfu/cmd/signal/grpc/server"
"github.com/pion/ion-sfu/pkg/middlewares/datachannel"

grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
pb "github.com/pion/ion-sfu/cmd/signal/grpc/proto"
"github.com/pion/ion-sfu/cmd/signal/grpc/server"
log "github.com/pion/ion-sfu/pkg/logger"
"github.com/pion/ion-sfu/pkg/sfu"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/spf13/viper"
"google.golang.org/grpc"
"google.golang.org/grpc/health"
"google.golang.org/grpc/health/grpc_health_v1"
)

type grpcConfig struct {
Expand All @@ -42,6 +37,10 @@ var (
verbosityLevel int
paddr string

enableTLS bool
cert string
key string

logger = log.New()
)

Expand All @@ -53,6 +52,9 @@ func showHelp() {
fmt.Printf("Usage:%s {params}\n", os.Args[0])
fmt.Println(" -c {config file}")
fmt.Println(" -a {listen addr}")
fmt.Println(" -tls (enable tls)")
fmt.Println(" -cert {cert file}")
fmt.Println(" -key {key file}")
fmt.Println(" -h (show help info)")
fmt.Println(" -v {0-10} (verbosity level, default 0)")
fmt.Println(" -paddr {pprof listen addr}")
Expand Down Expand Up @@ -101,6 +103,9 @@ func load() bool {
func parse() bool {
flag.StringVar(&file, "c", "config.toml", "config file")
flag.StringVar(&addr, "a", ":50051", "address to use")
flag.BoolVar(&enableTLS, "tls", false, "enable tls")
flag.StringVar(&cert, "cert", "", "cert file")
flag.StringVar(&key, "key", "", "key file")
flag.StringVar(&metricsAddr, "m", ":8100", "merics to use")
flag.IntVar(&verbosityLevel, "v", -1, "verbosity level, higher value - more logs")
flag.StringVar(&paddr, "paddr", "", "pprof listening address")
Expand Down Expand Up @@ -165,22 +170,14 @@ func main() {
logger := log.New()

logger.Info("--- Starting SFU Node ---")
lis, err := net.Listen("tcp", addr)
if err != nil {
logger.Error(err, "failed to listen")
os.Exit(1)
}

if paddr != "" {
go func() {
logger.Info("PProf Listening", "addr", paddr)
_ = http.ListenAndServe(paddr, http.DefaultServeMux)
}()
}

s := grpc.NewServer(
grpc.StreamInterceptor(grpc_prometheus.StreamServerInterceptor),
)
go startMetrics(metricsAddr)

// SFU instance needs to be created with logr implementation
sfu.Logger = logger
Expand All @@ -189,14 +186,8 @@ func main() {
dc := nsfu.NewDatachannel(sfu.APIChannelLabel)
dc.Use(datachannel.SubscriberAPI)

pb.RegisterSFUServer(s, server.NewServer(nsfu))
grpc_health_v1.RegisterHealthServer(s, health.NewServer())
grpc_prometheus.Register(s)

go startMetrics(metricsAddr)

logger.Info("SFU Listening", "addr", addr)
if err := s.Serve(lis); err != nil {
err := server.WrapperedGRPCWebServe(nsfu, addr, cert, key)
if err != nil {
logger.Error(err, "failed to serve SFU")
os.Exit(1)
}
Expand Down
19 changes: 0 additions & 19 deletions cmd/signal/grpc/proto/Dockerfile

This file was deleted.

Loading

0 comments on commit 83aac37

Please sign in to comment.