Skip to content

Commit

Permalink
force an enctype if one is not present
Browse files Browse the repository at this point in the history
  • Loading branch information
eyedeekay committed Jan 7, 2024
1 parent b08d519 commit 3dc49e3
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 39 deletions.
15 changes: 15 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ type I2PConfig struct {
ReduceIdle string
ReduceIdleTime string
ReduceIdleQuantity string
LeaseSetEncryption string

//Streaming Library options
AccessListType string
AccessList []string
Expand Down Expand Up @@ -234,6 +236,7 @@ func (f *I2PConfig) Print() []string {
lsk, lspk, lspsk,
f.Accesslisttype(),
f.Accesslist(),
f.LeaseSetEncryptionType(),
}
}

Expand All @@ -259,6 +262,18 @@ func (f *I2PConfig) Accesslist() string {
return ""
}

func (f *I2PConfig) LeaseSetEncryptionType() string {
if f.LeaseSetEncryption == "" {
return "i2cp.leaseSetEncType=4,0"
}
for _, s := range strings.Split(f.LeaseSetEncryption, ",") {
if _, err := strconv.Atoi(s); err != nil {
panic("Invalid encrypted leaseSet type: " + s)
}
}
return "i2cp.leaseSetEncType=" + f.LeaseSetEncryption
}

func NewConfig(opts ...func(*I2PConfig) error) (*I2PConfig, error) {
var config I2PConfig
config.SamHost = "127.0.0.1"
Expand Down
62 changes: 31 additions & 31 deletions emit-options.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"strings"
)

//Option is a SAMEmit Option
// Option is a SAMEmit Option
type Option func(*SAMEmit) error

//SetType sets the type of the forwarder server
// SetType sets the type of the forwarder server
func SetType(s string) func(*SAMEmit) error {
return func(c *SAMEmit) error {
if s == "STREAM" {
Expand Down Expand Up @@ -41,15 +41,15 @@ func SetSAMAddress(s string) func(*SAMEmit) error {
}
}

//SetSAMHost sets the host of the SAMEmit's SAM bridge
// SetSAMHost sets the host of the SAMEmit's SAM bridge
func SetSAMHost(s string) func(*SAMEmit) error {
return func(c *SAMEmit) error {
c.I2PConfig.SamHost = s
return nil
}
}

//SetSAMPort sets the port of the SAMEmit's SAM bridge using a string
// SetSAMPort sets the port of the SAMEmit's SAM bridge using a string
func SetSAMPort(s string) func(*SAMEmit) error {
return func(c *SAMEmit) error {
port, err := strconv.Atoi(s)
Expand All @@ -64,15 +64,15 @@ func SetSAMPort(s string) func(*SAMEmit) error {
}
}

//SetName sets the host of the SAMEmit's SAM bridge
// SetName sets the host of the SAMEmit's SAM bridge
func SetName(s string) func(*SAMEmit) error {
return func(c *SAMEmit) error {
c.I2PConfig.TunName = s
return nil
}
}

//SetInLength sets the number of hops inbound
// SetInLength sets the number of hops inbound
func SetInLength(u int) func(*SAMEmit) error {
return func(c *SAMEmit) error {
if u < 7 && u >= 0 {
Expand All @@ -83,7 +83,7 @@ func SetInLength(u int) func(*SAMEmit) error {
}
}

//SetOutLength sets the number of hops outbound
// SetOutLength sets the number of hops outbound
func SetOutLength(u int) func(*SAMEmit) error {
return func(c *SAMEmit) error {
if u < 7 && u >= 0 {
Expand All @@ -94,7 +94,7 @@ func SetOutLength(u int) func(*SAMEmit) error {
}
}

//SetInVariance sets the variance of a number of hops inbound
// SetInVariance sets the variance of a number of hops inbound
func SetInVariance(i int) func(*SAMEmit) error {
return func(c *SAMEmit) error {
if i < 7 && i > -7 {
Expand All @@ -105,7 +105,7 @@ func SetInVariance(i int) func(*SAMEmit) error {
}
}

//SetOutVariance sets the variance of a number of hops outbound
// SetOutVariance sets the variance of a number of hops outbound
func SetOutVariance(i int) func(*SAMEmit) error {
return func(c *SAMEmit) error {
if i < 7 && i > -7 {
Expand All @@ -116,7 +116,7 @@ func SetOutVariance(i int) func(*SAMEmit) error {
}
}

//SetInQuantity sets the inbound tunnel quantity
// SetInQuantity sets the inbound tunnel quantity
func SetInQuantity(u int) func(*SAMEmit) error {
return func(c *SAMEmit) error {
if u <= 16 && u > 0 {
Expand All @@ -127,7 +127,7 @@ func SetInQuantity(u int) func(*SAMEmit) error {
}
}

//SetOutQuantity sets the outbound tunnel quantity
// SetOutQuantity sets the outbound tunnel quantity
func SetOutQuantity(u int) func(*SAMEmit) error {
return func(c *SAMEmit) error {
if u <= 16 && u > 0 {
Expand All @@ -138,7 +138,7 @@ func SetOutQuantity(u int) func(*SAMEmit) error {
}
}

//SetInBackups sets the inbound tunnel backups
// SetInBackups sets the inbound tunnel backups
func SetInBackups(u int) func(*SAMEmit) error {
return func(c *SAMEmit) error {
if u < 6 && u >= 0 {
Expand All @@ -149,7 +149,7 @@ func SetInBackups(u int) func(*SAMEmit) error {
}
}

//SetOutBackups sets the inbound tunnel backups
// SetOutBackups sets the inbound tunnel backups
func SetOutBackups(u int) func(*SAMEmit) error {
return func(c *SAMEmit) error {
if u < 6 && u >= 0 {
Expand All @@ -160,7 +160,7 @@ func SetOutBackups(u int) func(*SAMEmit) error {
}
}

//SetEncrypt tells the router to use an encrypted leaseset
// SetEncrypt tells the router to use an encrypted leaseset
func SetEncrypt(b bool) func(*SAMEmit) error {
return func(c *SAMEmit) error {
if b {
Expand All @@ -172,39 +172,39 @@ func SetEncrypt(b bool) func(*SAMEmit) error {
}
}

//SetLeaseSetKey sets the host of the SAMEmit's SAM bridge
// SetLeaseSetKey sets the host of the SAMEmit's SAM bridge
func SetLeaseSetKey(s string) func(*SAMEmit) error {
return func(c *SAMEmit) error {
c.I2PConfig.LeaseSetKey = s
return nil
}
}

//SetLeaseSetPrivateKey sets the host of the SAMEmit's SAM bridge
// SetLeaseSetPrivateKey sets the host of the SAMEmit's SAM bridge
func SetLeaseSetPrivateKey(s string) func(*SAMEmit) error {
return func(c *SAMEmit) error {
c.I2PConfig.LeaseSetPrivateKey = s
return nil
}
}

//SetLeaseSetPrivateSigningKey sets the host of the SAMEmit's SAM bridge
// SetLeaseSetPrivateSigningKey sets the host of the SAMEmit's SAM bridge
func SetLeaseSetPrivateSigningKey(s string) func(*SAMEmit) error {
return func(c *SAMEmit) error {
c.I2PConfig.LeaseSetPrivateSigningKey = s
return nil
}
}

//SetMessageReliability sets the host of the SAMEmit's SAM bridge
// SetMessageReliability sets the host of the SAMEmit's SAM bridge
func SetMessageReliability(s string) func(*SAMEmit) error {
return func(c *SAMEmit) error {
c.I2PConfig.MessageReliability = s
return nil
}
}

//SetAllowZeroIn tells the tunnel to accept zero-hop peers
// SetAllowZeroIn tells the tunnel to accept zero-hop peers
func SetAllowZeroIn(b bool) func(*SAMEmit) error {
return func(c *SAMEmit) error {
if b {
Expand All @@ -216,7 +216,7 @@ func SetAllowZeroIn(b bool) func(*SAMEmit) error {
}
}

//SetAllowZeroOut tells the tunnel to accept zero-hop peers
// SetAllowZeroOut tells the tunnel to accept zero-hop peers
func SetAllowZeroOut(b bool) func(*SAMEmit) error {
return func(c *SAMEmit) error {
if b {
Expand All @@ -228,7 +228,7 @@ func SetAllowZeroOut(b bool) func(*SAMEmit) error {
}
}

//SetCompress tells clients to use compression
// SetCompress tells clients to use compression
func SetCompress(b bool) func(*SAMEmit) error {
return func(c *SAMEmit) error {
if b {
Expand All @@ -240,7 +240,7 @@ func SetCompress(b bool) func(*SAMEmit) error {
}
}

//SetFastRecieve tells clients to use compression
// SetFastRecieve tells clients to use compression
func SetFastRecieve(b bool) func(*SAMEmit) error {
return func(c *SAMEmit) error {
if b {
Expand All @@ -252,7 +252,7 @@ func SetFastRecieve(b bool) func(*SAMEmit) error {
}
}

//SetReduceIdle tells the connection to reduce it's tunnels during extended idle time.
// SetReduceIdle tells the connection to reduce it's tunnels during extended idle time.
func SetReduceIdle(b bool) func(*SAMEmit) error {
return func(c *SAMEmit) error {
if b {
Expand All @@ -264,7 +264,7 @@ func SetReduceIdle(b bool) func(*SAMEmit) error {
}
}

//SetReduceIdleTime sets the time to wait before reducing tunnels to idle levels
// SetReduceIdleTime sets the time to wait before reducing tunnels to idle levels
func SetReduceIdleTime(u int) func(*SAMEmit) error {
return func(c *SAMEmit) error {
c.I2PConfig.ReduceIdleTime = "300000"
Expand All @@ -276,7 +276,7 @@ func SetReduceIdleTime(u int) func(*SAMEmit) error {
}
}

//SetReduceIdleTimeMs sets the time to wait before reducing tunnels to idle levels in milliseconds
// SetReduceIdleTimeMs sets the time to wait before reducing tunnels to idle levels in milliseconds
func SetReduceIdleTimeMs(u int) func(*SAMEmit) error {
return func(c *SAMEmit) error {
c.I2PConfig.ReduceIdleTime = "300000"
Expand All @@ -288,7 +288,7 @@ func SetReduceIdleTimeMs(u int) func(*SAMEmit) error {
}
}

//SetReduceIdleQuantity sets minimum number of tunnels to reduce to during idle time
// SetReduceIdleQuantity sets minimum number of tunnels to reduce to during idle time
func SetReduceIdleQuantity(u int) func(*SAMEmit) error {
return func(c *SAMEmit) error {
if u < 5 {
Expand All @@ -299,7 +299,7 @@ func SetReduceIdleQuantity(u int) func(*SAMEmit) error {
}
}

//SetCloseIdle tells the connection to close it's tunnels during extended idle time.
// SetCloseIdle tells the connection to close it's tunnels during extended idle time.
func SetCloseIdle(b bool) func(*SAMEmit) error {
return func(c *SAMEmit) error {
if b {
Expand All @@ -311,7 +311,7 @@ func SetCloseIdle(b bool) func(*SAMEmit) error {
}
}

//SetCloseIdleTime sets the time to wait before closing tunnels to idle levels
// SetCloseIdleTime sets the time to wait before closing tunnels to idle levels
func SetCloseIdleTime(u int) func(*SAMEmit) error {
return func(c *SAMEmit) error {
c.I2PConfig.CloseIdleTime = "300000"
Expand All @@ -323,7 +323,7 @@ func SetCloseIdleTime(u int) func(*SAMEmit) error {
}
}

//SetCloseIdleTimeMs sets the time to wait before closing tunnels to idle levels in milliseconds
// SetCloseIdleTimeMs sets the time to wait before closing tunnels to idle levels in milliseconds
func SetCloseIdleTimeMs(u int) func(*SAMEmit) error {
return func(c *SAMEmit) error {
c.I2PConfig.CloseIdleTime = "300000"
Expand All @@ -335,7 +335,7 @@ func SetCloseIdleTimeMs(u int) func(*SAMEmit) error {
}
}

//SetAccessListType tells the system to treat the AccessList as a whitelist
// SetAccessListType tells the system to treat the AccessList as a whitelist
func SetAccessListType(s string) func(*SAMEmit) error {
return func(c *SAMEmit) error {
if s == "whitelist" {
Expand All @@ -355,7 +355,7 @@ func SetAccessListType(s string) func(*SAMEmit) error {
}
}

//SetAccessList tells the system to treat the AccessList as a whitelist
// SetAccessList tells the system to treat the AccessList as a whitelist
func SetAccessList(s []string) func(*SAMEmit) error {
return func(c *SAMEmit) error {
if len(s) > 0 {
Expand Down
5 changes: 1 addition & 4 deletions emit.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ type SAMEmit struct {
}

func (e *SAMEmit) OptStr() string {
optStr := ""
for _, opt := range e.I2PConfig.Print() {
optStr += opt + " "
}
optStr := strings.Join(e.I2PConfig.Print(), " ")
return optStr
}

Expand Down
5 changes: 1 addition & 4 deletions sam3.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,7 @@ func (sam *SAM) newGenericSessionWithSignature(style, id string, keys i2pkeys.I2
// This sam3 instance is now a session
func (sam *SAM) newGenericSessionWithSignatureAndPorts(style, id, from, to string, keys i2pkeys.I2PKeys, sigType string, options []string, extras []string) (net.Conn, error) {

optStr := ""
for _, opt := range options {
optStr += opt + " "
}
optStr := GenerateOptionString(options)

conn := sam.conn
fp := ""
Expand Down
9 changes: 9 additions & 0 deletions suggestedOptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"net"
"net/http"
"os"
"strings"
)

// Examples and suggestions for options when creating sessions.
Expand Down Expand Up @@ -105,3 +106,11 @@ func SAMDefaultAddr(fallforward string) string {
}
return fallforward
}

func GenerateOptionString(opts []string) string {
optStr := strings.Join(opts, " ")
if strings.Contains(optStr, "i2cp.leaseSetEncType") {
return optStr
}
return optStr + " i2cp.leaseSetEncType=4,0"
}

0 comments on commit 3dc49e3

Please sign in to comment.