<commit_before>package server

import (
	"encoding/json"

	"flag"
	"fmt"
	"math/big"
	"net/http"
	"net/url"
	"regexp"
	"strconv"
	"strings"
	"time"

	// pprof adds handlers to default mux via `init()`
	_ "net/http/pprof"

	"github.com/cenkalti/backoff"
	"github.com/ethereum/go-ethereum/common"
	"github.com/ethereum/go-ethereum/core/types"
	"github.com/golang/glog"
	lpcommon "github.com/livepeer/go-livepeer/common"
	"github.com/livepeer/go-livepeer/core"
	"github.com/livepeer/go-livepeer/eth"
	lpTypes "github.com/livepeer/go-livepeer/eth/types"
	"github.com/livepeer/go-livepeer/monitor"
	ffmpeg "github.com/livepeer/lpms/ffmpeg"
	"github.com/pkg/errors"
)

var vFlag *glog.Level = flag.Lookup("v").Value.(*glog.Level)

func (s *LivepeerServer) setServiceURI(serviceURI string) error {

	parsedURI, err := url.Parse(serviceURI)
	if err != nil {
		glog.Error(err)
		return err
	}

	glog.Infof("Storing service URI %v in service registry...", serviceURI)

	tx, err := s.LivepeerNode.Eth.SetServiceURI(serviceURI)
	if err != nil {
		glog.Error(err)
		return err
	}

	err = s.LivepeerNode.Eth.CheckTx(tx)
	if err != nil {
		glog.Error(err)
		return err
	}

	// Avoids a restart if only the host has been changed.
	// If the port has been changed, a restart is still needed.
	s.LivepeerNode.SetServiceURI(parsedURI)

	return nil
}

// StartCliWebserver starts web server for CLI
// blocks until exit
func (s *LivepeerServer) StartCliWebserver(bindAddr string) {
	mux := s.cliWebServerHandlers(bindAddr)
	srv := &http.Server{
		Addr:    bindAddr,
		Handler: mux,
	}

	glog.Info("CLI server listening on ", bindAddr)
	srv.ListenAndServe()<commit_msg>capture and log error on webserver crash<commit_after>package server

import (
	"encoding/json"

	"flag"
	"fmt"
	"math/big"
	"net/http"
	"net/url"
	"regexp"
	"strconv"
	"strings"
	"time"

	// pprof adds handlers to default mux via `init()`
	_ "net/http/pprof"

	"github.com/cenkalti/backoff"
	"github.com/ethereum/go-ethereum/common"
	"github.com/ethereum/go-ethereum/core/types"
	"github.com/golang/glog"
	lpcommon "github.com/livepeer/go-livepeer/common"
	"github.com/livepeer/go-livepeer/core"
	"github.com/livepeer/go-livepeer/eth"
	lpTypes "github.com/livepeer/go-livepeer/eth/types"
	"github.com/livepeer/go-livepeer/monitor"
	ffmpeg "github.com/livepeer/lpms/ffmpeg"
	"github.com/pkg/errors"
)

var vFlag *glog.Level = flag.Lookup("v").Value.(*glog.Level)

func (s *LivepeerServer) setServiceURI(serviceURI string) error {

	parsedURI, err := url.Parse(serviceURI)
	if err != nil {
		glog.Error(err)
		return err
	}

	glog.Infof("Storing service URI %v in service registry...", serviceURI)

	tx, err := s.LivepeerNode.Eth.SetServiceURI(serviceURI)
	if err != nil {
		glog.Error(err)
		return err
	}

	err = s.LivepeerNode.Eth.CheckTx(tx)
	if err != nil {
		glog.Error(err)
		return err
	}

	// Avoids a restart if only the host has been changed.
	// If the port has been changed, a restart is still needed.
	s.LivepeerNode.SetServiceURI(parsedURI)

	return nil
}

// StartCliWebserver starts web server for CLI
// blocks until exit
func (s *LivepeerServer) StartCliWebserver(bindAddr string) {
	mux := s.cliWebServerHandlers(bindAddr)
	srv := &http.Server{
		Addr:    bindAddr,
		Handler: mux,
	}

	glog.Info("CLI server listening on ", bindAddr)
	err := srv.ListenAndServe()
	glog.Error(err)
{'fraction_non_alphanumeric': 0.1377352853301464, 'fraction_numerical': 0.0, 'mean_word_length': 4.027027027027027, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5588834', 'n_tokens_mistral': 1347, 'n_tokens_neox': 1296, 'n_words': 271}