]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/cypherpunks.ru/nncp/tx.go
Merge branch 'develop'
[nncp.git] / src / cypherpunks.ru / nncp / tx.go
index 2c9bd07ba790a6e91573e13566fb2af5e66b6086..5dff27c3be2aa5dcd030eabb0ea8d1bc20191da6 100644 (file)
@@ -22,7 +22,6 @@ import (
        "bufio"
        "bytes"
        "compress/zlib"
-       "crypto/cipher"
        "crypto/rand"
        "errors"
        "hash"
@@ -35,7 +34,6 @@ import (
 
        "github.com/davecgh/go-xdr/xdr2"
        "golang.org/x/crypto/blake2b"
-       "golang.org/x/crypto/twofish"
 )
 
 func (ctx *Ctx) Tx(node *Node, pkt *Pkt, nice uint8, size, minSize int64, src io.Reader) (*Node, error) {
@@ -119,25 +117,20 @@ func prepareTxFile(srcPath string) (io.Reader, *os.File, int64, error) {
                }
                os.Remove(src.Name())
                tmpW := bufio.NewWriter(src)
-
-               tmpKey := make([]byte, 32)
-               if _, err = rand.Read(tmpKey); err != nil {
-                       return nil, nil, 0, err
-               }
-               ciph, err := twofish.NewCipher(tmpKey)
-               if err != nil {
+               tmpKey := new([32]byte)
+               if _, err = rand.Read(tmpKey[:]); err != nil {
                        return nil, nil, 0, err
                }
-               ctr := cipher.NewCTR(ciph, make([]byte, twofish.BlockSize))
-               encrypter := &cipher.StreamWriter{S: ctr, W: tmpW}
-               fileSize, err = io.Copy(encrypter, bufio.NewReader(os.Stdin))
+               written, err := ae(tmpKey, bufio.NewReader(os.Stdin), tmpW)
                if err != nil {
                        return nil, nil, 0, err
                }
+               fileSize = int64(written)
                tmpW.Flush()
                src.Seek(0, 0)
-               ctr = cipher.NewCTR(ciph, make([]byte, twofish.BlockSize))
-               reader = &cipher.StreamReader{S: ctr, R: bufio.NewReader(src)}
+               r, w := io.Pipe()
+               go ae(tmpKey, bufio.NewReader(src), w)
+               reader = r
        } else {
                src, err = os.Open(srcPath)
                if err != nil {
@@ -258,7 +251,7 @@ func (ctx *Ctx) TxFileChunked(node *Node, nice uint8, srcPath, dstPath string, m
                        io.TeeReader(reader, hsh),
                )
                if err == nil {
-                       ctx.LogD("tx", SDS{
+                       ctx.LogI("tx", SDS{
                                "type": "file",
                                "node": node.Id,
                                "nice": strconv.Itoa(int(nice)),
@@ -298,7 +291,7 @@ func (ctx *Ctx) TxFileChunked(node *Node, nice uint8, srcPath, dstPath string, m
        metaPktSize := int64(metaBuf.Len())
        _, err = ctx.Tx(node, pkt, nice, metaPktSize, minSize, &metaBuf)
        if err == nil {
-               ctx.LogD("tx", SDS{
+               ctx.LogI("tx", SDS{
                        "type": "file",
                        "node": node.Id,
                        "nice": strconv.Itoa(int(nice)),
@@ -306,14 +299,6 @@ func (ctx *Ctx) TxFileChunked(node *Node, nice uint8, srcPath, dstPath string, m
                        "dst":  path,
                        "size": strconv.FormatInt(metaPktSize, 10),
                }, "sent")
-               ctx.LogI("tx", SDS{
-                       "type": "file",
-                       "node": node.Id,
-                       "nice": strconv.Itoa(int(nice)),
-                       "src":  srcPath,
-                       "dst":  dstPath,
-                       "size": strconv.FormatInt(fileSize, 10),
-               }, "sent")
        } else {
                ctx.LogE("tx", SDS{
                        "type": "file",