From be432d256d2381033b5373aa98bd9e8f3ce674a8 Mon Sep 17 00:00:00 2001 From: eyedeekay Date: Thu, 29 May 2025 16:22:52 -0400 Subject: [PATCH] fix min/max api version functions --- common/config.go | 49 ++++++++++++++++++++++++++++------------------- common/const.go | 2 ++ common/session.go | 6 +++++- common/types.go | 4 ++-- 4 files changed, 38 insertions(+), 23 deletions(-) diff --git a/common/config.go b/common/config.go index 3e002a96..33a3c263 100644 --- a/common/config.go +++ b/common/config.go @@ -179,8 +179,8 @@ func (f *I2PConfig) samMax() float64 { // If no minimum version is set, returns default value "3.0" func (f *I2PConfig) MinSAM() string { if f.SamMin == "" { - log.Debug("Using default MinSAM: 3.0") - return "3.0" + log.Debug("Using default MinSAM: " + DEFAULT_SAM_MIN) + return DEFAULT_SAM_MIN } log.WithField("minSAM", f.SamMin).Debug("MinSAM set") return f.SamMin @@ -190,8 +190,8 @@ func (f *I2PConfig) MinSAM() string { // If no maximum version is set, returns default value "3.1" func (f *I2PConfig) MaxSAM() string { if f.SamMax == "" { - log.Debug("Using default MaxSAM: 3.1") - return "3.1" + log.Debug("Using default MaxSAM: " + DEFAULT_SAM_MAX) + return DEFAULT_SAM_MAX } log.WithField("maxSAM", f.SamMax).Debug("MaxSAM set") return f.SamMax @@ -369,23 +369,31 @@ func (f *I2PConfig) UsingCompression() string { // Print returns a slice of strings containing all the I2P configuration settings func (f *I2PConfig) Print() []string { - var settings []string - // Collect tunnel configuration settings - settings = append(settings, f.collectTunnelSettings()...) - // Collect connection behavior settings - settings = append(settings, f.collectConnectionSettings()...) - // Collect lease set settings - settings = append(settings, f.collectLeaseSetSettings()...) - // Collect access control settings - settings = append(settings, f.collectAccessSettings()...) - // Filter out empty strings to prevent duplicates - var filtered []string - for _, config := range settings { + var configs []string + + // Helper function to add non-empty strings to the config slice + addConfig := func(config string) { if strings.TrimSpace(config) != "" { - filtered = append(filtered, config) + configs = append(configs, strings.TrimSpace(config)) } } - return filtered + + // Collect all configuration settings, filtering out empty strings + allSettings := [][]string{ + f.collectTunnelSettings(), + f.collectConnectionSettings(), + f.collectLeaseSetSettings(), + f.collectAccessSettings(), + } + + for _, settingsGroup := range allSettings { + for _, setting := range settingsGroup { + addConfig(setting) + } + } + + log.WithField("configs", configs).Debug("Configuration strings collected") + return configs } // Accesslisttype returns the I2CP access list configuration string based on the AccessListType setting @@ -426,13 +434,14 @@ func (f *I2PConfig) Accesslist() string { func (f *I2PConfig) LeaseSetEncryptionType() string { // Use default if not specified if f.LeaseSetEncryption == "" { - return f.formatLeaseSetEncryptionType("4,0") + f.LeaseSetEncryption = "4,0" // Set default ECIES-X25519 and ElGamal compatibility + log.Debug("Using default lease set encryption type: 4,0") } // Validate all encryption types are integers if err := f.validateEncryptionTypes(f.LeaseSetEncryption); err != nil { log.WithError(err).Warn("Invalid encryption types, using default") - return f.formatLeaseSetEncryptionType("4,0") + f.LeaseSetEncryption = "4,0" } return f.formatLeaseSetEncryptionType(f.LeaseSetEncryption) diff --git a/common/const.go b/common/const.go index 1b65da3b..ad05bb90 100644 --- a/common/const.go +++ b/common/const.go @@ -20,6 +20,8 @@ const ( SIG_ECDSA_SHA384_P384 = "SIGNATURE_TYPE=ECDSA_SHA384_P384" SIG_ECDSA_SHA512_P521 = "SIGNATURE_TYPE=ECDSA_SHA512_P521" SIG_EdDSA_SHA512_Ed25519 = "SIGNATURE_TYPE=EdDSA_SHA512_Ed25519" + // Add a default constant that points to the recommended secure signature type + SIG_DEFAULT = SIG_EdDSA_SHA512_Ed25519 ) const ( diff --git a/common/session.go b/common/session.go index 8bb88d44..41d41e72 100644 --- a/common/session.go +++ b/common/session.go @@ -31,6 +31,10 @@ func (sam SAM) NewGenericSessionWithSignature(style, id string, keys i2pkeys.I2P func (sam SAM) NewGenericSessionWithSignatureAndPorts(style, id, from, to string, keys i2pkeys.I2PKeys, sigType string, extras []string) (Session, error) { log.WithFields(logrus.Fields{"style": style, "id": id, "from": from, "to": to, "sigType": sigType}).Debug("Creating new generic session with signature and ports") + // Update SAM configuration with session-specific ports + sam.I2PConfig.Fromport = from + sam.I2PConfig.Toport = to + optStr := sam.SamOptionsString() extraStr := strings.Join(extras, " ") @@ -43,7 +47,7 @@ func (sam SAM) NewGenericSessionWithSignatureAndPorts(style, id, from, to string if to != "0" { tp = " TO_PORT=" + to } - scmsg := []byte("SESSION CREATE STYLE=" + style + fp + tp + " ID=" + id + " DESTINATION=" + keys.String() + " " + optStr + extraStr + "\n") + scmsg := []byte("SESSION CREATE STYLE=" + style + fp + tp + " ID=" + id + " DESTINATION=" + keys.String() + " " + optStr + " " + extraStr + "\n") log.WithField("message", string(scmsg)).Debug("Sending SESSION CREATE message") diff --git a/common/types.go b/common/types.go index 75276b4f..d1ffd2cb 100644 --- a/common/types.go +++ b/common/types.go @@ -130,9 +130,9 @@ func (bs *BaseSession) SetWriteDeadline(t time.Time) error { } func (bs *BaseSession) From() string { - return bs.SAM.Fromport + return bs.SAM.FromPort() } func (bs *BaseSession) To() string { - return bs.SAM.Toport + return bs.SAM.ToPort() }