2025-02-23 18:45:11 -05:00
|
|
|
// package sam3 wraps the original sam3 API from github.com/go-i2p/sam3
|
2025-02-23 18:01:43 -05:00
|
|
|
package sam3
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/go-i2p/go-sam-go/common"
|
|
|
|
)
|
|
|
|
|
|
|
|
// I2PConfig is a struct which manages I2P configuration options
|
|
|
|
type I2PConfig struct {
|
|
|
|
common.I2PConfig
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewConfig(opts ...func(*I2PConfig) error) (*I2PConfig, error) {
|
|
|
|
var config I2PConfig
|
|
|
|
config.SamHost = "127.0.0.1"
|
|
|
|
config.SamPort = 7656
|
2025-04-07 23:48:02 +00:00
|
|
|
config.SamMin = common.DEFAULT_SAM_MIN
|
|
|
|
config.SamMax = common.DEFAULT_SAM_MAX
|
2025-02-23 18:01:43 -05:00
|
|
|
config.TunName = ""
|
|
|
|
config.TunType = "server"
|
2025-04-07 23:48:02 +00:00
|
|
|
config.Style = common.SESSION_STYLE_STREAM
|
2025-02-23 18:01:43 -05:00
|
|
|
config.InLength = 3
|
|
|
|
config.OutLength = 3
|
|
|
|
config.InQuantity = 2
|
|
|
|
config.OutQuantity = 2
|
|
|
|
config.InVariance = 1
|
|
|
|
config.OutVariance = 1
|
|
|
|
config.InBackupQuantity = 3
|
|
|
|
config.OutBackupQuantity = 3
|
|
|
|
config.InAllowZeroHop = false
|
|
|
|
config.OutAllowZeroHop = false
|
|
|
|
config.EncryptLeaseSet = false
|
|
|
|
config.LeaseSetKey = ""
|
|
|
|
config.LeaseSetPrivateKey = ""
|
|
|
|
config.LeaseSetPrivateSigningKey = ""
|
|
|
|
config.FastRecieve = false
|
|
|
|
config.UseCompression = true
|
|
|
|
config.ReduceIdle = false
|
|
|
|
config.ReduceIdleTime = 15
|
|
|
|
config.ReduceIdleQuantity = 4
|
|
|
|
config.CloseIdle = false
|
|
|
|
config.CloseIdleTime = 300000
|
|
|
|
config.MessageReliability = "none"
|
|
|
|
for _, o := range opts {
|
|
|
|
if err := o(&config); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return &config, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// options map
|
|
|
|
type Options map[string]string
|
|
|
|
|
|
|
|
// obtain sam options as list of strings
|
|
|
|
func (opts Options) AsList() (ls []string) {
|
|
|
|
for k, v := range opts {
|
|
|
|
ls = append(ls, fmt.Sprintf("%s=%s", k, v))
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|