Separate out generate address function and make it's SAM port configurable

This commit is contained in:
eyedeekay
2024-11-29 18:01:00 -05:00
parent 40e34d7089
commit d8a31854b9
6 changed files with 212 additions and 215 deletions

View File

@ -189,7 +189,6 @@ func Test_KeyGenerationAndHandling(t *testing.T) {
if loadedKeys.Address != keys.Address {
// fmt.Printf("loadedKeys.Address md5hash: '%s'\n keys.Address md5hash: '%s'\n", getMD5Hash(string(loadedKeys.Address)), getMD5Hash(string(keys.Address)))
t.Errorf("LoadKeysIncompat returned incorrect address. Got '%s', want '%s'", loadedKeys.Address, keys.Address)
}
if loadedKeys.Both != keys.Both {
t.Errorf("LoadKeysIncompat returned incorrect pair. Got '%s'\nwant '%s'\n", loadedKeys.Both, keys.Both)
@ -199,7 +198,6 @@ func Test_KeyGenerationAndHandling(t *testing.T) {
}
*/
}
})
expected := keys.Address.Base64() + "\n" + keys.Both

View File

@ -128,6 +128,7 @@ func StoreKeysIncompat(k I2PKeys, w io.Writer) error {
log.WithField("keys", k).Debug("Keys stored successfully")
return nil
}
func StoreKeys(k I2PKeys, r string) error {
log.WithField("filename", r).Debug("Storing keys to file")
if _, err := os.Stat(r); err != nil {
@ -225,4 +226,3 @@ func (k I2PKeys) HostnameEntry(hostname string, opts crypto.SignerOpts) (string,
}
return string(sig), nil
}

4
log.go
View File

@ -4,9 +4,7 @@ import (
"github.com/go-i2p/logger"
)
var (
log *logger.Logger
)
var log *logger.Logger
func InitializeI2PKeysLogger() {
logger.InitializeGoI2PLogger()

5
new.go
View File

@ -9,8 +9,9 @@ import (
"time"
)
var DefaultSAMAddress = "127.0.0.1:7656"
const (
defaultSAMAddress = "127.0.0.1:7656"
defaultTimeout = 30 * time.Second
maxResponseSize = 4096
@ -30,7 +31,7 @@ type samClient struct {
// newSAMClient creates a new SAM client with optional configuration
func newSAMClient(options ...func(*samClient)) *samClient {
client := &samClient{
addr: defaultSAMAddress,
addr: DefaultSAMAddress,
timeout: defaultTimeout,
}