"bufio"
"bytes"
"compress/zlib"
- "crypto/cipher"
"crypto/rand"
"errors"
"hash"
"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) {
}
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 {
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)),
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)),
"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",