mirror of
https://github.com/DeBrosOfficial/network.git
synced 2025-10-06 12:09:07 +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
|
// ClientConfig represents configuration for network clients
|
||||||
type ClientConfig struct {
|
type ClientConfig struct {
|
||||||
AppName string `json:"app_name"`
|
AppName string `json:"app_name"`
|
||||||
DatabaseName string `json:"database_name"`
|
DatabaseName string `json:"database_name"`
|
||||||
BootstrapPeers []string `json:"bootstrap_peers"`
|
BootstrapPeers []string `json:"bootstrap_peers"`
|
||||||
DatabaseEndpoints []string `json:"database_endpoints"`
|
DatabaseEndpoints []string `json:"database_endpoints"`
|
||||||
ConnectTimeout time.Duration `json:"connect_timeout"`
|
ConnectTimeout time.Duration `json:"connect_timeout"`
|
||||||
RetryAttempts int `json:"retry_attempts"`
|
RetryAttempts int `json:"retry_attempts"`
|
||||||
RetryDelay time.Duration `json:"retry_delay"`
|
RetryDelay time.Duration `json:"retry_delay"`
|
||||||
QuietMode bool `json:"quiet_mode"` // Suppress debug/info logs
|
QuietMode bool `json:"quiet_mode"` // Suppress debug/info logs
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultClientConfig returns a default client configuration
|
// DefaultClientConfig returns a default client configuration
|
||||||
func DefaultClientConfig(appName string) *ClientConfig {
|
func DefaultClientConfig(appName string) *ClientConfig {
|
||||||
// Base defaults
|
// Base defaults
|
||||||
peers := []string{}
|
peers := DefaultBootstrapPeers()
|
||||||
endpoints := DefaultDatabaseEndpoints()
|
endpoints := DefaultDatabaseEndpoints()
|
||||||
|
|
||||||
// Development local-only override via env
|
// Development local-only override via env
|
||||||
if isTruthyEnv("NETWORK_DEV_LOCAL") {
|
if isTruthyEnv("NETWORK_DEV_LOCAL") {
|
||||||
port := 5001
|
port := 5001
|
||||||
if v := os.Getenv("RQLITE_PORT"); v != "" {
|
if v := os.Getenv("RQLITE_PORT"); v != "" {
|
||||||
if n, err := strconv.Atoi(v); err == nil && n > 0 { port = n }
|
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}
|
endpoints = []string{fmt.Sprintf("http://127.0.0.1:%d", port)}
|
||||||
} else {
|
if ma := os.Getenv("LOCAL_BOOTSTRAP_MULTIADDR"); ma != "" {
|
||||||
// Leave peers empty if no local bootstrap multiaddr provided
|
peers = []string{ma}
|
||||||
peers = []string{}
|
}
|
||||||
}
|
// else: keep the peers from DefaultBootstrapPeers() which handles NETWORK_DEV_LOCAL appropriately
|
||||||
}
|
}
|
||||||
|
|
||||||
return &ClientConfig{
|
return &ClientConfig{
|
||||||
AppName: appName,
|
AppName: appName,
|
||||||
DatabaseName: fmt.Sprintf("%s_db", appName),
|
DatabaseName: fmt.Sprintf("%s_db", appName),
|
||||||
BootstrapPeers: peers,
|
BootstrapPeers: peers,
|
||||||
DatabaseEndpoints: endpoints,
|
DatabaseEndpoints: endpoints,
|
||||||
ConnectTimeout: time.Second * 30,
|
ConnectTimeout: time.Second * 30,
|
||||||
RetryAttempts: 3,
|
RetryAttempts: 3,
|
||||||
RetryDelay: time.Second * 5,
|
RetryDelay: time.Second * 5,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// isTruthyEnv returns true if the env var is set to a common truthy value.
|
// isTruthyEnv returns true if the env var is set to a common truthy value.
|
||||||
func isTruthyEnv(key string) bool {
|
func isTruthyEnv(key string) bool {
|
||||||
v := os.Getenv(key)
|
v := os.Getenv(key)
|
||||||
switch v {
|
switch v {
|
||||||
case "1", "true", "TRUE", "True", "yes", "YES", "on", "ON":
|
case "1", "true", "TRUE", "True", "yes", "YES", "on", "ON":
|
||||||
return true
|
return true
|
||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,12 +33,14 @@ func init() {
|
|||||||
func setDefaultBootstrapConfig() {
|
func setDefaultBootstrapConfig() {
|
||||||
// Check if we're in production environment
|
// Check if we're in production environment
|
||||||
BootstrapPeerIDs = []string{
|
BootstrapPeerIDs = []string{
|
||||||
"12D3KooWNxt9bNvqftdqXg98JcUHreGxedWSZRUbyqXJ6CW7GaD4",
|
// "12D3KooWNxt9bNvqftdqXg98JcUHreGxedWSZRUbyqXJ6CW7GaD4",
|
||||||
"12D3KooWGbdnA22bN24X2gyY1o9jozwTBq9wbfvwtJ7G4XQ9JgFm",
|
// "12D3KooWGbdnA22bN24X2gyY1o9jozwTBq9wbfvwtJ7G4XQ9JgFm",
|
||||||
|
"12D3KooWDL6LSjwwP5FwboV9JaTZzuxr8EhjbcZGFfnyFMDt1UDx",
|
||||||
}
|
}
|
||||||
BootstrapAddresses = []string{
|
BootstrapAddresses = []string{
|
||||||
"/ip4/57.129.81.31/tcp/4001/p2p/12D3KooWNxt9bNvqftdqXg98JcUHreGxedWSZRUbyqXJ6CW7GaD4",
|
// "/ip4/57.129.81.31/tcp/4001/p2p/12D3KooWNxt9bNvqftdqXg98JcUHreGxedWSZRUbyqXJ6CW7GaD4",
|
||||||
"/ip4/38.242.250.186/tcp/4001/p2p/12D3KooWGbdnA22bN24X2gyY1o9jozwTBq9wbfvwtJ7G4XQ9JgFm",
|
// "/ip4/38.242.250.186/tcp/4001/p2p/12D3KooWGbdnA22bN24X2gyY1o9jozwTBq9wbfvwtJ7G4XQ9JgFm",
|
||||||
|
"/ip4/127.0.0.1/tcp/4001/p2p/12D3KooWDL6LSjwwP5FwboV9JaTZzuxr8EhjbcZGFfnyFMDt1UDx",
|
||||||
}
|
}
|
||||||
|
|
||||||
BootstrapPort = 4001
|
BootstrapPort = 4001
|
||||||
|
@ -1,17 +1,28 @@
|
|||||||
package pubsub
|
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.
|
// newPubSubLogger creates a zap.Logger for pubsub components.
|
||||||
// Quiet mode can be handled by callers by using production config externally;
|
// Quiet mode can be handled by callers by using production config externally;
|
||||||
// here we default to development logger for richer diagnostics during dev.
|
// here we default to development logger for richer diagnostics during dev.
|
||||||
func newPubSubLogger(quiet bool) (*zap.Logger, error) {
|
func newPubSubLogger(quiet bool) (*zap.Logger, error) {
|
||||||
if quiet {
|
if quiet {
|
||||||
cfg := zap.NewProductionConfig()
|
cfg := zap.NewProductionConfig()
|
||||||
cfg.Level = zap.NewAtomicLevelAt(zap.WarnLevel)
|
cfg.Level = zap.NewAtomicLevelAt(zap.WarnLevel)
|
||||||
cfg.DisableCaller = true
|
cfg.DisableCaller = true
|
||||||
cfg.DisableStacktrace = true
|
cfg.DisableStacktrace = true
|
||||||
return cfg.Build()
|
return cfg.Build()
|
||||||
}
|
}
|
||||||
return zap.NewDevelopment()
|
return zap.NewDevelopment()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user