Simplify Print

This commit is contained in:
eyedeekay
2025-05-27 20:04:58 -04:00
parent 26ae8f209b
commit fbdeea0e4a

View File

@ -288,7 +288,6 @@ func (f *I2PConfig) Close() string {
log.Debug("Close idle settings not applied") log.Debug("Close idle settings not applied")
return "" return ""
} }
// Log and return the close idle configuration // Log and return the close idle configuration
result := fmt.Sprintf("i2cp.closeOnIdle=%t i2cp.closeIdleTime=%d", result := fmt.Sprintf("i2cp.closeOnIdle=%t i2cp.closeIdleTime=%d",
f.CloseIdle, f.CloseIdleTime) f.CloseIdle, f.CloseIdleTime)
@ -300,25 +299,20 @@ func (f *I2PConfig) Close() string {
func (f *I2PConfig) DoZero() string { func (f *I2PConfig) DoZero() string {
// Build settings using slices for cleaner concatenation // Build settings using slices for cleaner concatenation
var settings []string var settings []string
// Add inbound zero hop setting if enabled // Add inbound zero hop setting if enabled
if f.InAllowZeroHop { if f.InAllowZeroHop {
settings = append(settings, fmt.Sprintf("inbound.allowZeroHop=%t", f.InAllowZeroHop)) settings = append(settings, fmt.Sprintf("inbound.allowZeroHop=%t", f.InAllowZeroHop))
} }
// Add outbound zero hop setting if enabled // Add outbound zero hop setting if enabled
if f.OutAllowZeroHop { if f.OutAllowZeroHop {
settings = append(settings, fmt.Sprintf("outbound.allowZeroHop=%t", f.OutAllowZeroHop)) settings = append(settings, fmt.Sprintf("outbound.allowZeroHop=%t", f.OutAllowZeroHop))
} }
// Add fast receive setting if enabled // Add fast receive setting if enabled
if f.FastRecieve { if f.FastRecieve {
settings = append(settings, fmt.Sprintf("i2cp.fastRecieve=%t", f.FastRecieve)) settings = append(settings, fmt.Sprintf("i2cp.fastRecieve=%t", f.FastRecieve))
} }
// Join all settings with spaces // Join all settings with spaces
result := strings.Join(settings, " ") result := strings.Join(settings, " ")
// Log the final settings // Log the final settings
log.WithField("zeroHopSettings", result).Debug("Zero hop settings applied") log.WithField("zeroHopSettings", result).Debug("Zero hop settings applied")
@ -377,31 +371,15 @@ func (f *I2PConfig) UsingCompression() string {
// Print returns a slice of strings containing all the I2P configuration settings // Print returns a slice of strings containing all the I2P configuration settings
func (f *I2PConfig) Print() []string { func (f *I2PConfig) Print() []string {
// Get lease set settings var settings []string
lsk, lspk, lspsk := f.LeaseSetSettings() // Collect tunnel configuration settings
settings = append(settings, f.collectTunnelSettings()...)
// Build the configuration settings slice // Collect connection behavior settings
settings := []string{ settings = append(settings, f.collectConnectionSettings()...)
f.InboundLength(), // Collect lease set settings
f.OutboundLength(), settings = append(settings, f.collectLeaseSetSettings()...)
f.InboundLengthVariance(), // Collect access control settings
f.OutboundLengthVariance(), settings = append(settings, f.collectAccessSettings()...)
f.InboundBackupQuantity(),
f.OutboundBackupQuantity(),
f.InboundQuantity(),
f.OutboundQuantity(),
f.UsingCompression(),
f.DoZero(), // Zero hop settings
f.Reduce(), // Reduce idle settings
f.Close(), // Close idle settings
f.Reliability(), // Message reliability
f.EncryptLease(), // Lease encryption
lsk, lspk, lspsk, // Lease set keys
f.Accesslisttype(), // Access list type
f.Accesslist(), // Access list
f.LeaseSetEncryptionType(), // Lease set encryption type
}
return settings return settings
} }
@ -460,6 +438,49 @@ func (f *I2PConfig) LeaseSetEncryptionType() string {
return fmt.Sprintf("i2cp.leaseSetEncType=%s", f.LeaseSetEncryption) return fmt.Sprintf("i2cp.leaseSetEncType=%s", f.LeaseSetEncryption)
} }
// collectTunnelSettings returns all tunnel-related configuration strings
func (f *I2PConfig) collectTunnelSettings() []string {
return []string{
f.InboundLength(),
f.OutboundLength(),
f.InboundLengthVariance(),
f.OutboundLengthVariance(),
f.InboundBackupQuantity(),
f.OutboundBackupQuantity(),
f.InboundQuantity(),
f.OutboundQuantity(),
}
}
// collectConnectionSettings returns all connection behavior configuration strings
func (f *I2PConfig) collectConnectionSettings() []string {
return []string{
f.UsingCompression(),
f.DoZero(), // Zero hop settings
f.Reduce(), // Reduce idle settings
f.Close(), // Close idle settings
f.Reliability(), // Message reliability
}
}
// collectLeaseSetSettings returns all lease set configuration strings
func (f *I2PConfig) collectLeaseSetSettings() []string {
lsk, lspk, lspsk := f.LeaseSetSettings()
return []string{
f.EncryptLease(), // Lease encryption
lsk, lspk, lspsk, // Lease set keys
f.LeaseSetEncryptionType(), // Lease set encryption type
}
}
// collectAccessSettings returns all access control configuration strings
func (f *I2PConfig) collectAccessSettings() []string {
return []string{
f.Accesslisttype(), // Access list type
f.Accesslist(), // Access list
}
}
func NewConfig(opts ...func(*I2PConfig) error) (*I2PConfig, error) { func NewConfig(opts ...func(*I2PConfig) error) (*I2PConfig, error) {
// Initialize with struct literal containing only non-zero defaults // Initialize with struct literal containing only non-zero defaults
// Go automatically zero-initializes all other fields // Go automatically zero-initializes all other fields