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

Allow configurable suffixes for handle services for TCP connection reuse #813

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions atproto/identity/base_directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@ type BaseDirectory struct {
SkipDNSDomainSuffixes []string
// set of fallback DNS servers (eg, domain registrars) to try as a fallback. each entry should be "ip:port", eg "8.8.8.8:53"
FallbackDNSServers []string
// Map of well-known suffixes to call the same host for handle resolution, adds a host header for virtual routing
WellKnownSuffixMap WellKnownSuffixMap
}

// WellKnownSuffixMap is a map of well-known suffixes to call the same host for handle resolution, adds a host header for virtual routing
type WellKnownSuffixMap map[string]string

var _ Directory = (*BaseDirectory)(nil)

func (d *BaseDirectory) LookupHandle(ctx context.Context, h syntax.Handle) (*Identity, error) {
Expand Down
15 changes: 14 additions & 1 deletion atproto/identity/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,24 @@ func (d *BaseDirectory) ResolveHandleDNSFallback(ctx context.Context, handle syn
}

func (d *BaseDirectory) ResolveHandleWellKnown(ctx context.Context, handle syntax.Handle) (syntax.DID, error) {
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://%s/.well-known/atproto-did", handle), nil)
// Check for well-known suffixes to route to a specific host
// allowing for reuse of TCP connections for high-traffic providers
requestHost := handle.String()
for suffix, host := range d.WellKnownSuffixMap {
if strings.HasSuffix(handle.String(), suffix) {
requestHost = host
break
}
}

req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://%s/.well-known/atproto-did", requestHost), nil)
if err != nil {
return "", fmt.Errorf("constructing HTTP request for handle resolution: %w", err)
}

// Add host header for virtual routing
req.Header.Set("Host", handle.String())

resp, err := d.HTTPClient.Do(req)
if err != nil {
// check for NXDOMAIN
Expand Down
Loading