Monorepo for Tangled tangled.org
752
fork

Configure Feed

Select the types of activity you want to include in your feed.

knotmirror: add scheme to proxy hosts #2

open opened by boltless.me targeting master from sl/upukwxsowwop
Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:xasnlahkri4ewmbuzly2rlc5/sh.tangled.repo.pull/3mk32wgcc4b22
+35 -17
Diff #0
+20 -15
knotmirror/xrpc/proxy.go
··· 10 10 11 11 12 12 13 + indigoxrpc "github.com/bluesky-social/indigo/xrpc" 14 + "tangled.org/core/api/tangled" 15 + "tangled.org/core/knotmirror/db" 16 + ) 13 17 18 + var mirrorToKnotNSID = map[string]string{ 14 19 15 20 16 21 ··· 38 43 39 44 40 45 41 - 42 - 43 - 44 - 45 - 46 - 47 - 48 - 49 - 50 - 51 - 52 - 53 - 46 + func (x *Xrpc) resolveKnot(ctx context.Context, repoAt syntax.ATURI) (*knotInfo, error) { 47 + repo, err := db.GetRepoByAtUri(ctx, x.db, repoAt) 48 + if err == nil && repo != nil { 49 + knotURL := repo.KnotDomain 50 + if !strings.Contains(repo.KnotDomain, "://") { 51 + if host, _ := db.GetHost(ctx, x.db, repo.KnotDomain); host != nil { 52 + knotURL = host.URL() 53 + } else { 54 + x.logger.Warn("repo is from unknown knot") 55 + if x.cfg.KnotUseSSL { 56 + knotURL = "https://" + knotURL 57 + } else { 58 + knotURL = "http://" + knotURL 54 59 } 55 - }() 60 + } 56 61 } 57 - return &knotInfo{baseURL: repo.KnotDomain, didSlashRepo: repo.DidSlashRepo()}, nil 62 + return &knotInfo{baseURL: knotURL, didSlashRepo: repo.DidSlashRepo()}, nil 58 63 } 59 64 60 65 owner, err := x.resolver.ResolveIdent(ctx, repoAt.Authority().String())
+2 -1
knotmirror/xrpc/git_get_tree.go
··· 21 21 ref = r.URL.Query().Get("ref") // ref can be empty (git.Open handles this) 22 22 path = r.URL.Query().Get("path") // path can be empty (defaults to root) 23 23 ) 24 + l := x.logger.With("method", "git.getTree", "repo", repoQuery, "ref", ref) 24 25 25 26 repo, err := syntax.ParseATURI(repoQuery) 26 27 if err != nil || repo.RecordKey() == "" { ··· 30 31 31 32 out, err := x.getTree(r.Context(), repo, ref, path) 32 33 if err != nil { 33 - x.logger.Warn("local mirror failed, trying proxy", "repo", repo, "err", err) 34 + l.Warn("local mirror failed, trying proxy", "repo", repo, "err", err) 34 35 if x.proxyToKnot(w, r, repo) { 35 36 return 36 37 }
+1 -1
knotmirror/xrpc/git_list_languages.go
··· 18 18 repoQuery = r.URL.Query().Get("repo") 19 19 ref = r.URL.Query().Get("ref") 20 20 ) 21 - l := x.logger.With("repo", repoQuery, "ref", ref) 21 + l := x.logger.With("method", "git.listLanguages", "repo", repoQuery, "ref", ref) 22 22 23 23 repo, err := syntax.ParseATURI(repoQuery) 24 24 if err != nil || repo.RecordKey() == "" {
+5
knotmirror/models/models.go
··· 2 2 3 3 import ( 4 4 "fmt" 5 + "strings" 5 6 6 7 "github.com/bluesky-social/indigo/atproto/syntax" 7 8 "tangled.org/core/api/tangled" ··· 23 24 RetryAfter int64 // Unix timestamp (seconds) 24 25 } 25 26 27 + func (r *Repo) KnotHostname() string { 28 + return strings.TrimPrefix(strings.TrimPrefix(r.KnotDomain, "https"), "http") 29 + } 30 + 26 31 func (r *Repo) AtUri() syntax.ATURI { 27 32 return syntax.ATURI(fmt.Sprintf("at://%s/%s/%s", r.Did, tangled.RepoNSID, r.Rkey)) 28 33 }
+7
knotmirror/resyncer.go
··· 219 219 return false, nil 220 220 } 221 221 222 + // fail early if target knot is offline. 223 + if host, _ := db.GetHost(ctx, r.db, repo.KnotHostname()); host != nil { 224 + if host.Status != models.HostStatusActive { 225 + return false, nil 226 + } 227 + } 228 + 222 229 // HACK: check knot reachability with short timeout before running actual fetch. 223 230 // This is crucial as git-cli doesn't support http connection timeout. 224 231 // `http.lowSpeedTime` is only applied _after_ the connection.

History

1 round 0 comments
sign up or login to add to the discussion
boltless.me submitted #0
4 commits
expand
knotmirror: add scheme to proxy hosts
knotmirror/xrpc: don't schedule pending on xrpc failure
knotmirror/xrpc: log with xrpc method name
knotmirror: fail early if target knot is offline
no conflicts, ready to merge
expand 0 comments