Skip to content
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
2 changes: 1 addition & 1 deletion blossomMigration.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func migrateBlossomMetadata(ctx context.Context, bl *blossom.BlossomServer) {
// Create a temporary Blossom dbWrapper for the migration
outboxDBWrapper := blossom.EventStoreBlobIndexWrapper{Store: outboxDB, ServiceURL: "https://" + config.RelayURL}
outboxDBWrapper := blossom.EventStoreBlobIndexWrapper{Store: outboxDB, ServiceURL: getHTTPScheme(config.RelayURL) + config.RelayURL}

// List all BlobDescriptor for the relay owner pubkey
ownerPubkey := nPubToPubkey(config.OwnerNpub)
Expand Down
37 changes: 28 additions & 9 deletions init.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"log/slog"
"net/http"
"strings"
"text/template"
"time"

Expand All @@ -17,6 +18,24 @@ import (
"github.com/nbd-wtf/go-nostr"
)

// getHTTPScheme returns the appropriate HTTP scheme based on the URL.
// Returns "http://" for .onion domains (Tor), "https://" for regular domains.
func getHTTPScheme(url string) string {
if strings.Contains(url, ".onion") {
return "http://"
}
return "https://"
}

// getWSScheme returns the appropriate WebSocket scheme based on the URL.
// Returns "ws://" for .onion domains (Tor), "wss://" for regular domains.
func getWSScheme(url string) string {
if strings.Contains(url, ".onion") {
return "ws://"
}
return "wss://"
}

var (
privateRelay = khatru.NewRelay()
privateDB = newDBBackend("db/private")
Expand Down Expand Up @@ -111,7 +130,7 @@ func initRelays(ctx context.Context) {
privateRelay.Info.Icon = config.PrivateRelayIcon
privateRelay.Info.Version = config.RelayVersion
privateRelay.Info.Software = config.RelaySoftware
privateRelay.ServiceURL = "https://" + config.RelayURL + "/private"
privateRelay.ServiceURL = getHTTPScheme(config.RelayURL) + config.RelayURL + "/private"

if !privateRelayLimits.AllowEmptyFilters {
privateRelay.RejectFilter = append(privateRelay.RejectFilter, policies.NoEmptyFilters)
Expand Down Expand Up @@ -160,7 +179,7 @@ func initRelays(ctx context.Context) {
RelayName: config.PrivateRelayName,
RelayPubkey: nPubToPubkey(config.PrivateRelayNpub),
RelayDescription: config.PrivateRelayDescription,
RelayURL: "wss://" + config.RelayURL + "/private",
RelayURL: getWSScheme(config.RelayURL) + config.RelayURL + "/private",
}
err := tmpl.Execute(w, data)
if err != nil {
Expand All @@ -174,7 +193,7 @@ func initRelays(ctx context.Context) {
chatRelay.Info.Icon = config.ChatRelayIcon
chatRelay.Info.Version = config.RelayVersion
chatRelay.Info.Software = config.RelaySoftware
chatRelay.ServiceURL = "https://" + config.RelayURL + "/chat"
chatRelay.ServiceURL = getHTTPScheme(config.RelayURL) + config.RelayURL + "/chat"

if !chatRelayLimits.AllowEmptyFilters {
chatRelay.RejectFilter = append(chatRelay.RejectFilter, policies.NoEmptyFilters)
Expand Down Expand Up @@ -225,7 +244,7 @@ func initRelays(ctx context.Context) {
RelayName: config.ChatRelayName,
RelayPubkey: nPubToPubkey(config.ChatRelayNpub),
RelayDescription: config.ChatRelayDescription,
RelayURL: "wss://" + config.RelayURL + "/chat",
RelayURL: getWSScheme(config.RelayURL) + config.RelayURL + "/chat",
}
err := tmpl.Execute(w, data)
if err != nil {
Expand All @@ -239,7 +258,7 @@ func initRelays(ctx context.Context) {
outboxRelay.Info.Icon = config.OutboxRelayIcon
outboxRelay.Info.Version = config.RelayVersion
outboxRelay.Info.Software = config.RelaySoftware
outboxRelay.ServiceURL = "https://" + config.RelayURL
outboxRelay.ServiceURL = getHTTPScheme(config.RelayURL) + config.RelayURL

if !outboxRelayLimits.AllowEmptyFilters {
outboxRelay.RejectFilter = append(outboxRelay.RejectFilter, policies.NoEmptyFilters)
Expand Down Expand Up @@ -289,15 +308,15 @@ func initRelays(ctx context.Context) {
RelayName: config.OutboxRelayName,
RelayPubkey: nPubToPubkey(config.OutboxRelayNpub),
RelayDescription: config.OutboxRelayDescription,
RelayURL: "wss://" + config.RelayURL + "/outbox",
RelayURL: getWSScheme(config.RelayURL) + config.RelayURL + "/outbox",
}
err := tmpl.Execute(w, data)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
})

bl := blossom.New(outboxRelay, "https://"+config.RelayURL)
bl := blossom.New(outboxRelay, getHTTPScheme(config.RelayURL)+config.RelayURL)
bl.Store = blossom.EventStoreBlobIndexWrapper{Store: blossomDB, ServiceURL: bl.ServiceURL}
bl.StoreBlob = append(bl.StoreBlob, func(ctx context.Context, sha256 string, ext string, body []byte) error {
slog.Debug("storing blob", "sha256", sha256, "ext", ext)
Expand Down Expand Up @@ -333,7 +352,7 @@ func initRelays(ctx context.Context) {
inboxRelay.Info.Icon = config.InboxRelayIcon
inboxRelay.Info.Version = config.RelayVersion
inboxRelay.Info.Software = config.RelaySoftware
inboxRelay.ServiceURL = "https://" + config.RelayURL + "/inbox"
inboxRelay.ServiceURL = getHTTPScheme(config.RelayURL) + config.RelayURL + "/inbox"

if !inboxRelayLimits.AllowEmptyFilters {
inboxRelay.RejectFilter = append(inboxRelay.RejectFilter, policies.NoEmptyFilters)
Expand Down Expand Up @@ -382,7 +401,7 @@ func initRelays(ctx context.Context) {
RelayName: config.InboxRelayName,
RelayPubkey: nPubToPubkey(config.InboxRelayNpub),
RelayDescription: config.InboxRelayDescription,
RelayURL: "wss://" + config.RelayURL + "/inbox",
RelayURL: getWSScheme(config.RelayURL) + config.RelayURL + "/inbox",
}
err := tmpl.Execute(w, data)
if err != nil {
Expand Down