Use LevelDB storage backend

This commit is contained in:
Jakob Borg
2014-07-06 14:46:48 +02:00
parent 4a88d1244d
commit 31350b4352
114 changed files with 20315 additions and 683 deletions

View File

@@ -7,6 +7,7 @@ package scanner
import (
"bytes"
"crypto/sha256"
"fmt"
"io"
)
@@ -18,6 +19,10 @@ type Block struct {
Hash []byte
}
func (b Block) String() string {
return fmt.Sprintf("%d/%d/%x", b.Offset, b.Size, b.Hash)
}
// Blocks returns the blockwise hash of the reader.
func Blocks(r io.Reader, blocksize int) ([]Block, error) {
var blocks []Block

45
scanner/blocks_xdr.go Normal file
View File

@@ -0,0 +1,45 @@
package scanner
import (
"bytes"
"io"
"github.com/calmh/syncthing/xdr"
)
func (o Block) EncodeXDR(w io.Writer) (int, error) {
var xw = xdr.NewWriter(w)
return o.encodeXDR(xw)
}
func (o Block) MarshalXDR() []byte {
var buf bytes.Buffer
var xw = xdr.NewWriter(&buf)
o.encodeXDR(xw)
return buf.Bytes()
}
func (o Block) encodeXDR(xw *xdr.Writer) (int, error) {
xw.WriteUint64(uint64(o.Offset))
xw.WriteUint32(o.Size)
xw.WriteBytes(o.Hash)
return xw.Tot(), xw.Error()
}
func (o *Block) DecodeXDR(r io.Reader) error {
xr := xdr.NewReader(r)
return o.decodeXDR(xr)
}
func (o *Block) UnmarshalXDR(bs []byte) error {
var buf = bytes.NewBuffer(bs)
var xr = xdr.NewReader(buf)
return o.decodeXDR(xr)
}
func (o *Block) decodeXDR(xr *xdr.Reader) error {
o.Offset = int64(xr.ReadUint64())
o.Size = xr.ReadUint32()
o.Hash = xr.ReadBytes()
return xr.Error()
}

View File

@@ -17,8 +17,8 @@ type File struct {
}
func (f File) String() string {
return fmt.Sprintf("File{Name:%q, Flags:0%o, Modified:%d, Version:%d, Size:%d, NumBlocks:%d, Sup:%v}",
f.Name, f.Flags, f.Modified, f.Version, f.Size, len(f.Blocks), f.Suppressed)
return fmt.Sprintf("File{Name:%q, Flags:0%o, Modified:%d, Version:%d, Size:%d, Blocks:%v, Sup:%v}",
f.Name, f.Flags, f.Modified, f.Version, f.Size, f.Blocks, f.Suppressed)
}
func (f File) Equals(o File) bool {

60
scanner/file_xdr.go Normal file
View File

@@ -0,0 +1,60 @@
package scanner
import (
"bytes"
"io"
"github.com/calmh/syncthing/xdr"
)
func (o File) EncodeXDR(w io.Writer) (int, error) {
var xw = xdr.NewWriter(w)
return o.encodeXDR(xw)
}
func (o File) MarshalXDR() []byte {
var buf bytes.Buffer
var xw = xdr.NewWriter(&buf)
o.encodeXDR(xw)
return buf.Bytes()
}
func (o File) encodeXDR(xw *xdr.Writer) (int, error) {
xw.WriteString(o.Name)
xw.WriteUint32(o.Flags)
xw.WriteUint64(uint64(o.Modified))
xw.WriteUint64(o.Version)
xw.WriteUint64(uint64(o.Size))
xw.WriteUint32(uint32(len(o.Blocks)))
for i := range o.Blocks {
o.Blocks[i].encodeXDR(xw)
}
xw.WriteBool(o.Suppressed)
return xw.Tot(), xw.Error()
}
func (o *File) DecodeXDR(r io.Reader) error {
xr := xdr.NewReader(r)
return o.decodeXDR(xr)
}
func (o *File) UnmarshalXDR(bs []byte) error {
var buf = bytes.NewBuffer(bs)
var xr = xdr.NewReader(buf)
return o.decodeXDR(xr)
}
func (o *File) decodeXDR(xr *xdr.Reader) error {
o.Name = xr.ReadString()
o.Flags = xr.ReadUint32()
o.Modified = int64(xr.ReadUint64())
o.Version = xr.ReadUint64()
o.Size = int64(xr.ReadUint64())
_BlocksSize := int(xr.ReadUint32())
o.Blocks = make([]Block, _BlocksSize)
for i := range o.Blocks {
(&o.Blocks[i]).decodeXDR(xr)
}
o.Suppressed = xr.ReadBool()
return xr.Error()
}

View File

@@ -6,6 +6,7 @@ package scanner
import (
"bytes"
"code.google.com/p/go.text/unicode/norm"
"errors"
"fmt"
"io/ioutil"
@@ -14,7 +15,6 @@ import (
"runtime"
"strings"
"time"
"code.google.com/p/go.text/unicode/norm"
"github.com/calmh/syncthing/lamport"
"github.com/calmh/syncthing/protocol"