mirror of
https://github.com/DeBrosOfficial/network.git
synced 2025-10-06 06:19:08 +00:00
Use default peers during local development
The change keeps default peers in local dev mode instead of clearing them, while adding a global pubsub logger and updating bootstrap peer config.
This commit is contained in:
parent
d08626856f
commit
dfd1862cfd
@ -123,55 +123,55 @@ type HealthStatus struct {
|
||||
|
||||
// ClientConfig represents configuration for network clients
|
||||
type ClientConfig struct {
|
||||
AppName string `json:"app_name"`
|
||||
DatabaseName string `json:"database_name"`
|
||||
BootstrapPeers []string `json:"bootstrap_peers"`
|
||||
DatabaseEndpoints []string `json:"database_endpoints"`
|
||||
ConnectTimeout time.Duration `json:"connect_timeout"`
|
||||
RetryAttempts int `json:"retry_attempts"`
|
||||
RetryDelay time.Duration `json:"retry_delay"`
|
||||
QuietMode bool `json:"quiet_mode"` // Suppress debug/info logs
|
||||
AppName string `json:"app_name"`
|
||||
DatabaseName string `json:"database_name"`
|
||||
BootstrapPeers []string `json:"bootstrap_peers"`
|
||||
DatabaseEndpoints []string `json:"database_endpoints"`
|
||||
ConnectTimeout time.Duration `json:"connect_timeout"`
|
||||
RetryAttempts int `json:"retry_attempts"`
|
||||
RetryDelay time.Duration `json:"retry_delay"`
|
||||
QuietMode bool `json:"quiet_mode"` // Suppress debug/info logs
|
||||
}
|
||||
|
||||
// DefaultClientConfig returns a default client configuration
|
||||
func DefaultClientConfig(appName string) *ClientConfig {
|
||||
// Base defaults
|
||||
peers := []string{}
|
||||
endpoints := DefaultDatabaseEndpoints()
|
||||
// Base defaults
|
||||
peers := DefaultBootstrapPeers()
|
||||
endpoints := DefaultDatabaseEndpoints()
|
||||
|
||||
// Development local-only override via env
|
||||
if isTruthyEnv("NETWORK_DEV_LOCAL") {
|
||||
port := 5001
|
||||
if v := os.Getenv("RQLITE_PORT"); v != "" {
|
||||
if n, err := strconv.Atoi(v); err == nil && n > 0 { port = n }
|
||||
}
|
||||
endpoints = []string{fmt.Sprintf("http://127.0.0.1:%d", port)}
|
||||
if ma := os.Getenv("LOCAL_BOOTSTRAP_MULTIADDR"); ma != "" {
|
||||
peers = []string{ma}
|
||||
} else {
|
||||
// Leave peers empty if no local bootstrap multiaddr provided
|
||||
peers = []string{}
|
||||
}
|
||||
}
|
||||
// Development local-only override via env
|
||||
if isTruthyEnv("NETWORK_DEV_LOCAL") {
|
||||
port := 5001
|
||||
if v := os.Getenv("RQLITE_PORT"); v != "" {
|
||||
if n, err := strconv.Atoi(v); err == nil && n > 0 {
|
||||
port = n
|
||||
}
|
||||
}
|
||||
endpoints = []string{fmt.Sprintf("http://127.0.0.1:%d", port)}
|
||||
if ma := os.Getenv("LOCAL_BOOTSTRAP_MULTIADDR"); ma != "" {
|
||||
peers = []string{ma}
|
||||
}
|
||||
// else: keep the peers from DefaultBootstrapPeers() which handles NETWORK_DEV_LOCAL appropriately
|
||||
}
|
||||
|
||||
return &ClientConfig{
|
||||
AppName: appName,
|
||||
DatabaseName: fmt.Sprintf("%s_db", appName),
|
||||
BootstrapPeers: peers,
|
||||
DatabaseEndpoints: endpoints,
|
||||
ConnectTimeout: time.Second * 30,
|
||||
RetryAttempts: 3,
|
||||
RetryDelay: time.Second * 5,
|
||||
}
|
||||
return &ClientConfig{
|
||||
AppName: appName,
|
||||
DatabaseName: fmt.Sprintf("%s_db", appName),
|
||||
BootstrapPeers: peers,
|
||||
DatabaseEndpoints: endpoints,
|
||||
ConnectTimeout: time.Second * 30,
|
||||
RetryAttempts: 3,
|
||||
RetryDelay: time.Second * 5,
|
||||
}
|
||||
}
|
||||
|
||||
// isTruthyEnv returns true if the env var is set to a common truthy value.
|
||||
func isTruthyEnv(key string) bool {
|
||||
v := os.Getenv(key)
|
||||
switch v {
|
||||
case "1", "true", "TRUE", "True", "yes", "YES", "on", "ON":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
v := os.Getenv(key)
|
||||
switch v {
|
||||
case "1", "true", "TRUE", "True", "yes", "YES", "on", "ON":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
@ -33,12 +33,14 @@ func init() {
|
||||
func setDefaultBootstrapConfig() {
|
||||
// Check if we're in production environment
|
||||
BootstrapPeerIDs = []string{
|
||||
"12D3KooWNxt9bNvqftdqXg98JcUHreGxedWSZRUbyqXJ6CW7GaD4",
|
||||
"12D3KooWGbdnA22bN24X2gyY1o9jozwTBq9wbfvwtJ7G4XQ9JgFm",
|
||||
// "12D3KooWNxt9bNvqftdqXg98JcUHreGxedWSZRUbyqXJ6CW7GaD4",
|
||||
// "12D3KooWGbdnA22bN24X2gyY1o9jozwTBq9wbfvwtJ7G4XQ9JgFm",
|
||||
"12D3KooWDL6LSjwwP5FwboV9JaTZzuxr8EhjbcZGFfnyFMDt1UDx",
|
||||
}
|
||||
BootstrapAddresses = []string{
|
||||
"/ip4/57.129.81.31/tcp/4001/p2p/12D3KooWNxt9bNvqftdqXg98JcUHreGxedWSZRUbyqXJ6CW7GaD4",
|
||||
"/ip4/38.242.250.186/tcp/4001/p2p/12D3KooWGbdnA22bN24X2gyY1o9jozwTBq9wbfvwtJ7G4XQ9JgFm",
|
||||
// "/ip4/57.129.81.31/tcp/4001/p2p/12D3KooWNxt9bNvqftdqXg98JcUHreGxedWSZRUbyqXJ6CW7GaD4",
|
||||
// "/ip4/38.242.250.186/tcp/4001/p2p/12D3KooWGbdnA22bN24X2gyY1o9jozwTBq9wbfvwtJ7G4XQ9JgFm",
|
||||
"/ip4/127.0.0.1/tcp/4001/p2p/12D3KooWDL6LSjwwP5FwboV9JaTZzuxr8EhjbcZGFfnyFMDt1UDx",
|
||||
}
|
||||
|
||||
BootstrapPort = 4001
|
||||
|
@ -1,17 +1,28 @@
|
||||
package pubsub
|
||||
|
||||
import "go.uber.org/zap"
|
||||
import (
|
||||
"fmt"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// Logf is a package-level logger function used by pubsub internals.
|
||||
// By default it is a no-op to avoid polluting stdout; applications can
|
||||
// assign it (e.g., to a UI-backed logger) to surface logs as needed.
|
||||
var Logf = func(format string, args ...interface{}) { _ = fmt.Sprintf(format, args...) }
|
||||
|
||||
// SetLogFunc allows applications to provide a custom logger sink.
|
||||
func SetLogFunc(f func(string, ...interface{})) { if f != nil { Logf = f } }
|
||||
|
||||
// newPubSubLogger creates a zap.Logger for pubsub components.
|
||||
// Quiet mode can be handled by callers by using production config externally;
|
||||
// here we default to development logger for richer diagnostics during dev.
|
||||
func newPubSubLogger(quiet bool) (*zap.Logger, error) {
|
||||
if quiet {
|
||||
cfg := zap.NewProductionConfig()
|
||||
cfg.Level = zap.NewAtomicLevelAt(zap.WarnLevel)
|
||||
cfg.DisableCaller = true
|
||||
cfg.DisableStacktrace = true
|
||||
return cfg.Build()
|
||||
}
|
||||
return zap.NewDevelopment()
|
||||
if quiet {
|
||||
cfg := zap.NewProductionConfig()
|
||||
cfg.Level = zap.NewAtomicLevelAt(zap.WarnLevel)
|
||||
cfg.DisableCaller = true
|
||||
cfg.DisableStacktrace = true
|
||||
return cfg.Build()
|
||||
}
|
||||
return zap.NewDevelopment()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user