added logging to suggestedOptions.go

-fixed name collision in stream_test.go
This commit is contained in:
Haris Khan
2024-10-16 10:35:43 -04:00
parent 6e2cc71a92
commit a372049be9

View File

@ -1,6 +1,7 @@
package sam3
import (
"github.com/sirupsen/logrus"
"net"
"net/http"
"os"
@ -60,30 +61,38 @@ var (
)
func PrimarySessionString() string {
log.Debug("Determining primary session type")
_, err := http.Get("http://127.0.0.1:7070")
if err != nil {
log.WithError(err).Debug("Failed to connect to 127.0.0.1:7070, trying 127.0.0.1:7657")
_, err := http.Get("http://127.0.0.1:7657")
if err != nil {
return "MASTER"
}
log.Debug("Connected to 127.0.0.1:7657, attempting to create a PRIMARY session")
// at this point we're probably running on Java I2P and thus probably
// have a PRIMARY session. Just to be sure, try to make one, check
// for errors, then immediately close it.
testSam, err := NewSAM(SAMDefaultAddr(""))
if err != nil {
log.WithError(err).Debug("Failed to create SAM instance, assuming MASTER session")
return "MASTER"
}
newKeys, err := testSam.NewKeys()
if err != nil {
log.WithError(err).Debug("Failed to create new keys, assuming MASTER session")
return "MASTER"
}
primarySession, err := testSam.newPrimarySession("PRIMARY", "primaryTestTunnel", newKeys, Options_Small)
if err != nil {
log.WithError(err).Debug("Failed to create primary session, assuming MASTER session")
return "MASTER"
}
primarySession.Close()
log.Debug("Successfully created and closed a PRIMARY session")
return "PRIMARY"
}
log.Debug("Connected to 127.0.0.1:7070, assuming MASTER session")
return "MASTER"
}
@ -92,8 +101,16 @@ var PrimarySessionSwitch string = PrimarySessionString()
func getEnv(key, fallback string) string {
value, ok := os.LookupEnv(key)
if !ok {
log.WithFields(logrus.Fields{
"key": key,
"fallback": fallback,
}).Debug("Environment variable not set, using fallback")
return fallback
}
log.WithFields(logrus.Fields{
"key": key,
"value": value,
}).Debug("Retrieved environment variable")
return value
}
@ -102,15 +119,23 @@ var SAM_PORT = getEnv("sam_port", "7656")
func SAMDefaultAddr(fallforward string) string {
if fallforward == "" {
return net.JoinHostPort(SAM_HOST, SAM_PORT)
addr := net.JoinHostPort(SAM_HOST, SAM_PORT)
log.WithField("addr", addr).Debug("Using default SAM address")
return addr
}
log.WithField("addr", fallforward).Debug("Using fallforward SAM address")
return fallforward
}
func GenerateOptionString(opts []string) string {
optStr := strings.Join(opts, " ")
log.WithField("options", optStr).Debug("Generating option string")
if strings.Contains(optStr, "i2cp.leaseSetEncType") {
log.Debug("i2cp.leaseSetEncType already present in options")
return optStr
}
return optStr + " i2cp.leaseSetEncType=4,0"
finalOpts := optStr + " i2cp.leaseSetEncType=4,0"
log.WithField("finalOptions", finalOpts).Debug("Added default i2cp.leaseSetEncType to options")
return finalOpts
//return optStr + " i2cp.leaseSetEncType=4,0"
}