Skip to content
This repository has been archived by the owner on Dec 2, 2023. It is now read-only.

Commit

Permalink
[WIP] Adjust architecture (#553)
Browse files Browse the repository at this point in the history
* Minor fix.

* fix lint errors.

* Refactor business logic.

* Separate business logic and signaling.
  - Support custom business logic node.
  - Add JWT support.

* Remove FindNode from islb.proto.

* Move the jwt directory to signal.

* Move biz(conference server) to /apps.

* Add node id to config.

* golangci-lint fix.

* update.

* Support disconnection detection using service discovery.

* Update.

* Upgrade nats-discovery to v0.3.0.

* Improve directory structure.

* update.

* golangci-lint.

* update.

* update nats-grpc.
  • Loading branch information
cloudwebrtc authored Jun 18, 2021
1 parent 62cb04f commit e141bff
Show file tree
Hide file tree
Showing 59 changed files with 2,920 additions and 1,156 deletions.
27 changes: 18 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ clean:

go_deps:
go mod download
go generate ./...

build: go_deps
go build -o bin/biz $(GO_LDFLAGS) cmd/biz/main.go
go build -o bin/app-biz $(GO_LDFLAGS) apps/biz/main.go
go build -o bin/islb $(GO_LDFLAGS) cmd/islb/main.go
go build -o bin/sfu $(GO_LDFLAGS) cmd/sfu/main.go
go build -o bin/avp $(GO_LDFLAGS) cmd/avp/main.go
go build -o bin/signal $(GO_LDFLAGS) cmd/signal/main.go

start-bin:

start-services:
Expand All @@ -36,11 +37,19 @@ test: go_deps start-services
-timeout 120s \
-coverpkg=${GO_COVERPKGS} -coverprofile=cover.out -covermode=atomic \
-v -race ${GO_TESTPKGS}
proto:
docker build -t protoc-builder ./protos && \
docker run -v $(CURDIR):/workspace protoc-builder \
protoc \
--go_opt=module=github.com/pion/ion --go_out=. \
--go-grpc_opt=module=github.com/pion/ion --go-grpc_out=. \
protos/*.proto

proto-gen-from-docker:
docker build -t go-protoc ./proto
docker run -v $(CURDIR):/workspace go-protoc proto

proto: proto_ion proto_biz

proto_ion:
protoc proto/ion/ion.proto --go_opt=module=github.com/pion/ion --go_out=. --go-grpc_opt=module=github.com/pion/ion --go-grpc_out=.
protoc proto/debug/debug.proto --experimental_allow_proto3_optional --go_opt=module=github.com/pion/ion --go_out=. --go-grpc_opt=module=github.com/pion/ion --go-grpc_out=.
protoc proto/sfu/sfu.proto --go_opt=module=github.com/pion/ion --go_out=. --go-grpc_opt=module=github.com/pion/ion --go-grpc_out=.
protoc proto/islb/islb.proto --go_opt=module=github.com/pion/ion --go_out=. --go-grpc_opt=module=github.com/pion/ion --go-grpc_out=.
protoc proto/rtc/rtc.proto --go_opt=module=github.com/pion/ion --go_out=. --go-grpc_opt=module=github.com/pion/ion --go-grpc_out=.

proto_biz:
protoc apps/biz/proto/biz.proto --go_opt=module=github.com/pion/ion --go_out=. --go-grpc_opt=module=github.com/pion/ion --go-grpc_out=.
8 changes: 8 additions & 0 deletions apps/biz/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package main

// ============================================================================
// GO
// ============================================================================
// GRPC & Protobuf
//go:generate /usr/bin/env bash -c "echo 'Generating [biz] protobuf and grpc services for Go, outdir=$OUTDIR'"
//go:generate protoc ./proto/biz.proto -I./proto -I../../ --go_opt=module=github.com/pion/ion --go_out=../../$OUTDIR --go-grpc_opt=module=github.com/pion/ion --go-grpc_out=../../$OUTDIR
90 changes: 90 additions & 0 deletions apps/biz/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Package cmd contains an entrypoint for running an ion-sfu instance.
package main

import (
"flag"
"fmt"
"os"

log "github.com/pion/ion-log"
biz "github.com/pion/ion/apps/biz/server"
"github.com/spf13/viper"
)

var (
conf = biz.Config{}
file string
)

func showHelp() {
fmt.Printf("Usage:%s {params}\n", os.Args[0])
fmt.Println(" -c {config file}")
fmt.Println(" -h (show help info)")
}

func unmarshal(rawVal interface{}) bool {
if err := viper.Unmarshal(rawVal); err != nil {
fmt.Printf("config file %s loaded failed. %v\n", file, err)
return false
}
return true
}

func load() bool {
_, err := os.Stat(file)
if err != nil {
return false
}

viper.SetConfigFile(file)
viper.SetConfigType("toml")

err = viper.ReadInConfig()
if err != nil {
fmt.Printf("config file %s read failed. %v\n", file, err)
return false
}

if !unmarshal(&conf) {
return false
}
if err != nil {
fmt.Printf("config file %s loaded failed. %v\n", file, err)
return false
}

fmt.Printf("config %s load ok!\n", file)

return true
}

func parse() bool {
flag.StringVar(&file, "c", "configs/biz.toml", "config file")
help := flag.Bool("h", false, "help info")
flag.Parse()
if !load() {
return false
}

if *help {
showHelp()
return false
}
return true
}

func main() {
if !parse() {
showHelp()
os.Exit(-1)
}
log.Init(conf.Log.Level)
log.Infof("--- Starting Biz Node ---")
node := biz.NewBIZ(conf.Node.NID)
if err := node.Start(conf); err != nil {
log.Errorf("biz init start: %v", err)
os.Exit(-1)
}
defer node.Close()
select {}
}
Loading

0 comments on commit e141bff

Please sign in to comment.