mirror of
https://github.com/go-i2p/go-i2ptunnel-config.git
synced 2025-07-12 21:59:33 -04:00
fix compile erors
This commit is contained in:
3
go.mod
3
go.mod
@ -3,6 +3,7 @@ module github.com/go-i2p/go-i2ptunnel-config
|
||||
go 1.23.5
|
||||
|
||||
require (
|
||||
github.com/go-i2p/i2pkeys v0.33.92
|
||||
github.com/magiconair/properties v1.8.9
|
||||
github.com/urfave/cli v1.22.16
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
@ -11,4 +12,6 @@ require (
|
||||
require (
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
|
||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||
github.com/sirupsen/logrus v1.9.3 // indirect
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
|
||||
)
|
||||
|
7
go.sum
7
go.sum
@ -4,16 +4,21 @@ github.com/cpuguy83/go-md2man/v2 v2.0.5/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/go-i2p/i2pkeys v0.33.92 h1:e2vx3vf7tNesaJ8HmAlGPOcfiGM86jzeIGxh27I9J2Y=
|
||||
github.com/go-i2p/i2pkeys v0.33.92/go.mod h1:BRURQ/twxV0WKjZlFSKki93ivBi+MirZPWudfwTzMpE=
|
||||
github.com/magiconair/properties v1.8.9 h1:nWcCbLq1N2v/cpNsy5WvQ37Fb+YElfq20WJ/a8RkpQM=
|
||||
github.com/magiconair/properties v1.8.9/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
||||
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
@ -21,6 +26,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/urfave/cli v1.22.16 h1:MH0k6uJxdwdeWQTwhSO42Pwr4YLrNLwBtg1MRgTqPdQ=
|
||||
github.com/urfave/cli v1.22.16/go.mod h1:EeJR6BKodywf4zciqrdw6hpCPk68JO9z5LazXZMn5Po=
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
|
125
lib/sam.go
125
lib/sam.go
@ -1,76 +1,83 @@
|
||||
package i2pconv
|
||||
|
||||
import (
|
||||
"github.com/go-i2p/i2pkeys"
|
||||
"path/filepath"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/go-i2p/i2pkeys"
|
||||
)
|
||||
|
||||
// SAMTunnel returns the I2P keys and SAM options for this tunnel configuration.
|
||||
// If PersistentKeys is true, keys will be stored in a SAMv3 compatible format.
|
||||
func (c *TunnelConfig) SAMTunnel() (*i2pkeys.I2PKeys, []string, error) {
|
||||
var keys *i2pkeys.I2PKeys
|
||||
var err error
|
||||
|
||||
if c.PersistentKeys {
|
||||
// Get default I2P keystore path
|
||||
keystore, err := i2pkeys.I2PKeystorePath()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
// Load or create keys for this tunnel
|
||||
keypath := filepath.Join(keystore, c.Name+".keys")
|
||||
loadedKeys, err := i2pkeys.LoadKeys(keypath)
|
||||
if err == nil {
|
||||
keys = &loadedKeys
|
||||
} else {
|
||||
// Create new keys if none exist
|
||||
newKeys, err := i2pkeys.GenerateKeys()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
keys = &newKeys
|
||||
// Store the new keys
|
||||
if err := i2pkeys.StoreKeysIncompat(newKeys, keypath); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
var keys *i2pkeys.I2PKeys
|
||||
|
||||
// Generate SAM options from config
|
||||
var opts []string
|
||||
|
||||
// Process I2CP options
|
||||
for k, v := range c.I2CP {
|
||||
opts = append(opts, "i2cp."+k+"="+fmt.Sprint(v))
|
||||
}
|
||||
if c.PersistentKey {
|
||||
// Get default I2P keystore path
|
||||
keystore, err := os.Getwd()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
// Process tunnel options
|
||||
for k, v := range c.Tunnel {
|
||||
opts = append(opts, k+"="+fmt.Sprint(v))
|
||||
}
|
||||
// Load or create keys for this tunnel
|
||||
keypath := filepath.Join(keystore, c.Name+".keys")
|
||||
loadedKeys, err := i2pkeys.LoadKeys(keypath)
|
||||
if err == nil {
|
||||
keys = &loadedKeys
|
||||
} else {
|
||||
// Create new keys if none exist
|
||||
newKeys, err := i2pkeys.NewDestination()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
keys = newKeys
|
||||
// Store the new
|
||||
keyFile, err := os.Open(keypath)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if err := i2pkeys.StoreKeysIncompat(*newKeys, keyFile); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Process inbound/outbound options
|
||||
for k, v := range c.Inbound {
|
||||
opts = append(opts, "inbound."+k+"="+fmt.Sprint(v))
|
||||
}
|
||||
for k, v := range c.Outbound {
|
||||
opts = append(opts, "outbound."+k+"="+fmt.Sprint(v))
|
||||
}
|
||||
// Generate SAM options from config
|
||||
var opts []string
|
||||
|
||||
// Ensure lease set encryption
|
||||
if !hasOption(opts, "i2cp.leaseSetEncType") {
|
||||
opts = append(opts, "i2cp.leaseSetEncType=4,0")
|
||||
}
|
||||
// Process I2CP options
|
||||
for k, v := range c.I2CP {
|
||||
opts = append(opts, "i2cp."+k+"="+fmt.Sprint(v))
|
||||
}
|
||||
|
||||
return keys, opts, nil
|
||||
// Process tunnel options
|
||||
for k, v := range c.Tunnel {
|
||||
opts = append(opts, k+"="+fmt.Sprint(v))
|
||||
}
|
||||
|
||||
// Process inbound/outbound options
|
||||
for k, v := range c.Inbound {
|
||||
opts = append(opts, "inbound."+k+"="+fmt.Sprint(v))
|
||||
}
|
||||
for k, v := range c.Outbound {
|
||||
opts = append(opts, "outbound."+k+"="+fmt.Sprint(v))
|
||||
}
|
||||
|
||||
// Ensure lease set encryption
|
||||
if !hasOption(opts, "i2cp.leaseSetEncType") {
|
||||
opts = append(opts, "i2cp.leaseSetEncType=4,0")
|
||||
}
|
||||
|
||||
return keys, opts, nil
|
||||
}
|
||||
|
||||
func hasOption(opts []string, prefix string) bool {
|
||||
for _, opt := range opts {
|
||||
if strings.HasPrefix(opt, prefix) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
for _, opt := range opts {
|
||||
if strings.HasPrefix(opt, prefix) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
Reference in New Issue
Block a user