From ff3b15108d4221afae30f5005dd0246c0aeac380 Mon Sep 17 00:00:00 2001 From: anonpenguin23 Date: Thu, 18 Sep 2025 15:27:53 +0300 Subject: [PATCH] replaced git.debros.io with github.com --- CONTRIBUTING.md | 2 +- Makefile | 2 +- README.md | 10 +-- cmd/cli/main.go | 6 +- cmd/gateway/config.go | 4 +- cmd/gateway/main.go | 4 +- cmd/node/main.go | 8 +- e2e/client_e2e_test.go | 24 +++-- examples/basic_usage.go | 2 +- go.mod | 2 +- pkg/client/client.go | 4 +- pkg/client/client_test.go | 2 +- pkg/client/context.go | 2 +- pkg/client/defaults.go | 2 +- pkg/client/implementations.go | 2 +- pkg/client/pubsub_bridge.go | 2 +- pkg/database/rqlite.go | 2 +- pkg/gateway/apps_handlers.go | 16 ++-- pkg/gateway/auth_handlers.go | 4 +- pkg/gateway/db_helpers.go | 2 +- pkg/gateway/gateway.go | 7 +- pkg/gateway/middleware.go | 88 +++++++++---------- pkg/gateway/migrate.go | 4 +- pkg/gateway/pubsub_handlers.go | 86 +++++++++--------- pkg/gateway/status_handlers.go | 4 +- pkg/gateway/storage_handlers.go | 141 ++++++++++++++++-------------- pkg/node/node.go | 10 +-- pkg/node/node_test.go | 2 +- scripts/install-debros-network.sh | 2 +- 29 files changed, 233 insertions(+), 213 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2d01d64..efff5c6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,7 +11,7 @@ Thanks for helping improve the network! This guide covers setup, local dev, test ## Setup ```bash -git clone https://git.debros.io/DeBros/network.git +git clone https://github.com/DeBrosOfficial/network.git cd network make deps ``` diff --git a/Makefile b/Makefile index b34ed4f..a7e542e 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,7 @@ build: deps go build -ldflags "$(LDFLAGS)" -o bin/node ./cmd/node go build -ldflags "$(LDFLAGS)" -o bin/network-cli cmd/cli/main.go # Inject gateway build metadata via pkg path variables - go build -ldflags "$(LDFLAGS) -X 'git.debros.io/DeBros/network/pkg/gateway.BuildVersion=$(VERSION)' -X 'git.debros.io/DeBros/network/pkg/gateway.BuildCommit=$(COMMIT)' -X 'git.debros.io/DeBros/network/pkg/gateway.BuildTime=$(DATE)'" -o bin/gateway ./cmd/gateway + go build -ldflags "$(LDFLAGS) -X 'github.com/DeBrosOfficial/network/pkg/gateway.BuildVersion=$(VERSION)' -X 'github.com/DeBrosOfficial/network/pkg/gateway.BuildCommit=$(COMMIT)' -X 'github.com/DeBrosOfficial/network/pkg/gateway.BuildTime=$(DATE)'" -o bin/gateway ./cmd/gateway @echo "Build complete! Run ./bin/network-cli version" # Clean build artifacts diff --git a/README.md b/README.md index b583ff0..a5c7f1f 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ A robust, decentralized peer-to-peer network built in Go, providing distributed ### 1. Clone and Setup ```bash -git clone https://git.debros.io/DeBros/network.git +git clone https://github.com/DeBrosOfficial/network.git cd network ``` @@ -138,7 +138,7 @@ go run ./cmd/node --config configs/node.yaml Run the install script for a secure, production-ready setup: ```bash -curl -sSL https://git.debros.io/DeBros/network/raw/branch/main/scripts/install-debros-network.sh | sudo bash +curl -sSL https://github.com/DeBrosOfficial/network/raw/branch/main/scripts/install-debros-network.sh | sudo bash ``` **What the Script Does:** @@ -279,7 +279,7 @@ logging: ./bin/network-cli peers # List connected peers ``` - + ### Database Operations @@ -435,7 +435,7 @@ GET /v1/auth/whoami # Current auth status POST /v1/auth/api-key # Generate API key (authenticated) ``` - + #### Network Operations ```http @@ -542,7 +542,7 @@ curl -X POST http://localhost:8080/v1/auth/verify \ -d '{"wallet":"0x...","nonce":"...","signature":"0x..."}' ``` - + #### Real-time Messaging ```javascript diff --git a/cmd/cli/main.go b/cmd/cli/main.go index 794bef1..cc9e009 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -12,9 +12,9 @@ import ( "strings" "time" - "git.debros.io/DeBros/network/pkg/anyoneproxy" - "git.debros.io/DeBros/network/pkg/auth" - "git.debros.io/DeBros/network/pkg/client" + "github.com/DeBrosOfficial/network/pkg/anyoneproxy" + "github.com/DeBrosOfficial/network/pkg/auth" + "github.com/DeBrosOfficial/network/pkg/client" "github.com/libp2p/go-libp2p/core/crypto" "github.com/libp2p/go-libp2p/core/peer" ) diff --git a/cmd/gateway/config.go b/cmd/gateway/config.go index eaba07f..af36b41 100644 --- a/cmd/gateway/config.go +++ b/cmd/gateway/config.go @@ -5,8 +5,8 @@ import ( "os" "strings" - "git.debros.io/DeBros/network/pkg/gateway" - "git.debros.io/DeBros/network/pkg/logging" + "github.com/DeBrosOfficial/network/pkg/gateway" + "github.com/DeBrosOfficial/network/pkg/logging" "go.uber.org/zap" ) diff --git a/cmd/gateway/main.go b/cmd/gateway/main.go index 4d35c78..02b9446 100644 --- a/cmd/gateway/main.go +++ b/cmd/gateway/main.go @@ -9,8 +9,8 @@ import ( "syscall" "time" - "git.debros.io/DeBros/network/pkg/gateway" - "git.debros.io/DeBros/network/pkg/logging" + "github.com/DeBrosOfficial/network/pkg/gateway" + "github.com/DeBrosOfficial/network/pkg/logging" "go.uber.org/zap" ) diff --git a/cmd/node/main.go b/cmd/node/main.go index ad01872..7eea3d4 100644 --- a/cmd/node/main.go +++ b/cmd/node/main.go @@ -11,10 +11,10 @@ import ( "path/filepath" "syscall" - "git.debros.io/DeBros/network/pkg/anyoneproxy" - "git.debros.io/DeBros/network/pkg/config" - "git.debros.io/DeBros/network/pkg/logging" - "git.debros.io/DeBros/network/pkg/node" + "github.com/DeBrosOfficial/network/pkg/anyoneproxy" + "github.com/DeBrosOfficial/network/pkg/config" + "github.com/DeBrosOfficial/network/pkg/logging" + "github.com/DeBrosOfficial/network/pkg/node" "go.uber.org/zap" "gopkg.in/yaml.v3" ) diff --git a/e2e/client_e2e_test.go b/e2e/client_e2e_test.go index 16bfbc2..04962e3 100644 --- a/e2e/client_e2e_test.go +++ b/e2e/client_e2e_test.go @@ -10,7 +10,7 @@ import ( "testing" "time" - "git.debros.io/DeBros/network/pkg/client" + "github.com/DeBrosOfficial/network/pkg/client" ) func getenv(k, def string) string { @@ -42,7 +42,9 @@ func TestClient_Database_CreateQueryMigrate(t *testing.T) { var peers []string for _, p := range parts { p = strings.TrimSpace(p) - if p != "" { peers = append(peers, p) } + if p != "" { + peers = append(peers, p) + } } cfg.BootstrapPeers = peers } @@ -52,9 +54,13 @@ func TestClient_Database_CreateQueryMigrate(t *testing.T) { } c, err := client.NewClient(cfg) - if err != nil { t.Fatalf("new client: %v", err) } - if err := c.Connect(); err != nil { t.Fatalf("connect: %v", err) } - t.Cleanup(func(){ _ = c.Disconnect() }) + if err != nil { + t.Fatalf("new client: %v", err) + } + if err := c.Connect(); err != nil { + t.Fatalf("connect: %v", err) + } + t.Cleanup(func() { _ = c.Disconnect() }) // Unique table per run table := fmt.Sprintf("e2e_items_client_%d", time.Now().UnixNano()) @@ -78,6 +84,10 @@ func TestClient_Database_CreateQueryMigrate(t *testing.T) { ctx3, cancel3 := context.WithTimeout(context.Background(), 10*time.Second) defer cancel3() res, err := c.Database().Query(ctx3, fmt.Sprintf("SELECT name FROM %s ORDER BY id", table)) - if err != nil { t.Fatalf("query: %v", err) } - if res.Count < 2 { t.Fatalf("expected at least 2 rows, got %d", res.Count) } + if err != nil { + t.Fatalf("query: %v", err) + } + if res.Count < 2 { + t.Fatalf("expected at least 2 rows, got %d", res.Count) + } } diff --git a/examples/basic_usage.go b/examples/basic_usage.go index 80e0573..e95e78d 100644 --- a/examples/basic_usage.go +++ b/examples/basic_usage.go @@ -5,7 +5,7 @@ import ( "log" "time" - "git.debros.io/DeBros/network/pkg/client" + "github.com/DeBrosOfficial/network/pkg/client" ) func main() { diff --git a/go.mod b/go.mod index d2db8ed..0b1a4b6 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module git.debros.io/DeBros/network +module github.com/DeBrosOfficial/network go 1.23.8 diff --git a/pkg/client/client.go b/pkg/client/client.go index f7f0a85..79a8bcd 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -20,8 +20,8 @@ import ( libp2ppubsub "github.com/libp2p/go-libp2p-pubsub" - "git.debros.io/DeBros/network/pkg/anyoneproxy" - "git.debros.io/DeBros/network/pkg/pubsub" + "github.com/DeBrosOfficial/network/pkg/anyoneproxy" + "github.com/DeBrosOfficial/network/pkg/pubsub" ) // Client implements the NetworkClient interface diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index 8a2ba28..c990c7e 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -6,7 +6,7 @@ import ( "encoding/json" "testing" - "git.debros.io/DeBros/network/pkg/pubsub" + "github.com/DeBrosOfficial/network/pkg/pubsub" ) // MakeJWT creates a minimal JWT-like token with a json payload diff --git a/pkg/client/context.go b/pkg/client/context.go index cdcdee4..6e5735e 100644 --- a/pkg/client/context.go +++ b/pkg/client/context.go @@ -3,7 +3,7 @@ package client import ( "context" - "git.debros.io/DeBros/network/pkg/pubsub" + "github.com/DeBrosOfficial/network/pkg/pubsub" ) // contextKey for internal operations diff --git a/pkg/client/defaults.go b/pkg/client/defaults.go index 3276cdd..c42f6ae 100644 --- a/pkg/client/defaults.go +++ b/pkg/client/defaults.go @@ -5,7 +5,7 @@ import ( "strconv" "strings" - "git.debros.io/DeBros/network/pkg/config" + "github.com/DeBrosOfficial/network/pkg/config" "github.com/multiformats/go-multiaddr" ) diff --git a/pkg/client/implementations.go b/pkg/client/implementations.go index 4309c54..bf1bc9d 100644 --- a/pkg/client/implementations.go +++ b/pkg/client/implementations.go @@ -7,7 +7,7 @@ import ( "sync" "time" - "git.debros.io/DeBros/network/pkg/anyoneproxy" + "github.com/DeBrosOfficial/network/pkg/anyoneproxy" "github.com/libp2p/go-libp2p/core/peer" "github.com/multiformats/go-multiaddr" "github.com/rqlite/gorqlite" diff --git a/pkg/client/pubsub_bridge.go b/pkg/client/pubsub_bridge.go index cbaa7a7..653301e 100644 --- a/pkg/client/pubsub_bridge.go +++ b/pkg/client/pubsub_bridge.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "git.debros.io/DeBros/network/pkg/pubsub" + "github.com/DeBrosOfficial/network/pkg/pubsub" ) // pubSubBridge bridges between our PubSubClient interface and the pubsub package diff --git a/pkg/database/rqlite.go b/pkg/database/rqlite.go index c25da22..de1866b 100644 --- a/pkg/database/rqlite.go +++ b/pkg/database/rqlite.go @@ -15,7 +15,7 @@ import ( "github.com/rqlite/gorqlite" "go.uber.org/zap" - "git.debros.io/DeBros/network/pkg/config" + "github.com/DeBrosOfficial/network/pkg/config" ) // RQLiteManager manages an RQLite node instance diff --git a/pkg/gateway/apps_handlers.go b/pkg/gateway/apps_handlers.go index 6df86b1..2b6c533 100644 --- a/pkg/gateway/apps_handlers.go +++ b/pkg/gateway/apps_handlers.go @@ -7,16 +7,16 @@ import ( "net/http" "strings" - "git.debros.io/DeBros/network/pkg/storage" + "github.com/DeBrosOfficial/network/pkg/storage" ) // appsHandler implements minimal CRUD for apps within a namespace. // Routes handled: -// - GET /v1/apps -> list -// - POST /v1/apps -> create -// - GET /v1/apps/{app_id} -> fetch -// - PUT /v1/apps/{app_id} -> update (name/public_key) -// - DELETE /v1/apps/{app_id} -> delete +// - GET /v1/apps -> list +// - POST /v1/apps -> create +// - GET /v1/apps/{app_id} -> fetch +// - PUT /v1/apps/{app_id} -> update (name/public_key) +// - DELETE /v1/apps/{app_id} -> delete func (g *Gateway) appsHandler(w http.ResponseWriter, r *http.Request) { if g.client == nil { writeError(w, http.StatusServiceUnavailable, "client not initialized") @@ -29,7 +29,9 @@ func (g *Gateway) appsHandler(w http.ResponseWriter, r *http.Request) { ns = s } } - if strings.TrimSpace(ns) == "" { ns = "default" } + if strings.TrimSpace(ns) == "" { + ns = "default" + } db := g.client.Database() nsID, err := g.resolveNamespaceID(ctx, ns) if err != nil { diff --git a/pkg/gateway/auth_handlers.go b/pkg/gateway/auth_handlers.go index 2060ae6..0504fee 100644 --- a/pkg/gateway/auth_handlers.go +++ b/pkg/gateway/auth_handlers.go @@ -11,8 +11,8 @@ import ( "strings" "time" - "git.debros.io/DeBros/network/pkg/client" - "git.debros.io/DeBros/network/pkg/storage" + "github.com/DeBrosOfficial/network/pkg/client" + "github.com/DeBrosOfficial/network/pkg/storage" ethcrypto "github.com/ethereum/go-ethereum/crypto" ) diff --git a/pkg/gateway/db_helpers.go b/pkg/gateway/db_helpers.go index f6c8e0c..99334a0 100644 --- a/pkg/gateway/db_helpers.go +++ b/pkg/gateway/db_helpers.go @@ -3,7 +3,7 @@ package gateway import ( "context" - "git.debros.io/DeBros/network/pkg/client" + "github.com/DeBrosOfficial/network/pkg/client" ) func (g *Gateway) resolveNamespaceID(ctx context.Context, ns string) (interface{}, error) { diff --git a/pkg/gateway/gateway.go b/pkg/gateway/gateway.go index 134f12a..fbb9a10 100644 --- a/pkg/gateway/gateway.go +++ b/pkg/gateway/gateway.go @@ -7,10 +7,9 @@ import ( "net/http" "strconv" "time" - - "git.debros.io/DeBros/network/pkg/client" - "git.debros.io/DeBros/network/pkg/logging" + "github.com/DeBrosOfficial/network/pkg/client" + "github.com/DeBrosOfficial/network/pkg/logging" "go.uber.org/zap" ) @@ -59,7 +58,7 @@ func New(logger *logging.ColoredLogger, cfg *Config) (*Gateway, error) { ) logger.ComponentInfo(logging.ComponentGeneral, "Creating gateway instance...") - gw := &Gateway{ + gw := &Gateway{ logger: logger, cfg: cfg, client: c, diff --git a/pkg/gateway/middleware.go b/pkg/gateway/middleware.go index 94fd78c..d2fb209 100644 --- a/pkg/gateway/middleware.go +++ b/pkg/gateway/middleware.go @@ -9,9 +9,9 @@ import ( "strings" "time" - "git.debros.io/DeBros/network/pkg/client" - "git.debros.io/DeBros/network/pkg/logging" - "git.debros.io/DeBros/network/pkg/storage" + "github.com/DeBrosOfficial/network/pkg/client" + "github.com/DeBrosOfficial/network/pkg/logging" + "github.com/DeBrosOfficial/network/pkg/storage" "go.uber.org/zap" ) @@ -96,13 +96,13 @@ func (g *Gateway) authMiddleware(next http.Handler) http.Handler { return } - // Look up API key in DB and derive namespace - db := g.client.Database() - // Use internal auth for DB validation (auth not established yet) - internalCtx := client.WithInternalAuth(r.Context()) - // Join to namespaces to resolve name in one query - q := "SELECT namespaces.name FROM api_keys JOIN namespaces ON api_keys.namespace_id = namespaces.id WHERE api_keys.key = ? LIMIT 1" - res, err := db.Query(internalCtx, q, key) + // Look up API key in DB and derive namespace + db := g.client.Database() + // Use internal auth for DB validation (auth not established yet) + internalCtx := client.WithInternalAuth(r.Context()) + // Join to namespaces to resolve name in one query + q := "SELECT namespaces.name FROM api_keys JOIN namespaces ON api_keys.namespace_id = namespaces.id WHERE api_keys.key = ? LIMIT 1" + res, err := db.Query(internalCtx, q, key) if err != nil || res == nil || res.Count == 0 || len(res.Rows) == 0 || len(res.Rows[0]) == 0 { w.Header().Set("WWW-Authenticate", "Bearer error=\"invalid_token\"") writeError(w, http.StatusUnauthorized, "invalid API key") @@ -123,10 +123,10 @@ func (g *Gateway) authMiddleware(next http.Handler) http.Handler { return } - // Attach auth metadata to context for downstream use - reqCtx := context.WithValue(r.Context(), ctxKeyAPIKey, key) - reqCtx = storage.WithNamespace(reqCtx, ns) - next.ServeHTTP(w, r.WithContext(reqCtx)) + // Attach auth metadata to context for downstream use + reqCtx := context.WithValue(r.Context(), ctxKeyAPIKey, key) + reqCtx = storage.WithNamespace(reqCtx, ns) + next.ServeHTTP(w, r.WithContext(reqCtx)) }) } @@ -203,25 +203,25 @@ func (g *Gateway) authorizationMiddleware(next http.Handler) http.Handler { return } - // Identify actor from context - ownerType := "" - ownerID := "" - if v := ctx.Value(ctxKeyJWT); v != nil { - if claims, ok := v.(*jwtClaims); ok && claims != nil && strings.TrimSpace(claims.Sub) != "" { - // Determine subject type. - // If subject looks like an API key (e.g., ak_:), - // treat it as an API key owner; otherwise assume a wallet subject. - subj := strings.TrimSpace(claims.Sub) - lowerSubj := strings.ToLower(subj) - if strings.HasPrefix(lowerSubj, "ak_") || strings.Contains(subj, ":") { - ownerType = "api_key" - ownerID = subj - } else { - ownerType = "wallet" - ownerID = subj - } - } - } + // Identify actor from context + ownerType := "" + ownerID := "" + if v := ctx.Value(ctxKeyJWT); v != nil { + if claims, ok := v.(*jwtClaims); ok && claims != nil && strings.TrimSpace(claims.Sub) != "" { + // Determine subject type. + // If subject looks like an API key (e.g., ak_:), + // treat it as an API key owner; otherwise assume a wallet subject. + subj := strings.TrimSpace(claims.Sub) + lowerSubj := strings.ToLower(subj) + if strings.HasPrefix(lowerSubj, "ak_") || strings.Contains(subj, ":") { + ownerType = "api_key" + ownerID = subj + } else { + ownerType = "wallet" + ownerID = subj + } + } + } if ownerType == "" && ownerID == "" { if v := ctx.Value(ctxKeyAPIKey); v != nil { if s, ok := v.(string); ok && strings.TrimSpace(s) != "" { @@ -236,23 +236,23 @@ func (g *Gateway) authorizationMiddleware(next http.Handler) http.Handler { return } - // Check ownership in DB using internal auth context - db := g.client.Database() - internalCtx := client.WithInternalAuth(ctx) - // Ensure namespace exists and get id - if _, err := db.Query(internalCtx, "INSERT OR IGNORE INTO namespaces(name) VALUES (?)", ns); err != nil { + // Check ownership in DB using internal auth context + db := g.client.Database() + internalCtx := client.WithInternalAuth(ctx) + // Ensure namespace exists and get id + if _, err := db.Query(internalCtx, "INSERT OR IGNORE INTO namespaces(name) VALUES (?)", ns); err != nil { writeError(w, http.StatusInternalServerError, err.Error()) return } - nres, err := db.Query(internalCtx, "SELECT id FROM namespaces WHERE name = ? LIMIT 1", ns) + nres, err := db.Query(internalCtx, "SELECT id FROM namespaces WHERE name = ? LIMIT 1", ns) if err != nil || nres == nil || nres.Count == 0 || len(nres.Rows) == 0 || len(nres.Rows[0]) == 0 { writeError(w, http.StatusForbidden, "namespace not found") return } nsID := nres.Rows[0][0] - q := "SELECT 1 FROM namespace_ownership WHERE namespace_id = ? AND owner_type = ? AND owner_id = ? LIMIT 1" - res, err := db.Query(internalCtx, q, nsID, ownerType, ownerID) + q := "SELECT 1 FROM namespace_ownership WHERE namespace_id = ? AND owner_type = ? AND owner_id = ? LIMIT 1" + res, err := db.Query(internalCtx, q, nsID, ownerType, ownerID) if err != nil || res == nil || res.Count == 0 { writeError(w, http.StatusForbidden, "forbidden: not an owner of namespace") return @@ -274,9 +274,9 @@ func requiresNamespaceOwnership(p string) bool { if strings.HasPrefix(p, "/v1/pubsub") { return true } - if strings.HasPrefix(p, "/v1/db/") { - return true - } + if strings.HasPrefix(p, "/v1/db/") { + return true + } return false } diff --git a/pkg/gateway/migrate.go b/pkg/gateway/migrate.go index 882e446..a419210 100644 --- a/pkg/gateway/migrate.go +++ b/pkg/gateway/migrate.go @@ -9,8 +9,8 @@ import ( "strconv" "strings" - "git.debros.io/DeBros/network/pkg/client" - "git.debros.io/DeBros/network/pkg/logging" + "github.com/DeBrosOfficial/network/pkg/client" + "github.com/DeBrosOfficial/network/pkg/logging" "go.uber.org/zap" ) diff --git a/pkg/gateway/pubsub_handlers.go b/pkg/gateway/pubsub_handlers.go index 7be5e8f..84ecaf3 100644 --- a/pkg/gateway/pubsub_handlers.go +++ b/pkg/gateway/pubsub_handlers.go @@ -1,15 +1,15 @@ package gateway import ( - "encoding/base64" - "encoding/json" "crypto/sha256" + "encoding/base64" "encoding/hex" + "encoding/json" "net/http" "time" - "git.debros.io/DeBros/network/pkg/client" - "git.debros.io/DeBros/network/pkg/storage" + "github.com/DeBrosOfficial/network/pkg/client" + "github.com/DeBrosOfficial/network/pkg/storage" "github.com/gorilla/websocket" ) @@ -25,51 +25,51 @@ var wsUpgrader = websocket.Upgrader{ // are published to the same namespaced topic. func (g *Gateway) pubsubWebsocketHandler(w http.ResponseWriter, r *http.Request) { if g.client == nil { - g.logger.ComponentWarn("gateway", "pubsub ws: client not initialized") - writeError(w, http.StatusServiceUnavailable, "client not initialized") + g.logger.ComponentWarn("gateway", "pubsub ws: client not initialized") + writeError(w, http.StatusServiceUnavailable, "client not initialized") return } if r.Method != http.MethodGet { - g.logger.ComponentWarn("gateway", "pubsub ws: method not allowed",) - writeError(w, http.StatusMethodNotAllowed, "method not allowed") + g.logger.ComponentWarn("gateway", "pubsub ws: method not allowed") + writeError(w, http.StatusMethodNotAllowed, "method not allowed") return } // Resolve namespace from auth context - ns := resolveNamespaceFromRequest(r) + ns := resolveNamespaceFromRequest(r) if ns == "" { - g.logger.ComponentWarn("gateway", "pubsub ws: namespace not resolved") - writeError(w, http.StatusForbidden, "namespace not resolved") + g.logger.ComponentWarn("gateway", "pubsub ws: namespace not resolved") + writeError(w, http.StatusForbidden, "namespace not resolved") return } topic := r.URL.Query().Get("topic") - if topic == "" { - g.logger.ComponentWarn("gateway", "pubsub ws: missing topic") - writeError(w, http.StatusBadRequest, "missing 'topic'") + if topic == "" { + g.logger.ComponentWarn("gateway", "pubsub ws: missing topic") + writeError(w, http.StatusBadRequest, "missing 'topic'") return } - conn, err := wsUpgrader.Upgrade(w, r, nil) + conn, err := wsUpgrader.Upgrade(w, r, nil) if err != nil { - g.logger.ComponentWarn("gateway", "pubsub ws: upgrade failed",) + g.logger.ComponentWarn("gateway", "pubsub ws: upgrade failed") return } defer conn.Close() // Channel to deliver PubSub messages to WS writer msgs := make(chan []byte, 128) - // Use internal auth context when interacting with client to avoid circular auth requirements - ctx := client.WithInternalAuth(r.Context()) - // Subscribe to the topic; push data into msgs with simple per-connection de-dup - recent := make(map[string]time.Time) - h := func(_ string, data []byte) error { - // Drop duplicates seen in the last 2 seconds - sum := sha256.Sum256(data) - key := hex.EncodeToString(sum[:]) - if t, ok := recent[key]; ok && time.Since(t) < 2*time.Second { - return nil - } - recent[key] = time.Now() + // Use internal auth context when interacting with client to avoid circular auth requirements + ctx := client.WithInternalAuth(r.Context()) + // Subscribe to the topic; push data into msgs with simple per-connection de-dup + recent := make(map[string]time.Time) + h := func(_ string, data []byte) error { + // Drop duplicates seen in the last 2 seconds + sum := sha256.Sum256(data) + key := hex.EncodeToString(sum[:]) + if t, ok := recent[key]; ok && time.Since(t) < 2*time.Second { + return nil + } + recent[key] = time.Now() select { case msgs <- data: return nil @@ -78,14 +78,14 @@ func (g *Gateway) pubsubWebsocketHandler(w http.ResponseWriter, r *http.Request) return nil } } - if err := g.client.PubSub().Subscribe(ctx, topic, h); err != nil { - g.logger.ComponentWarn("gateway", "pubsub ws: subscribe failed",) - writeError(w, http.StatusInternalServerError, err.Error()) + if err := g.client.PubSub().Subscribe(ctx, topic, h); err != nil { + g.logger.ComponentWarn("gateway", "pubsub ws: subscribe failed") + writeError(w, http.StatusInternalServerError, err.Error()) return } - defer func() { _ = g.client.PubSub().Unsubscribe(ctx, topic) }() + defer func() { _ = g.client.PubSub().Unsubscribe(ctx, topic) }() - // no extra fan-out; rely on libp2p subscription + // no extra fan-out; rely on libp2p subscription // Writer loop done := make(chan struct{}) @@ -116,7 +116,7 @@ func (g *Gateway) pubsubWebsocketHandler(w http.ResponseWriter, r *http.Request) }() // Reader loop: treat any client message as publish to the same topic - for { + for { mt, data, err := conn.ReadMessage() if err != nil { break @@ -124,7 +124,7 @@ func (g *Gateway) pubsubWebsocketHandler(w http.ResponseWriter, r *http.Request) if mt != websocket.TextMessage && mt != websocket.BinaryMessage { continue } - if err := g.client.PubSub().Publish(ctx, topic, data); err != nil { + if err := g.client.PubSub().Publish(ctx, topic, data); err != nil { // Best-effort notify client _ = conn.WriteMessage(websocket.TextMessage, []byte("publish_error")) } @@ -142,14 +142,14 @@ func (g *Gateway) pubsubPublishHandler(w http.ResponseWriter, r *http.Request) { writeError(w, http.StatusMethodNotAllowed, "method not allowed") return } - ns := resolveNamespaceFromRequest(r) + ns := resolveNamespaceFromRequest(r) if ns == "" { writeError(w, http.StatusForbidden, "namespace not resolved") return } var body struct { - Topic string `json:"topic"` - DataB64 string `json:"data_base64"` + Topic string `json:"topic"` + DataB64 string `json:"data_base64"` } if err := json.NewDecoder(r.Body).Decode(&body); err != nil || body.Topic == "" || body.DataB64 == "" { writeError(w, http.StatusBadRequest, "invalid body: expected {topic,data_base64}") @@ -160,11 +160,11 @@ func (g *Gateway) pubsubPublishHandler(w http.ResponseWriter, r *http.Request) { writeError(w, http.StatusBadRequest, "invalid base64 data") return } - if err := g.client.PubSub().Publish(client.WithInternalAuth(r.Context()), body.Topic, data); err != nil { + if err := g.client.PubSub().Publish(client.WithInternalAuth(r.Context()), body.Topic, data); err != nil { writeError(w, http.StatusInternalServerError, err.Error()) return } - // rely on libp2p to deliver to WS subscribers + // rely on libp2p to deliver to WS subscribers writeJSON(w, http.StatusOK, map[string]any{"status": "ok"}) } @@ -179,13 +179,13 @@ func (g *Gateway) pubsubTopicsHandler(w http.ResponseWriter, r *http.Request) { writeError(w, http.StatusForbidden, "namespace not resolved") return } - all, err := g.client.PubSub().ListTopics(client.WithInternalAuth(r.Context())) + all, err := g.client.PubSub().ListTopics(client.WithInternalAuth(r.Context())) if err != nil { writeError(w, http.StatusInternalServerError, err.Error()) return } - // Client returns topics already trimmed to its namespace; return as-is - writeJSON(w, http.StatusOK, map[string]any{"topics": all}) + // Client returns topics already trimmed to its namespace; return as-is + writeJSON(w, http.StatusOK, map[string]any{"topics": all}) } // resolveNamespaceFromRequest gets namespace from context set by auth middleware diff --git a/pkg/gateway/status_handlers.go b/pkg/gateway/status_handlers.go index c09714d..37d6448 100644 --- a/pkg/gateway/status_handlers.go +++ b/pkg/gateway/status_handlers.go @@ -5,8 +5,8 @@ import ( "net/http" "time" - "git.debros.io/DeBros/network/pkg/client" - "git.debros.io/DeBros/network/pkg/logging" + "github.com/DeBrosOfficial/network/pkg/client" + "github.com/DeBrosOfficial/network/pkg/logging" "go.uber.org/zap" ) diff --git a/pkg/gateway/storage_handlers.go b/pkg/gateway/storage_handlers.go index b15b4ad..f3784fb 100644 --- a/pkg/gateway/storage_handlers.go +++ b/pkg/gateway/storage_handlers.go @@ -4,116 +4,125 @@ import ( "encoding/json" "net/http" - "git.debros.io/DeBros/network/pkg/client" - "git.debros.io/DeBros/network/pkg/pubsub" + "github.com/DeBrosOfficial/network/pkg/client" + "github.com/DeBrosOfficial/network/pkg/pubsub" ) // Database HTTP handlers func (g *Gateway) dbQueryHandler(w http.ResponseWriter, r *http.Request) { - if g.client == nil { - writeError(w, http.StatusServiceUnavailable, "client not initialized"); - return + if g.client == nil { + writeError(w, http.StatusServiceUnavailable, "client not initialized") + return } - if r.Method != http.MethodPost { - writeError(w, http.StatusMethodNotAllowed, "method not allowed"); - return + if r.Method != http.MethodPost { + writeError(w, http.StatusMethodNotAllowed, "method not allowed") + return } - var body struct{ SQL string `json:"sql"`; Args []any `json:"args"` } - if err := json.NewDecoder(r.Body).Decode(&body); err != nil || body.SQL == "" { - writeError(w, http.StatusBadRequest, "invalid body: {sql, args?}"); - return + var body struct { + SQL string `json:"sql"` + Args []any `json:"args"` + } + if err := json.NewDecoder(r.Body).Decode(&body); err != nil || body.SQL == "" { + writeError(w, http.StatusBadRequest, "invalid body: {sql, args?}") + return } ctx := client.WithInternalAuth(r.Context()) res, err := g.client.Database().Query(ctx, body.SQL, body.Args...) - if err != nil { - writeError(w, http.StatusInternalServerError, err.Error()); - return + if err != nil { + writeError(w, http.StatusInternalServerError, err.Error()) + return } writeJSON(w, http.StatusOK, res) } func (g *Gateway) dbTransactionHandler(w http.ResponseWriter, r *http.Request) { - if g.client == nil { - writeError(w, http.StatusServiceUnavailable, "client not initialized"); - return + if g.client == nil { + writeError(w, http.StatusServiceUnavailable, "client not initialized") + return } - if r.Method != http.MethodPost { - writeError(w, http.StatusMethodNotAllowed, "method not allowed"); - return + if r.Method != http.MethodPost { + writeError(w, http.StatusMethodNotAllowed, "method not allowed") + return } - var body struct{ Statements []string `json:"statements"` } - if err := json.NewDecoder(r.Body).Decode(&body); err != nil || len(body.Statements) == 0 { - writeError(w, http.StatusBadRequest, "invalid body: {statements:[...]}"); - return + var body struct { + Statements []string `json:"statements"` + } + if err := json.NewDecoder(r.Body).Decode(&body); err != nil || len(body.Statements) == 0 { + writeError(w, http.StatusBadRequest, "invalid body: {statements:[...]}") + return } ctx := client.WithInternalAuth(r.Context()) - if err := g.client.Database().Transaction(ctx, body.Statements); err != nil { - writeError(w, http.StatusInternalServerError, err.Error()); - return + if err := g.client.Database().Transaction(ctx, body.Statements); err != nil { + writeError(w, http.StatusInternalServerError, err.Error()) + return } - writeJSON(w, http.StatusOK, map[string]any{"status":"ok"}) + writeJSON(w, http.StatusOK, map[string]any{"status": "ok"}) } func (g *Gateway) dbSchemaHandler(w http.ResponseWriter, r *http.Request) { - if g.client == nil { - writeError(w, http.StatusServiceUnavailable, "client not initialized"); - return + if g.client == nil { + writeError(w, http.StatusServiceUnavailable, "client not initialized") + return } - if r.Method != http.MethodGet { - writeError(w, http.StatusMethodNotAllowed, "method not allowed"); - return + if r.Method != http.MethodGet { + writeError(w, http.StatusMethodNotAllowed, "method not allowed") + return } ctx := client.WithInternalAuth(r.Context()) schema, err := g.client.Database().GetSchema(ctx) - if err != nil { - writeError(w, http.StatusInternalServerError, err.Error()); - return + if err != nil { + writeError(w, http.StatusInternalServerError, err.Error()) + return } writeJSON(w, http.StatusOK, schema) } func (g *Gateway) dbCreateTableHandler(w http.ResponseWriter, r *http.Request) { - if g.client == nil { - writeError(w, http.StatusServiceUnavailable, "client not initialized"); - return + if g.client == nil { + writeError(w, http.StatusServiceUnavailable, "client not initialized") + return } - if r.Method != http.MethodPost { - writeError(w, http.StatusMethodNotAllowed, "method not allowed"); - return + if r.Method != http.MethodPost { + writeError(w, http.StatusMethodNotAllowed, "method not allowed") + return } - var body struct{ Schema string `json:"schema"` } - if err := json.NewDecoder(r.Body).Decode(&body); err != nil || body.Schema == "" { - writeError(w, http.StatusBadRequest, "invalid body: {schema}"); - return + var body struct { + Schema string `json:"schema"` + } + if err := json.NewDecoder(r.Body).Decode(&body); err != nil || body.Schema == "" { + writeError(w, http.StatusBadRequest, "invalid body: {schema}") + return } ctx := client.WithInternalAuth(r.Context()) - if err := g.client.Database().CreateTable(ctx, body.Schema); err != nil { - writeError(w, http.StatusInternalServerError, err.Error()); - return + if err := g.client.Database().CreateTable(ctx, body.Schema); err != nil { + writeError(w, http.StatusInternalServerError, err.Error()) + return } - writeJSON(w, http.StatusCreated, map[string]any{"status":"ok"}) + writeJSON(w, http.StatusCreated, map[string]any{"status": "ok"}) } func (g *Gateway) dbDropTableHandler(w http.ResponseWriter, r *http.Request) { - if g.client == nil { - writeError(w, http.StatusServiceUnavailable, "client not initialized"); - return + if g.client == nil { + writeError(w, http.StatusServiceUnavailable, "client not initialized") + return } - if r.Method != http.MethodPost { - writeError(w, http.StatusMethodNotAllowed, "method not allowed"); - return + if r.Method != http.MethodPost { + writeError(w, http.StatusMethodNotAllowed, "method not allowed") + return } - var body struct{ Table string `json:"table"` } - if err := json.NewDecoder(r.Body).Decode(&body); err != nil || body.Table == "" { - writeError(w, http.StatusBadRequest, "invalid body: {table}"); - return + var body struct { + Table string `json:"table"` + } + if err := json.NewDecoder(r.Body).Decode(&body); err != nil || body.Table == "" { + writeError(w, http.StatusBadRequest, "invalid body: {table}") + return } ctx := client.WithInternalAuth(r.Context()) - if err := g.client.Database().DropTable(ctx, body.Table); err != nil { - writeError(w, http.StatusInternalServerError, err.Error()); - return + if err := g.client.Database().DropTable(ctx, body.Table); err != nil { + writeError(w, http.StatusInternalServerError, err.Error()) + return } - writeJSON(w, http.StatusOK, map[string]any{"status":"ok"}) + writeJSON(w, http.StatusOK, map[string]any{"status": "ok"}) } func (g *Gateway) networkStatusHandler(w http.ResponseWriter, r *http.Request) { diff --git a/pkg/node/node.go b/pkg/node/node.go index 10fa933..e6c45f2 100644 --- a/pkg/node/node.go +++ b/pkg/node/node.go @@ -22,11 +22,11 @@ import ( "github.com/multiformats/go-multiaddr" "go.uber.org/zap" - "git.debros.io/DeBros/network/pkg/anyoneproxy" - "git.debros.io/DeBros/network/pkg/config" - "git.debros.io/DeBros/network/pkg/database" - "git.debros.io/DeBros/network/pkg/logging" - "git.debros.io/DeBros/network/pkg/pubsub" + "github.com/DeBrosOfficial/network/pkg/anyoneproxy" + "github.com/DeBrosOfficial/network/pkg/config" + "github.com/DeBrosOfficial/network/pkg/database" + "github.com/DeBrosOfficial/network/pkg/logging" + "github.com/DeBrosOfficial/network/pkg/pubsub" ) // Node represents a network node with RQLite database diff --git a/pkg/node/node_test.go b/pkg/node/node_test.go index d25e20b..8ee0ab4 100644 --- a/pkg/node/node_test.go +++ b/pkg/node/node_test.go @@ -9,7 +9,7 @@ import ( "testing" "time" - "git.debros.io/DeBros/network/pkg/config" + "github.com/DeBrosOfficial/network/pkg/config" "github.com/libp2p/go-libp2p" "github.com/libp2p/go-libp2p/core/crypto" "github.com/libp2p/go-libp2p/core/network" diff --git a/scripts/install-debros-network.sh b/scripts/install-debros-network.sh index 5f08c38..f0514f1 100755 --- a/scripts/install-debros-network.sh +++ b/scripts/install-debros-network.sh @@ -17,7 +17,7 @@ NOCOLOR='\033[0m' # Defaults INSTALL_DIR="/opt/debros" -REPO_URL="https://git.debros.io/DeBros/network.git" +REPO_URL="https://github.com/DeBrosOfficial/network.git" MIN_GO_VERSION="1.21" NODE_PORT="4001" RQLITE_PORT="5001"