Skip to content
Closed
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 supernode/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ The supernode will connect to the Lumera network and begin participating in the
if gatewayPort == 0 {
gatewayPort = 8002 // Default fallback
}
gatewayServer, err := gateway.NewServer(int(gatewayPort), supernodeServer)
gatewayServer, err := gateway.NewServer(appConfig.SupernodeConfig.IpAddress, int(gatewayPort), supernodeServer)
if err != nil {
return fmt.Errorf("failed to create gateway server: %w", err)
}
Expand Down
11 changes: 8 additions & 3 deletions supernode/node/supernode/gateway/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package gateway
import (
"context"
"fmt"
"net"
"net/http"
"strconv"
"time"

"github.com/grpc-ecosystem/grpc-gateway/runtime"
Expand All @@ -14,18 +16,20 @@ import (

// Server represents the HTTP gateway server
type Server struct {
ipAddress string
port int
server *http.Server
supernodeServer pb.SupernodeServiceServer
}

// NewServer creates a new HTTP gateway server that directly calls the service
func NewServer(port int, supernodeServer pb.SupernodeServiceServer) (*Server, error) {
func NewServer(ipAddress string, port int, supernodeServer pb.SupernodeServiceServer) (*Server, error) {
Copy link

Copilot AI Aug 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ipAddress parameter lacks input validation. Consider validating that the provided IP address is valid using net.ParseIP() to prevent runtime errors when starting the server.

Copilot uses AI. Check for mistakes.
if supernodeServer == nil {
return nil, fmt.Errorf("supernode server is required")
}

return &Server{
ipAddress: ipAddress,
port: port,
supernodeServer: supernodeServer,
}, nil
Expand Down Expand Up @@ -66,15 +70,16 @@ func (s *Server) Run(ctx context.Context) error {

// Create HTTP server
s.server = &http.Server{
Addr: fmt.Sprintf(":%d", s.port),
Addr: net.JoinHostPort(s.ipAddress, strconv.Itoa(s.port)),
Handler: s.corsMiddleware(httpMux),
ReadTimeout: 15 * time.Second,
WriteTimeout: 15 * time.Second,
IdleTimeout: 60 * time.Second,
}

logtrace.Info(ctx, "Starting HTTP gateway server", logtrace.Fields{
"port": s.port,
"address": s.ipAddress,
"port": s.port,
})

// Start server
Expand Down