fix min/max api version functions

This commit is contained in:
eyedeekay
2025-05-29 16:22:52 -04:00
parent 9604afd647
commit be432d256d
4 changed files with 38 additions and 23 deletions

View File

@ -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)

View File

@ -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 (

View File

@ -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")

View File

@ -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()
}