Actually save keys in SaveKeys.
This commit is contained in:
parent
7b06157524
commit
b40b2f03af
1 changed files with 24 additions and 8 deletions
32
conn/conn.go
32
conn/conn.go
|
@ -1,11 +1,13 @@
|
||||||
package conn
|
package conn
|
||||||
|
|
||||||
import (
|
import (
|
||||||
//"os"
|
"bufio"
|
||||||
"github.com/eyedeekay/sam3"
|
"github.com/eyedeekay/sam3"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Conn struct {
|
type Conn struct {
|
||||||
|
*sam3.SAM
|
||||||
sam3.I2PKeys
|
sam3.I2PKeys
|
||||||
*sam3.StreamSession
|
*sam3.StreamSession
|
||||||
*sam3.SAMConn
|
*sam3.SAMConn
|
||||||
|
@ -16,19 +18,32 @@ func (c Conn) FindKeys() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Conn) SaveKeys() (*sam3.I2PKeys, error) {
|
func (c Conn) SaveKeys() (sam3.I2PKeys, error) {
|
||||||
c.I2PKeys, err = sam.NewKeys()
|
var err error
|
||||||
|
c.I2PKeys, err = c.SAM.NewKeys()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return sam3.I2PKeys{}, err
|
||||||
}
|
}
|
||||||
return &c.I2PKeys, nil
|
f, err := os.Create(c.path)
|
||||||
|
if err != nil {
|
||||||
|
return sam3.I2PKeys{}, err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
filewriter := bufio.NewWriter(f)
|
||||||
|
err = sam3.StoreKeysIncompat(c.I2PKeys, filewriter)
|
||||||
|
if err != nil {
|
||||||
|
return sam3.I2PKeys{}, err
|
||||||
|
}
|
||||||
|
filewriter.Flush()
|
||||||
|
return c.I2PKeys, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Conn) LoadKeys() (*sam3.I2PKeys, error) {
|
func (c Conn) LoadKeys() (sam3.I2PKeys, error) {
|
||||||
return &c.I2PKeys, nil
|
//sam3.LoadKeysIncompat(filereader)
|
||||||
|
return c.I2PKeys, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Conn) Keys() (*sam3.I2PKeys, error) {
|
func (c Conn) Keys() (sam3.I2PKeys, error) {
|
||||||
if c.FindKeys() {
|
if c.FindKeys() {
|
||||||
return c.LoadKeys()
|
return c.LoadKeys()
|
||||||
}
|
}
|
||||||
|
@ -48,6 +63,7 @@ func (m Conn) Cleanup() error {
|
||||||
func NewConn(sam *sam3.SAM, addr, path string, opts []string) (*Conn, error) {
|
func NewConn(sam *sam3.SAM, addr, path string, opts []string) (*Conn, error) {
|
||||||
var c Conn
|
var c Conn
|
||||||
var err error
|
var err error
|
||||||
|
c.SAM = sam
|
||||||
c.path = path + addr + ".i2pkeys"
|
c.path = path + addr + ".i2pkeys"
|
||||||
c.I2PKeys, err = c.Keys()
|
c.I2PKeys, err = c.Keys()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue