@@ -24,6 +24,7 @@ import (
2424 "github.com/livepeer/go-livepeer/eth"
2525 "github.com/livepeer/go-livepeer/eth/types"
2626 "github.com/livepeer/go-livepeer/monitor"
27+ "github.com/livepeer/go-livepeer/net"
2728 "github.com/livepeer/go-livepeer/pm"
2829 "github.com/livepeer/lpms/ffmpeg"
2930 "github.com/pkg/errors"
@@ -400,6 +401,67 @@ func (s *LivepeerServer) getSessionPoolInfoHandler() http.Handler {
400401
401402}
402403
404+ type orchInfoResponse struct {
405+ OrchInfo * net.OrchestratorInfo `json:"orchestrator_info"`
406+ Status string `json:"status"`
407+ Took int64 `json:"took_ms"`
408+ }
409+
410+ func (s * LivepeerServer ) getOrchestratorInfoHandler () http.Handler {
411+ return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
412+ if s .LivepeerNode .NodeType == core .BroadcasterNode {
413+ //create GetOrchestrator request
414+ b := core .NewBroadcaster (s .LivepeerNode )
415+ b_sig , err := b .Sign ([]byte (fmt .Sprintf ("%v" , b .Address ().Hex ())))
416+ if err != nil {
417+ respond500 (w , "could not create sig" )
418+ return
419+ }
420+ req := & net.OrchestratorRequest {Address : b .Address ().Bytes (), Sig : b_sig }
421+ //send GetOrchestrator request
422+ orch_url := r .Header .Get ("Url" )
423+ if orch_url != "" {
424+ url , err := url .ParseRequestURI (orch_url )
425+ if err != nil {
426+ respond400 (w , "could not parse url" )
427+ return
428+ }
429+ orchInfoResp := orchInfoResponse {}
430+
431+ client , conn , err := startOrchestratorClient (context .Background (), url )
432+ defer conn .Close ()
433+ if conn != nil && err == nil {
434+ start := time .Now ()
435+ orch_info , err := client .GetOrchestrator (context .Background (), req )
436+ if err != nil {
437+ orchInfoResp .Status = "failed"
438+ orchInfoResp .Took = time .Since (start ).Milliseconds ()
439+ glog .Errorf ("getorchestrator request failed: %v" , err )
440+ respondJson (w , orchInfoResp )
441+ return
442+ }
443+ //parse net.OrchestratorInfo to json
444+ orchInfoResp .Status = "success"
445+ orchInfoResp .Took = time .Since (start ).Milliseconds ()
446+ orchInfoResp .OrchInfo = orch_info
447+ //send orchestrator info received
448+ respondJson (w , orchInfoResp )
449+ return
450+ } else {
451+ respond500 (w , "getorchestrator request failed: " + err .Error ())
452+ return
453+ }
454+ } else {
455+ respond400 (w , "url not provided" )
456+ return
457+ }
458+ } else {
459+ respond400 (w , "not broadcaster node" )
460+ return
461+ }
462+ })
463+ }
464+
403465// Rounds
404466func currentRoundHandler (client eth.LivepeerEthClient ) http.Handler {
405467 return mustHaveClient (client , http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
0 commit comments