diff --git a/common/config.go b/common/config.go index 8a424bcf..a01438f4 100644 --- a/common/config.go +++ b/common/config.go @@ -311,16 +311,24 @@ func (f *I2PConfig) DoZero() string { // formatConfigPair creates a configuration string for inbound/outbound pairs func (f *I2PConfig) formatConfigPair(direction, property string, value interface{}) string { + var valueStr string switch v := value.(type) { case int: - return fmt.Sprintf("%s.%s=%d", direction, property, v) + if v == 0 { + return "" // Skip zero values to avoid duplicates + } + valueStr = strconv.Itoa(v) case string: - return fmt.Sprintf("%s.%s=%s", direction, property, v) + if v == "" { + return "" + } + valueStr = v case bool: - return fmt.Sprintf("%s.%s=%t", direction, property, v) + valueStr = strconv.FormatBool(v) default: return "" } + return fmt.Sprintf("%s.%s=%s", direction, property, valueStr) } func (f *I2PConfig) InboundLength() string { diff --git a/common/config_test.go b/common/config_test.go index 0c8e2889..db7abfd5 100644 --- a/common/config_test.go +++ b/common/config_test.go @@ -1,6 +1,7 @@ package common import ( + "strings" "testing" ) @@ -158,3 +159,38 @@ func TestLeaseSetSettings_Formatting(t *testing.T) { }) } } + +func TestTunnelConfigNoDuplicates(t *testing.T) { + cfg := &I2PConfig{ + InLength: 3, + OutLength: 3, + InQuantity: 2, + OutQuantity: 2, + } + + config := cfg.TunnelConfig() + params := strings.Split(config, " ") + + // Verify no duplicate parameters + seen := make(map[string]bool) + for _, param := range params { + if seen[param] { + t.Errorf("Duplicate parameter found: %s", param) + } + seen[param] = true + } + + // Verify expected parameters present + expectedParams := []string{ + "inbound.length=3", + "outbound.length=3", + "inbound.quantity=2", + "outbound.quantity=2", + } + + for _, expected := range expectedParams { + if !strings.Contains(config, expected) { + t.Errorf("Missing expected parameter: %s", expected) + } + } +}