From 86e5b7c368f11e571ce36488362c98d27c9e93f0 Mon Sep 17 00:00:00 2001 From: eyedeekay Date: Sat, 30 Nov 2024 18:49:30 -0500 Subject: [PATCH] Move just a spectacular amount of config stuff into a config package because --- config.go | 39 +-------------------------------------- config/transport.go | 43 +++++++++++++++++++++++++++++++++++++++++-- config/tunnel.go | 3 +-- emit-options.go | 2 +- 4 files changed, 44 insertions(+), 43 deletions(-) diff --git a/config.go b/config.go index 22692c1..293f447 100644 --- a/config.go +++ b/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, diff --git a/config/transport.go b/config/transport.go index 4f8345c..2aef76f 100644 --- a/config/transport.go +++ b/config/transport.go @@ -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 "" -} \ No newline at end of file +} + +// 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 "" +} diff --git a/config/tunnel.go b/config/tunnel.go index badb94f..b97fef3 100644 --- a/config/tunnel.go +++ b/config/tunnel.go @@ -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 -} \ No newline at end of file +} diff --git a/emit-options.go b/emit-options.go index 2506e84..9379d80 100644 --- a/emit-options.go +++ b/emit-options.go @@ -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 }