mirror of
https://github.com/go-i2p/go-sam-go.git
synced 2025-07-19 10:35:42 -04:00
simplify NewGenericSessionWithSignatureAndPorts
This commit is contained in:
@@ -111,8 +111,9 @@ func (f *I2PConfig) LeaseSetSettings() (string, string, string) {
|
|||||||
// FromPort returns the FROM_PORT configuration string for SAM bridges >= 3.1
|
// FromPort returns the FROM_PORT configuration string for SAM bridges >= 3.1
|
||||||
// Returns an empty string if SAM version < 3.1 or if fromport is "0"
|
// Returns an empty string if SAM version < 3.1 or if fromport is "0"
|
||||||
func (f *I2PConfig) FromPort() string {
|
func (f *I2PConfig) FromPort() string {
|
||||||
|
minv, _ := strconv.Atoi(DEFAULT_SAM_MIN)
|
||||||
// Check SAM version compatibility
|
// Check SAM version compatibility
|
||||||
if f.SamMax == "" || f.samMax() < 3.1 {
|
if f.samMax() < minv {
|
||||||
log.Debug("SAM version < 3.1, FromPort not applicable")
|
log.Debug("SAM version < 3.1, FromPort not applicable")
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
@@ -130,8 +131,9 @@ func (f *I2PConfig) FromPort() string {
|
|||||||
// ToPort returns the TO_PORT configuration string for SAM bridges >= 3.1
|
// ToPort returns the TO_PORT configuration string for SAM bridges >= 3.1
|
||||||
// Returns an empty string if SAM version < 3.1 or if toport is "0"
|
// Returns an empty string if SAM version < 3.1 or if toport is "0"
|
||||||
func (f *I2PConfig) ToPort() string {
|
func (f *I2PConfig) ToPort() string {
|
||||||
|
minv, _ := strconv.Atoi(DEFAULT_SAM_MIN)
|
||||||
// Check SAM version compatibility
|
// Check SAM version compatibility
|
||||||
if f.samMax() < 3.1 {
|
if f.samMax() < minv {
|
||||||
log.Debug("SAM version < 3.1, ToPort not applicable")
|
log.Debug("SAM version < 3.1, ToPort not applicable")
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
@@ -162,12 +164,13 @@ func (f *I2PConfig) SessionStyle() string {
|
|||||||
|
|
||||||
// samMax returns the maximum SAM version supported as a float64
|
// samMax returns the maximum SAM version supported as a float64
|
||||||
// If parsing fails, returns default value 3.1
|
// If parsing fails, returns default value 3.1
|
||||||
func (f *I2PConfig) samMax() float64 {
|
func (f *I2PConfig) samMax() int {
|
||||||
// Parse SAM max version to integer
|
// Parse SAM max version to integer
|
||||||
i, err := strconv.ParseFloat(f.SamMax, 64)
|
i, err := strconv.Atoi(f.MaxSAM())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Warn("Failed to parse SamMax, using default 3.1")
|
log.WithError(err).Warn("Failed to parse SamMax, using default 3.1")
|
||||||
return 3.1
|
i, _ = strconv.Atoi(DEFAULT_SAM_MIN)
|
||||||
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log the parsed version and return
|
// Log the parsed version and return
|
||||||
@@ -215,8 +218,9 @@ func (f *I2PConfig) DestinationKey() string {
|
|||||||
// SignatureType returns the SIGNATURE_TYPE configuration string for SAM bridges >= 3.1
|
// SignatureType returns the SIGNATURE_TYPE configuration string for SAM bridges >= 3.1
|
||||||
// Returns empty string if SAM version < 3.1 or if no signature type is set
|
// Returns empty string if SAM version < 3.1 or if no signature type is set
|
||||||
func (f *I2PConfig) SignatureType() string {
|
func (f *I2PConfig) SignatureType() string {
|
||||||
|
minv, _ := strconv.Atoi(DEFAULT_SAM_MIN)
|
||||||
// Check SAM version compatibility
|
// Check SAM version compatibility
|
||||||
if f.samMax() < 3.1 {
|
if f.samMax() < minv {
|
||||||
log.Debug("SAM version < 3.1, SignatureType not applicable")
|
log.Debug("SAM version < 3.1, SignatureType not applicable")
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
@@ -51,7 +51,7 @@ func (sam SAM) NewGenericSessionWithSignatureAndPorts(style, id, from, to string
|
|||||||
// Create final message with proper line termination
|
// Create final message with proper line termination
|
||||||
scmsg := []byte(baseMsg + "\n")
|
scmsg := []byte(baseMsg + "\n")
|
||||||
|
|
||||||
log.WithField("message", string(scmsg)).Debug("Sending SESSION CREATE message")
|
log.WithField("message", string(scmsg)).Debug("Sending SESSION CREATE message " + string(scmsg))
|
||||||
|
|
||||||
conn := sam.Conn
|
conn := sam.Conn
|
||||||
n, err := conn.Write(scmsg)
|
n, err := conn.Write(scmsg)
|
||||||
|
Reference in New Issue
Block a user