Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove deadcode (2025-03-03) #972

Merged
merged 8 commits into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 0 additions & 122 deletions bgs/bgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,25 @@ package bgs
import (
"context"
"database/sql"
"encoding/json"
"errors"
"fmt"
"log/slog"
"net"
"net/http"
_ "net/http/pprof"
"net/url"
"reflect"
"strconv"
"strings"
"sync"
"time"

"contrib.go.opencensus.io/exporter/prometheus"
"github.com/bluesky-social/indigo/api"
atproto "github.com/bluesky-social/indigo/api/atproto"
comatproto "github.com/bluesky-social/indigo/api/atproto"
"github.com/bluesky-social/indigo/carstore"
"github.com/bluesky-social/indigo/did"
"github.com/bluesky-social/indigo/events"
"github.com/bluesky-social/indigo/indexer"
lexutil "github.com/bluesky-social/indigo/lex/util"
"github.com/bluesky-social/indigo/models"
"github.com/bluesky-social/indigo/repomgr"
"github.com/bluesky-social/indigo/xrpc"
Expand All @@ -34,7 +30,6 @@ import (
"golang.org/x/time/rate"

"github.com/gorilla/websocket"
"github.com/ipfs/go-cid"
ipld "github.com/ipfs/go-ipld-format"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
Expand Down Expand Up @@ -207,95 +202,6 @@ func (bgs *BGS) StartMetrics(listen string) error {
return http.ListenAndServe(listen, nil)
}

// Disabled for now, maybe reimplement behind admin auth later
func (bgs *BGS) StartDebug(listen string) error {
http.HandleFunc("/repodbg/user", func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
did := r.FormValue("did")

u, err := bgs.Index.LookupUserByDid(ctx, did)
if err != nil {
http.Error(w, err.Error(), 400)
return
}

root, err := bgs.repoman.GetRepoRoot(ctx, u.Uid)
if err != nil {
http.Error(w, err.Error(), 400)
return
}

out := map[string]any{
"root": root.String(),
"actorInfo": u,
}

if r.FormValue("carstore") != "" {
stat, err := bgs.repoman.CarStore().Stat(ctx, u.Uid)
if err != nil {
http.Error(w, err.Error(), 400)
return
}
out["carstore"] = stat
}

json.NewEncoder(w).Encode(out)
})
http.HandleFunc("/repodbg/crawl", func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
did := r.FormValue("did")

act, err := bgs.Index.GetUserOrMissing(ctx, did)
if err != nil {
w.WriteHeader(500)
bgs.log.Error("failed to get user", "err", err)
return
}

if err := bgs.Index.Crawler.Crawl(ctx, act); err != nil {
w.WriteHeader(500)
bgs.log.Error("failed to add user to crawler", "err", err)
return
}
})
http.HandleFunc("/repodbg/blocks", func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
did := r.FormValue("did")
c := r.FormValue("cid")

bcid, err := cid.Decode(c)
if err != nil {
http.Error(w, err.Error(), 400)
return
}

cs := bgs.repoman.CarStore()

u, err := bgs.Index.LookupUserByDid(ctx, did)
if err != nil {
http.Error(w, err.Error(), 400)
return
}

bs, err := cs.ReadOnlySession(u.Uid)
if err != nil {
http.Error(w, err.Error(), 400)
return
}

blk, err := bs.Get(ctx, bcid)
if err != nil {
http.Error(w, err.Error(), 400)
return
}

w.WriteHeader(200)
w.Write(blk.RawData())
})

return http.ListenAndServe(listen, nil)
}

func (bgs *BGS) Start(addr string) error {
var lc net.ListenConfig
ctx, cancel := context.WithTimeout(context.Background(), serverListenerBootTimeout)
Expand Down Expand Up @@ -761,26 +667,6 @@ func (bgs *BGS) EventsHandler(c echo.Context) error {
}
}

func prometheusHandler() http.Handler {
// Prometheus globals are exposed as interfaces, but the prometheus
// OpenCensus exporter expects a concrete *Registry. The concrete type of
// the globals are actually *Registry, so we downcast them, staying
// defensive in case things change under the hood.
registry, ok := promclient.DefaultRegisterer.(*promclient.Registry)
if !ok {
slog.Warn("failed to export default prometheus registry; some metrics will be unavailable; unexpected type", "type", reflect.TypeOf(promclient.DefaultRegisterer))
}
exporter, err := prometheus.NewExporter(prometheus.Options{
Registry: registry,
Namespace: "bigsky",
})
if err != nil {
slog.Error("could not create the prometheus stats exporter", "err", err, "system", "bgs")
}

return exporter
}

// domainIsBanned checks if the given host is banned, starting with the host
// itself, then checking every parent domain up to the tld
func (s *BGS) domainIsBanned(ctx context.Context, host string) (bool, error) {
Expand Down Expand Up @@ -867,14 +753,6 @@ func (bgs *BGS) lookupUserByUID(ctx context.Context, uid models.Uid) (*User, err
return &u, nil
}

func stringLink(lnk *lexutil.LexLink) string {
if lnk == nil {
return "<nil>"
}

return lnk.String()
}

func (bgs *BGS) handleFedEvent(ctx context.Context, host *models.PDS, env *events.XRPCStreamEvent) error {
ctx, span := tracer.Start(ctx, "handleFedEvent")
defer span.End()
Expand Down
15 changes: 0 additions & 15 deletions bgs/stubs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,6 @@ type XRPCError struct {
Message string `json:"message"`
}

func (s *BGS) RegisterHandlersAppBsky(e *echo.Echo) error {
return nil
}

func (s *BGS) RegisterHandlersComAtproto(e *echo.Echo) error {
e.GET("/xrpc/com.atproto.sync.getBlocks", s.HandleComAtprotoSyncGetBlocks)
e.GET("/xrpc/com.atproto.sync.getLatestCommit", s.HandleComAtprotoSyncGetLatestCommit)
e.GET("/xrpc/com.atproto.sync.getRecord", s.HandleComAtprotoSyncGetRecord)
e.GET("/xrpc/com.atproto.sync.getRepo", s.HandleComAtprotoSyncGetRepo)
e.GET("/xrpc/com.atproto.sync.listRepos", s.HandleComAtprotoSyncListRepos)
e.POST("/xrpc/com.atproto.sync.notifyOfUpdate", s.HandleComAtprotoSyncNotifyOfUpdate)
e.POST("/xrpc/com.atproto.sync.requestCrawl", s.HandleComAtprotoSyncRequestCrawl)
return nil
}

func (s *BGS) HandleComAtprotoSyncGetBlocks(c echo.Context) error {
ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoSyncGetBlocks")
defer span.End()
Expand Down
60 changes: 0 additions & 60 deletions events/repostream.go

This file was deleted.

20 changes: 0 additions & 20 deletions pds/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,3 @@ func (s *Server) createAuthTokenForUser(ctx context.Context, handle, did string)
Did: did,
}, nil
}

func (s *Server) createCrossServerAuthToken(ctx context.Context, otherpds string) (*xrpc.AuthInfo, error) {
accessTok := makeToken(otherpds, "com.atproto.federation", time.Now().Add(24*time.Hour))

// setting this is a little weird,
// since the token isn't signed by this key, we dont have a way to validate...
accessTok.Set("pds", s.signingKey.Public().DID())

rval := make([]byte, 10)
rand.Read(rval)

accSig, err := jwt.Sign(accessTok, jwt.WithKey(jwa.HS256, s.jwtSigningKey))
if err != nil {
return nil, err
}

return &xrpc.AuthInfo{
AccessJwt: string(accSig),
}, nil
}
Loading
Loading