fix bug in address setting function, work on removing some more redundant code and config options
This commit is contained in:
56
config.go
56
config.go
@ -1,6 +1,7 @@
|
||||
package sam3
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"strings"
|
||||
"time"
|
||||
@ -53,9 +54,14 @@ func (f *I2PConfig) SetSAMAddress(addr string) {
|
||||
} else if len(hp) == 2 {
|
||||
f.SamPort = hp[1]
|
||||
f.SamHost = hp[0]
|
||||
} else {
|
||||
if f.SamHost == "" {
|
||||
f.SamHost = "127.0.0.1"
|
||||
}
|
||||
if f.SamPort == "" {
|
||||
f.SamPort = "7656"
|
||||
}
|
||||
}
|
||||
f.SamPort = "7656"
|
||||
f.SamHost = "127.0.0.1"
|
||||
log.WithFields(logrus.Fields{
|
||||
"host": f.SamHost,
|
||||
"port": f.SamPort,
|
||||
@ -73,27 +79,7 @@ func (f *I2PConfig) ID() string {
|
||||
f.NickName = string(b)
|
||||
log.WithField("NickName", f.NickName).Debug("Generated random tunnel name")
|
||||
}
|
||||
return " ID=" + f.NickName + " "
|
||||
}
|
||||
|
||||
// Leasesetsettings returns the lease set settings in the form of "i2cp.leaseSetKey=key i2cp.leaseSetPrivateKey=key i2cp.leaseSetPrivateSigningKey=key"
|
||||
func (f *I2PConfig) Leasesetsettings() (string, string, string) {
|
||||
var r, s, t string
|
||||
if f.LeaseSetKey != "" {
|
||||
r = " i2cp.leaseSetKey=" + f.LeaseSetKey + " "
|
||||
}
|
||||
if f.LeaseSetPrivateKey != "" {
|
||||
s = " i2cp.leaseSetPrivateKey=" + f.LeaseSetPrivateKey + " "
|
||||
}
|
||||
if f.LeaseSetPrivateSigningKey != "" {
|
||||
t = " i2cp.leaseSetPrivateSigningKey=" + f.LeaseSetPrivateSigningKey + " "
|
||||
}
|
||||
log.WithFields(logrus.Fields{
|
||||
"leaseSetKey": r,
|
||||
"leaseSetPrivateKey": s,
|
||||
"leaseSetPrivateSigningKey": t,
|
||||
}).Debug("Lease set settings constructed")
|
||||
return r, s, t
|
||||
return fmt.Sprintf(" ID=%s ", f.NickName)
|
||||
}
|
||||
|
||||
// MinSAM returns the minimum SAM version required in major.minor form
|
||||
@ -127,7 +113,7 @@ func (f *I2PConfig) GetVersions() (min, max common.ProtocolVersion) {
|
||||
func (f *I2PConfig) DestinationKey() string {
|
||||
if &f.DestinationKeys != nil {
|
||||
log.WithField("destinationKey", f.DestinationKeys.String()).Debug("Destination key set")
|
||||
return " DESTINATION=" + f.DestinationKeys.String() + " "
|
||||
fmt.Sprintf(" DESTINATION=%s ", f.DestinationKeys.String())
|
||||
}
|
||||
log.Debug("Using TRANSIENT destination")
|
||||
return " DESTINATION=TRANSIENT "
|
||||
@ -138,17 +124,19 @@ func (f *I2PConfig) Print() []string {
|
||||
lsk, lspk, lspsk := f.Leasesetsettings()
|
||||
return []string{
|
||||
// f.targetForPort443(),
|
||||
"inbound.length=" + f.InboundLength(),
|
||||
"outbound.length=" + f.OutboundLength(),
|
||||
"inbound.lengthVariance=" + f.InboundVariance(),
|
||||
"outbound.lengthVariance=" + f.OutboundVariance(),
|
||||
"inbound.backupQuantity=" + f.InboundBackupQuantity(),
|
||||
"outbound.backupQuantity=" + f.OutboundBackupQuantity(),
|
||||
"inbound.quantity=" + f.InboundQuantity(),
|
||||
"outbound.quantity=" + f.OutboundQuantity(),
|
||||
f.DoZero(),
|
||||
f.InboundLength(),
|
||||
f.OutboundLength(),
|
||||
f.InboundVariance(),
|
||||
f.OutboundVariance(),
|
||||
f.InboundBackupQuantity(),
|
||||
f.OutboundBackupQuantity(),
|
||||
f.InboundQuantity(),
|
||||
f.OutboundQuantity(),
|
||||
f.InboundDoZero(),
|
||||
f.OutboundDoZero(),
|
||||
//"i2cp.fastRecieve=" + f.FastRecieve,
|
||||
"i2cp.gzip=" + f.TransportOptions.UseCompression,
|
||||
f.DoFastReceive(),
|
||||
f.UsesCompression(),
|
||||
f.Reduce(),
|
||||
f.Close(),
|
||||
f.Reliability(),
|
||||
|
@ -1,14 +1,15 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/go-i2p/i2pkeys"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type EncryptedLeaseSetOptions struct {
|
||||
// SigType string
|
||||
EncryptLeaseSet bool
|
||||
LeaseSetKey string
|
||||
LeaseSetPrivateKey string
|
||||
@ -40,5 +41,43 @@ func (f *EncryptedLeaseSetOptions) LeaseSetEncryptionType() string {
|
||||
}
|
||||
}
|
||||
log.WithField("leaseSetEncType", f.LeaseSetEncryption).Debug("Lease set encryption type set")
|
||||
return "i2cp.leaseSetEncType=" + f.LeaseSetEncryption
|
||||
return fmt.Sprintf(" i2cp.leaseSetEncType=%s ", f.LeaseSetEncryption)
|
||||
}
|
||||
|
||||
func (f *EncryptedLeaseSetOptions) leaseSetKey() string {
|
||||
if f.LeaseSetKey != "" {
|
||||
return fmt.Sprintf(" i2cp.leaseSetKey=%s ", f.LeaseSetKey)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (f *EncryptedLeaseSetOptions) leaseSetPrivateKey() string {
|
||||
if f.LeaseSetPrivateKey != "" {
|
||||
return fmt.Sprintf(" i2cp.leaseSetPrivateKey=%s ", f.LeaseSetPrivateKey)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (f *EncryptedLeaseSetOptions) leaseSetPrivateSigningKey() string {
|
||||
if f.LeaseSetPrivateSigningKey != "" {
|
||||
return fmt.Sprintf(" i2cp.leaseSetPrivateSigningKey=%s ", f.LeaseSetPrivateSigningKey)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// Leasesetsettings returns the lease set settings in the form of "i2cp.leaseSetKey=key i2cp.leaseSetPrivateKey=key i2cp.leaseSetPrivateSigningKey=key"
|
||||
func (f *EncryptedLeaseSetOptions) Leasesetsettings() (string, string, string) {
|
||||
if f.EncryptLeaseSet {
|
||||
var r, s, t string
|
||||
r = f.leaseSetKey()
|
||||
s = f.leaseSetPrivateKey()
|
||||
t = f.leaseSetPrivateSigningKey()
|
||||
log.WithFields(logrus.Fields{
|
||||
"leaseSetKey": r,
|
||||
"leaseSetPrivateKey": s,
|
||||
"leaseSetPrivateSigningKey": t,
|
||||
}).Debug("Lease set settings constructed")
|
||||
return r, s, t
|
||||
}
|
||||
return "", "", ""
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
package config
|
||||
|
||||
import "github.com/go-i2p/sam3/common"
|
||||
import logger "github.com/go-i2p/sam3/log"
|
||||
|
||||
var log = common.GetSAM3Logger()
|
||||
var log = logger.GetSAM3Logger()
|
||||
|
@ -40,8 +40,10 @@ func (f *TransportOptions) CloseOnIdle() string {
|
||||
|
||||
func (f *TransportOptions) DoFastReceive() string {
|
||||
if f.FastReceive == "true" {
|
||||
return " " + f.FastReceive + " "
|
||||
log.Debug("Fast receive enabled")
|
||||
return " i2cp.fastReceive=true "
|
||||
}
|
||||
log.Debug("Fast receive disabled")
|
||||
return ""
|
||||
}
|
||||
|
||||
@ -81,3 +83,12 @@ func (f *TransportOptions) Close() string {
|
||||
log.Debug("Close idle settings not applied")
|
||||
return ""
|
||||
}
|
||||
|
||||
func (f *TransportOptions) UsesCompression() string {
|
||||
if f.UseCompression == "true" {
|
||||
log.Debug("Compression enabled")
|
||||
return " i2cp.useCompression=true "
|
||||
}
|
||||
log.Debug("Compression disabled")
|
||||
return ""
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
package config
|
||||
|
||||
import "strconv"
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type TunnelOptions struct {
|
||||
InAllowZeroHop bool
|
||||
@ -16,43 +19,53 @@ type TunnelOptions struct {
|
||||
}
|
||||
|
||||
func (f *TunnelOptions) InboundDoZero() string {
|
||||
return boolToStr(f.InAllowZeroHop)
|
||||
val := boolToStr(f.InAllowZeroHop)
|
||||
return fmt.Sprintf(" inbound.allowZeroHop=%s ", val)
|
||||
}
|
||||
|
||||
func (f *TunnelOptions) OutboundDoZero() string {
|
||||
return boolToStr(f.OutAllowZeroHop)
|
||||
val := boolToStr(f.OutAllowZeroHop)
|
||||
return fmt.Sprintf(" outbound.allowZeroHop=%s ", val)
|
||||
}
|
||||
|
||||
func (f *TunnelOptions) InboundLength() string {
|
||||
return strconv.Itoa(f.InLength)
|
||||
val := strconv.Itoa(f.InLength)
|
||||
return fmt.Sprintf(" inbound.length=%s ", val)
|
||||
}
|
||||
|
||||
func (f *TunnelOptions) OutboundLength() string {
|
||||
return strconv.Itoa(f.OutLength)
|
||||
val := strconv.Itoa(f.OutLength)
|
||||
return fmt.Sprintf(" outbound.length=%s ", val)
|
||||
}
|
||||
|
||||
func (f *TunnelOptions) InboundQuantity() string {
|
||||
return strconv.Itoa(f.InQuantity)
|
||||
val := strconv.Itoa(f.InQuantity)
|
||||
return fmt.Sprintf(" inbound.quantity=%s ", val)
|
||||
}
|
||||
|
||||
func (f *TunnelOptions) OutboundQuantity() string {
|
||||
return strconv.Itoa(f.OutQuantity)
|
||||
val := strconv.Itoa(f.OutQuantity)
|
||||
return fmt.Sprintf(" outbound.quantity=%s ", val)
|
||||
}
|
||||
|
||||
func (f *TunnelOptions) InboundVariance() string {
|
||||
return strconv.Itoa(f.InVariance)
|
||||
val := strconv.Itoa(f.InVariance)
|
||||
return fmt.Sprintf(" inbound.variance=%s ", val)
|
||||
}
|
||||
|
||||
func (f *TunnelOptions) OutboundVariance() string {
|
||||
return strconv.Itoa(f.OutVariance)
|
||||
val := strconv.Itoa(f.OutVariance)
|
||||
return fmt.Sprintf(" outbound.variance=%s ", val)
|
||||
}
|
||||
|
||||
func (f *TunnelOptions) InboundBackupQuantity() string {
|
||||
return strconv.Itoa(f.InBackupQuantity)
|
||||
val := strconv.Itoa(f.InBackupQuantity)
|
||||
return fmt.Sprintf(" inbound.backupQuantity=%s ", val)
|
||||
}
|
||||
|
||||
func (f *TunnelOptions) OutboundBackupQuantity() string {
|
||||
return strconv.Itoa(f.OutBackupQuantity)
|
||||
val := strconv.Itoa(f.OutBackupQuantity)
|
||||
return fmt.Sprintf(" outbound.backupQuantity=%s ", val)
|
||||
}
|
||||
|
||||
// DoZero returns the zero hop settings in the form of "inbound.allowZeroHop=true outbound.allowZeroHop=true fastRecieve=true"
|
||||
|
4
log.go
4
log.go
@ -1,5 +1,5 @@
|
||||
package sam3
|
||||
|
||||
import "github.com/go-i2p/sam3/common"
|
||||
import logger "github.com/go-i2p/sam3/log"
|
||||
|
||||
var log = common.GetSAM3Logger()
|
||||
var log = logger.GetSAM3Logger()
|
||||
|
3
sam3.go
3
sam3.go
@ -16,10 +16,11 @@ import (
|
||||
|
||||
"github.com/go-i2p/i2pkeys"
|
||||
"github.com/go-i2p/sam3/common"
|
||||
logger "github.com/go-i2p/sam3/log"
|
||||
)
|
||||
|
||||
func init() {
|
||||
common.InitializeSAM3Logger()
|
||||
logger.InitializeSAM3Logger()
|
||||
}
|
||||
|
||||
// Used for controlling I2Ps SAMv3.
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/go-i2p/sam3/common"
|
||||
logger "github.com/go-i2p/sam3/log"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@ -115,7 +115,7 @@ func PrimarySessionString() string {
|
||||
var PrimarySessionSwitch string = PrimarySessionString()
|
||||
|
||||
func getEnv(key, fallback string) string {
|
||||
common.InitializeSAM3Logger()
|
||||
logger.InitializeSAM3Logger()
|
||||
value, ok := os.LookupEnv(key)
|
||||
if !ok {
|
||||
log.WithFields(logrus.Fields{
|
||||
|
Reference in New Issue
Block a user