diff --git a/conn/conn.go b/conn/conn.go index 1fd9d25..9deacc5 100644 --- a/conn/conn.go +++ b/conn/conn.go @@ -6,20 +6,51 @@ import ( ) type Conn struct { + sam3.I2PKeys + *sam3.StreamSession *sam3.SAMConn path string } -func (c Conn) SaveKeys() { - +func (c Conn) FindKeys() bool { + return true } -func NewConn(conn *sam3.SAMConn, path string) (*Conn, error) { - return GenConn(conn, path), nil +func (c Conn) SaveKeys() (*sam3.I2PKeys, error) { + return &c.I2PKeys, nil } -func GenConn(conn *sam3.SAMConn, path string) *Conn { - var c = Conn{SAMConn: conn, path: path} +func (c Conn) LoadKeys() (*sam3.I2PKeys, error) { + return &c.I2PKeys, nil +} + +func (c Conn) Keys() (*sam3.I2PKeys, error) { + if c.FindKeys() { + return c.LoadKeys() + } + return c.SaveKeys() +} + +func NewConn(sam *sam3.SAM, addr, path string, opts []string) (*Conn, error) { + var c Conn + var err error + c.I2PKeys, err = sam.NewKeys() + if err != nil { + return nil, err + } + c.path = path + c.I2PKeys.Addr().Base32() c.SaveKeys() - return &c + c.StreamSession, err = sam.NewStreamSession("stream_example", c.I2PKeys, sam3.Options_Small) + if err != nil { + return nil, err + } + return &c, nil +} + +func GenConn(sam *sam3.SAM, addr, path string, opts []string) *Conn { + c, err := NewConn(sam, addr, path, opts) + if err != nil { + panic(err) + } + return c } diff --git a/socks/manager.go b/socks/manager.go index 5f1efa6..d15a78e 100644 --- a/socks/manager.go +++ b/socks/manager.go @@ -17,12 +17,12 @@ import ( type Manager struct { resolver.Resolver socks5.Config - sam3.StreamSession + *sam3.SAM conns []*conn.Conn datadir string samhost string samport string - samopts string + samopts []string } func (m Manager) Serve() error { @@ -40,11 +40,11 @@ func (m Manager) DialI2P(ctx context.Context, addr string) (*sam3.SAMConn, error return c.SAMConn, nil } } - newconn, err := m.StreamSession.DialI2P(i2paddr) + newconn, err := conn.NewConn(m.SAM, addr, m.datadir, m.samopts) if err != nil { return nil, err } - m.conns = append(m.conns, conn.GenConn(newconn, m.datadir)) + m.conns = append(m.conns, newconn) log.Println("Generated destination for address:", i2paddr.Base32(), "at position", len(m.conns)-1) return m.conns[len(m.conns)-1].SAMConn, nil } diff --git a/socks/manager_options.go b/socks/manager_options.go index 2d6fe4f..e04c3e6 100644 --- a/socks/manager_options.go +++ b/socks/manager_options.go @@ -43,7 +43,9 @@ func SetPort(v string) func(*Manager) error { func SetSAMOpts(s []string) func(*Manager) error { return func(c *Manager) error { for _, i := range s { - c.samopts += i + " " + if i != "" { + c.samopts = append(c.samopts, i) + } } return nil }