Skip to content

Commit

Permalink
update ports to be different for B / O / T (livepeer#2850)
Browse files Browse the repository at this point in the history
  • Loading branch information
ad-astra-video authored and eliteprox committed Feb 21, 2024
1 parent de8227b commit ac42df2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
36 changes: 22 additions & 14 deletions cmd/livepeer/starter/starter.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ var (
smTTL = 60 // 1 minute
)

const RTMPPort = "1935"
const RPCPort = "8935"
const CliPort = "7935"
const BroadcasterRpcPort = "9935"
const BroadcasterCliPort = "5935"
const BroadcasterRtmpPort = "1935"
const OrchestratorRpcPort = "8935"
const OrchestratorCliPort = "7935"
const TranscoderCliPort = "6935"

type LivepeerConfig struct {
Network *string
Expand Down Expand Up @@ -135,8 +138,8 @@ type LivepeerConfig struct {
func DefaultLivepeerConfig() LivepeerConfig {
// Network & Addresses:
defaultNetwork := "offchain"
defaultRtmpAddr := "127.0.0.1:" + RTMPPort
defaultCliAddr := "127.0.0.1:" + CliPort
defaultRtmpAddr := ""
defaultCliAddr := ""
defaultHttpAddr := ""
defaultServiceAddr := ""
defaultOrchAddr := ""
Expand Down Expand Up @@ -782,7 +785,7 @@ func StartLivepeer(ctx context.Context, cfg LivepeerConfig) {

var sm pm.SenderMonitor
if *cfg.RedeemerAddr != "" {
*cfg.RedeemerAddr = defaultAddr(*cfg.RedeemerAddr, "127.0.0.1", RPCPort)
*cfg.RedeemerAddr = defaultAddr(*cfg.RedeemerAddr, "127.0.0.1", OrchestratorRpcPort)
rc, err := server.NewRedeemerClient(*cfg.RedeemerAddr, senderWatcher, timeWatcher)
if err != nil {
glog.Error("Unable to start redeemer client: ", err)
Expand Down Expand Up @@ -878,7 +881,7 @@ func StartLivepeer(ctx context.Context, cfg LivepeerConfig) {
return
}

*cfg.HttpAddr = defaultAddr(*cfg.HttpAddr, "127.0.0.1", RPCPort)
*cfg.HttpAddr = defaultAddr(*cfg.HttpAddr, "127.0.0.1", OrchestratorRpcPort)
url, err := url.ParseRequestURI("https://" + *cfg.HttpAddr)
if err != nil {
glog.Error("Could not parse redeemer URI: ", err)
Expand Down Expand Up @@ -1020,8 +1023,9 @@ func StartLivepeer(ctx context.Context, cfg LivepeerConfig) {
if n.NodeType == core.BroadcasterNode {
// default lpms listener for broadcaster; same as default rpc port
// TODO provide an option to disable this?
*cfg.RtmpAddr = defaultAddr(*cfg.RtmpAddr, "127.0.0.1", RTMPPort)
*cfg.HttpAddr = defaultAddr(*cfg.HttpAddr, "127.0.0.1", RPCPort)
*cfg.RtmpAddr = defaultAddr(*cfg.RtmpAddr, "127.0.0.1", BroadcasterRtmpPort)
*cfg.HttpAddr = defaultAddr(*cfg.HttpAddr, "127.0.0.1", BroadcasterRpcPort)
*cfg.CliAddr = defaultAddr(*cfg.CliAddr, "127.0.0.1", BroadcasterCliPort)

bcast := core.NewBroadcaster(n)

Expand Down Expand Up @@ -1105,6 +1109,8 @@ func StartLivepeer(ctx context.Context, cfg LivepeerConfig) {
server.SelectRandFreq = *cfg.SelectRandFreq

} else if n.NodeType == core.OrchestratorNode {
*cfg.CliAddr = defaultAddr(*cfg.CliAddr, "127.0.0.1", OrchestratorCliPort)

suri, err := getServiceURI(n, *cfg.ServiceAddr)
if err != nil {
glog.Fatal("Error getting service URI: ", err)
Expand All @@ -1116,9 +1122,11 @@ func StartLivepeer(ctx context.Context, cfg LivepeerConfig) {
if !*cfg.Transcoder && n.OrchSecret == "" {
glog.Fatal("Running an orchestrator requires an -orchSecret for standalone mode or -transcoder for orchestrator+transcoder mode")
}
} else if n.NodeType == core.TranscoderNode {
*cfg.CliAddr = defaultAddr(*cfg.CliAddr, "127.0.0.1", TranscoderCliPort)
}

n.Capabilities = core.NewCapabilities(transcoderCaps, core.MandatoryOCapabilities())
*cfg.CliAddr = defaultAddr(*cfg.CliAddr, "127.0.0.1", CliPort)

if drivers.NodeStorage == nil {
// base URI will be empty for broadcasters; that's OK
Expand Down Expand Up @@ -1163,7 +1171,6 @@ func StartLivepeer(ctx context.Context, cfg LivepeerConfig) {
glog.Info("Current ManifestID will be available over ", *cfg.HttpAddr)
s.ExposeCurrentManifest = *cfg.CurrentManifest
}

srv := &http.Server{Addr: *cfg.CliAddr}
go func() {
s.StartCliWebserver(srv)
Expand Down Expand Up @@ -1256,7 +1263,7 @@ func parseOrchAddrs(addrs string) []*url.URL {
if len(addrs) > 0 {
for _, addr := range strings.Split(addrs, ",") {
addr = strings.TrimSpace(addr)
addr = defaultAddr(addr, "127.0.0.1", RPCPort)
addr = defaultAddr(addr, "127.0.0.1", OrchestratorRpcPort)
if !strings.HasPrefix(addr, "http") {
addr = "https://" + addr
}
Expand Down Expand Up @@ -1332,7 +1339,7 @@ func getServiceURI(n *core.LivepeerNode, serviceAddr string) (*url.URL, error) {
glog.Errorf("Could not look up public IP err=%q", err)
return nil, err
}
addr := "https://" + strings.TrimSpace(string(body)) + ":" + RPCPort
addr := "https://" + strings.TrimSpace(string(body)) + ":" + OrchestratorRpcPort
inferredUri, err := url.ParseRequestURI(addr)
if err != nil {
glog.Errorf("Could not look up public IP err=%q", err)
Expand All @@ -1352,7 +1359,7 @@ func getServiceURI(n *core.LivepeerNode, serviceAddr string) (*url.URL, error) {
ethUri, err := url.ParseRequestURI(addr)
if err != nil {
glog.Errorf("Could not parse service URI; orchestrator may be unreachable err=%q", err)
ethUri, _ = url.ParseRequestURI("http://127.0.0.1:" + RPCPort)
ethUri, _ = url.ParseRequestURI("http://127.0.0.1:" + OrchestratorRpcPort)
}
if ethUri.Hostname() != inferredUri.Hostname() || ethUri.Port() != inferredUri.Port() {
glog.Errorf("Service address %v did not match discovered address %v; set the correct address in livepeer_cli or use -serviceAddr", ethUri, inferredUri)
Expand Down Expand Up @@ -1389,6 +1396,7 @@ func defaultAddr(addr, defaultHost, defaultPort string) string {
if addr == "" {
return defaultHost + ":" + defaultPort
}

if addr[0] == ':' {
return defaultHost + addr
}
Expand Down
22 changes: 11 additions & 11 deletions test_args.sh
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ $TMPDIR/livepeer -broadcaster -maxSessions 0 || res=$?

# Check that pprof is running on CLI port
run_lp -broadcaster
curl -sI http://127.0.0.1:7935/debug/pprof/allocs | grep "200 OK"
curl -sI http://127.0.0.1:5935/debug/pprof/allocs | grep "200 OK"
kill $pid

# exit early if verifier URL is not http
Expand All @@ -223,55 +223,55 @@ kill $pid

# Check that HTTP ingest is disabled when -httpAddr is publicly accessible and there is no auth webhook URL and -httpIngest defaults to false
run_lp -broadcaster -httpAddr 0.0.0.0
curl -X PUT http://localhost:8935/live/movie/0.ts | grep "404 page not found"
curl -X PUT http://localhost:9935/live/movie/0.ts | grep "404 page not found"
kill $pid

# Check that HTTP ingest is disabled when -httpAddr is not publicly accessible and -httpIngest is set to false
run_lp -broadcaster -httpIngest=false
curl -X PUT http://localhost:8935/live/movie/0.ts | grep "404 page not found"
curl -X PUT http://localhost:9935/live/movie/0.ts | grep "404 page not found"
kill $pid

# Check that HTTP ingest is disabled when -httpAddr is publicly accessible and there is a auth webhook URL and -httpIngest is set to false
run_lp -broadcaster -httpAddr 0.0.0.0 -authWebhookUrl http://foo.com -httpIngest=false
curl -X PUT http://localhost:8935/live/movie/0.ts | grep "404 page not found"
curl -X PUT http://localhost:9935/live/movie/0.ts | grep "404 page not found"
kill $pid

# Check that HTTP ingest is enabled when -httpIngest is true
run_lp -broadcaster -httpAddr 0.0.0.0 -httpIngest
curl -X PUT http://localhost:8935/live/movie/0.ts | grep -v "404 page not found"
curl -X PUT http://localhost:9935/live/movie/0.ts | grep -v "404 page not found"
kill $pid

# Check that HTTP ingest is enabled when -httpAddr sets the hostname to 127.0.0.1
run_lp -broadcaster -httpAddr 127.0.0.1
curl -X PUT http://localhost:8935/live/movie/0.ts | grep -v "404 page not found"
curl -X PUT http://localhost:9935/live/movie/0.ts | grep -v "404 page not found"
kill $pid

# Check that HTTP ingest is enabled when -httpAddr sets the hostname to localhost
run_lp -broadcaster -httpAddr localhost
curl -X PUT http://localhost:8935/live/movie/0.ts | grep -v "404 page not found"
curl -X PUT http://localhost:9935/live/movie/0.ts | grep -v "404 page not found"
kill $pid

# Check that HTTP ingest is enabled when there is an auth webhook URL
run_lp -broadcaster -httpAddr 0.0.0.0 -authWebhookUrl http://foo.com
curl -X PUT http://localhost:8935/live/movie/0.ts | grep -v "404 page not found"
curl -X PUT http://localhost:9935/live/movie/0.ts | grep -v "404 page not found"
kill $pid

# Check that the default presets are used
run_lp -broadcaster
curl -s --stderr - http://localhost:7935/getBroadcastConfig | grep P240p30fps16x9,P360p30fps16x9
curl -s --stderr - http://localhost:5935/getBroadcastConfig | grep P240p30fps16x9,P360p30fps16x9
kill $pid

# Check that the presets passed in are used
run_lp -broadcaster -transcodingOptions P144p30fps16x9,P720p30fps16x9
curl -s --stderr - http://localhost:7935/getBroadcastConfig | grep P144p30fps16x9,P720p30fps16x9
curl -s --stderr - http://localhost:5935/getBroadcastConfig | grep P144p30fps16x9,P720p30fps16x9
kill $pid

# Check that config file profiles passed in are used
cat >$TMPDIR/profile.json <<PROFILE_JSON
[{"name":"abc","width":1,"height":2},{"name":"def","width":1,"height":2}]
PROFILE_JSON
run_lp -broadcaster -transcodingOptions $TMPDIR/profile.json
curl -s --stderr - http://localhost:7935/getBroadcastConfig | grep abc,def
curl -s --stderr - http://localhost:5935/getBroadcastConfig | grep abc,def
kill $pid

# Check nonexistent profile config file
Expand Down

0 comments on commit ac42df2

Please sign in to comment.