Move just a spectacular amount of config stuff into a config package because
This commit is contained in:
39
config.go
39
config.go
@ -143,43 +143,6 @@ func (f *I2PConfig) DestinationKey() string {
|
||||
return " DESTINATION=TRANSIENT "
|
||||
}
|
||||
|
||||
// Reliability returns the message reliability setting in the form of "i2cp.messageReliability=reliability"
|
||||
func (f *I2PConfig) Reliability() string {
|
||||
if f.TransportOptions.Reliability != "" {
|
||||
log.WithField("reliability", f.TransportOptions.Reliability).Debug("Message reliability set")
|
||||
return " i2cp.messageReliability=" + f.TransportOptions.Reliability + " "
|
||||
}
|
||||
log.Debug("Message reliability not set")
|
||||
return ""
|
||||
}
|
||||
|
||||
// Reduce returns the reduce idle settings in the form of "i2cp.reduceOnIdle=true i2cp.reduceIdleTime=time i2cp.reduceQuantity=quantity"
|
||||
func (f *I2PConfig) Reduce() string {
|
||||
if f.ReduceIdle {
|
||||
log.WithFields(logrus.Fields{
|
||||
"reduceIdle": f.ReduceIdle,
|
||||
"reduceIdleTime": f.TransportOptions.ReduceIdleTimeout.String(),
|
||||
"reduceIdleQuantity": f.TransportOptions.ReduceIdleQuantity,
|
||||
}).Debug("Reduce idle settings applied")
|
||||
return "i2cp.reduceOnIdle=" + f.ReduceOnIdle() + "i2cp.reduceIdleTime=" + f.TransportOptions.ReduceIdleTimeout.String() + "i2cp.reduceQuantity=" + f.ReduceQuantity()
|
||||
}
|
||||
log.Debug("Reduce idle settings not applied")
|
||||
return ""
|
||||
}
|
||||
|
||||
// Close returns the close idle settings in the form of "i2cp.closeOnIdle=true i2cp.closeIdleTime=time"
|
||||
func (f *I2PConfig) Close() string {
|
||||
if f.CloseIdle {
|
||||
log.WithFields(logrus.Fields{
|
||||
"closeIdle": f.CloseIdle,
|
||||
"closeIdleTime": f.TransportOptions.CloseIdleTimeout.String(),
|
||||
}).Debug("Close idle settings applied")
|
||||
return "i2cp.closeOnIdle=" + f.CloseOnIdle() + "i2cp.closeIdleTime=" + f.TransportOptions.CloseIdleTimeout.String()
|
||||
}
|
||||
log.Debug("Close idle settings not applied")
|
||||
return ""
|
||||
}
|
||||
|
||||
// Print returns the full config as a string
|
||||
func (f *I2PConfig) Print() []string {
|
||||
lsk, lspk, lspsk := f.Leasesetsettings()
|
||||
@ -275,7 +238,7 @@ func NewConfig(opts ...func(*I2PConfig) error) (*I2PConfig, error) {
|
||||
TransportOptions: config.TransportOptions{
|
||||
UseCompression: "true",
|
||||
FastReceive: "false",
|
||||
Reliability: "none",
|
||||
MessageReliability: "none",
|
||||
CloseIdleTimeout: 5 * time.Minute,
|
||||
ReduceIdleQuantity: 1,
|
||||
ReduceIdle: false,
|
||||
|
@ -3,6 +3,8 @@ package config
|
||||
import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func boolToStr(b bool) string {
|
||||
@ -16,7 +18,7 @@ func boolToStr(b bool) string {
|
||||
type TransportOptions struct {
|
||||
UseCompression string
|
||||
FastReceive string
|
||||
Reliability string
|
||||
MessageReliability string
|
||||
CloseIdleTimeout time.Duration
|
||||
CloseIdle bool
|
||||
ReduceIdleTimeout time.Duration
|
||||
@ -41,4 +43,41 @@ func (f *TransportOptions) DoFastReceive() string {
|
||||
return " " + f.FastReceive + " "
|
||||
}
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
// Reliability returns the message reliability setting in the form of "i2cp.messageReliability=reliability"
|
||||
func (f *TransportOptions) Reliability() string {
|
||||
if f.MessageReliability != "" {
|
||||
log.WithField("reliability", f.MessageReliability).Debug("Message reliability set")
|
||||
return " i2cp.messageReliability=" + f.MessageReliability + " "
|
||||
}
|
||||
log.Debug("Message reliability not set")
|
||||
return ""
|
||||
}
|
||||
|
||||
// Reduce returns the reduce idle settings in the form of "i2cp.reduceOnIdle=true i2cp.reduceIdleTime=time i2cp.reduceQuantity=quantity"
|
||||
func (f *TransportOptions) Reduce() string {
|
||||
if f.ReduceIdle {
|
||||
log.WithFields(logrus.Fields{
|
||||
"reduceIdle": f.ReduceIdle,
|
||||
"reduceIdleTime": f.ReduceIdleTimeout.String(),
|
||||
"reduceIdleQuantity": f.ReduceIdleQuantity,
|
||||
}).Debug("Reduce idle settings applied")
|
||||
return "i2cp.reduceOnIdle=" + f.ReduceOnIdle() + "i2cp.reduceIdleTime=" + f.ReduceIdleTimeout.String() + "i2cp.reduceQuantity=" + f.ReduceQuantity()
|
||||
}
|
||||
log.Debug("Reduce idle settings not applied")
|
||||
return ""
|
||||
}
|
||||
|
||||
// Close returns the close idle settings in the form of "i2cp.closeOnIdle=true i2cp.closeIdleTime=time"
|
||||
func (f *TransportOptions) Close() string {
|
||||
if f.CloseIdle {
|
||||
log.WithFields(logrus.Fields{
|
||||
"closeIdle": f.CloseIdle,
|
||||
"closeIdleTime": f.CloseIdleTimeout.String(),
|
||||
}).Debug("Close idle settings applied")
|
||||
return "i2cp.closeOnIdle=" + f.CloseOnIdle() + "i2cp.closeIdleTime=" + f.CloseIdleTimeout.String()
|
||||
}
|
||||
log.Debug("Close idle settings not applied")
|
||||
return ""
|
||||
}
|
||||
|
@ -55,7 +55,6 @@ func (f *TunnelOptions) OutboundBackupQuantity() string {
|
||||
return strconv.Itoa(f.OutBackupQuantity)
|
||||
}
|
||||
|
||||
|
||||
// DoZero returns the zero hop settings in the form of "inbound.allowZeroHop=true outbound.allowZeroHop=true fastRecieve=true"
|
||||
func (f *TunnelOptions) DoZero() string {
|
||||
r := ""
|
||||
@ -67,4 +66,4 @@ func (f *TunnelOptions) DoZero() string {
|
||||
}
|
||||
log.WithField("zeroHopSettings", r).Debug("Zero hop settings applied")
|
||||
return r
|
||||
}
|
||||
}
|
||||
|
@ -232,7 +232,7 @@ func SetLeaseSetPrivateSigningKey(s string) func(*SAMEmit) error {
|
||||
// SetMessageReliability sets the host of the SAMEmit's SAM bridge
|
||||
func SetMessageReliability(s string) func(*SAMEmit) error {
|
||||
return func(c *SAMEmit) error {
|
||||
c.I2PConfig.TransportOptions.Reliability = s
|
||||
c.I2PConfig.TransportOptions.MessageReliability = s
|
||||
log.WithField("messageReliability", s).Debug("Set message reliability")
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user