Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some issues found by lint #16

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions internal/anonssh/anonssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ type session struct {
}

func (s *session) request(ctx context.Context, req *ssh.Request) error {
_ = ctx // FIXME: not yet used
stapelberg marked this conversation as resolved.
Show resolved Hide resolved

switch req.Type {

case "env":
Expand Down
2 changes: 1 addition & 1 deletion internal/maincmd/maincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func Main(ctx context.Context, args []string, stdin io.Reader, stdout io.Writer,
opts, opt := rsyncd.NewGetOpt()
remaining, err := opt.Parse(args[1:])
if opt.Called("help") {
fmt.Fprintf(stderr, opt.Help())
fmt.Fprint(stderr, opt.Help())
os.Exit(1)
}
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions internal/receivermaincmd/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (rt *recvTransfer) setPerms(f *file) error {
}
}

st, err = rt.setUid(f, local, st)
_, err = rt.setUid(f, local, st)
if err != nil {
return err
}
Expand Down Expand Up @@ -260,13 +260,13 @@ func (rt *recvTransfer) recvGenerator(idx int, f *file) error {
}

// rsync/generator.c:generate_and_send_sums
func (rt *recvTransfer) generateAndSendSums(in *os.File, len int64) error {
sh := rsynccommon.SumSizesSqroot(len)
func (rt *recvTransfer) generateAndSendSums(in *os.File, fileLen int64) error {
sh := rsynccommon.SumSizesSqroot(fileLen)
if err := sh.WriteTo(rt.conn); err != nil {
return err
}
buf := make([]byte, int(sh.BlockLength))
remaining := len
remaining := fileLen
for i := int32(0); i < sh.ChecksumCount; i++ {
n1 := int64(sh.BlockLength)
if n1 > remaining {
Expand Down
6 changes: 3 additions & 3 deletions internal/receivermaincmd/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ func (rt *recvTransfer) receiveData(f *file, localFile *os.File) error {
}
token = -(token + 1)
offset2 := int64(token) * int64(sh.BlockLength)
len := sh.BlockLength
dataLen := sh.BlockLength
if token == sh.ChecksumCount-1 && sh.RemainderLength != 0 {
len = sh.RemainderLength
dataLen = sh.RemainderLength
}
data = make([]byte, len)
data = make([]byte, dataLen)
if _, err := localFile.ReadAt(data, offset2); err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/receivermaincmd/receivermaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func rsyncMain(osenv osenv, opts *Opts, sources []string, dest string) (*Stats,
user = machine[:idx]
machine = machine[idx+1:]
}
rc, wc, err := doCmd(osenv, opts, machine, user, path, daemonConnection)
rc, wc, err := doCmd(opts, machine, user, path, daemonConnection)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -236,7 +236,7 @@ func (prw *readWriter) Write(p []byte) (n int, err error) {
}

// rsync/main.c:do_cmd
func doCmd(osenv osenv, opts *Opts, machine, user, path string, daemonConnection int) (io.ReadCloser, io.WriteCloser, error) {
func doCmd(opts *Opts, machine, user, path string, daemonConnection int) (io.ReadCloser, io.WriteCloser, error) {
cmd := opts.ShellCommand
if cmd == "" {
cmd = "ssh"
Expand Down
8 changes: 4 additions & 4 deletions internal/rsyncchecksum/rsyncchecksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ func signExtend(b byte) uint32 {
}

func Checksum1(buf []byte) uint32 {
len := len(buf)
bufLen := len(buf)
var s1, s2 uint32
var i int

if len > 4 {
for i = 0; i < (len - 4); i += 4 {
if bufLen > 4 {
for i = 0; i < (bufLen - 4); i += 4 {
s2 += 4*(s1+signExtend(buf[i])) +
3*signExtend(buf[i+1]) +
2*signExtend(buf[i+2]) +
Expand All @@ -39,7 +39,7 @@ func Checksum1(buf []byte) uint32 {
signExtend(buf[i+3])
}
}
for ; i < len; i++ {
for ; i < bufLen; i++ {
s1 += signExtend(buf[i])
s2 += s1
}
Expand Down
8 changes: 4 additions & 4 deletions internal/rsynccommon/rsynccommon.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import (
const blockSize = 700 // rsync/rsync.h

// Corresponds to rsync/generator.c:sum_sizes_sqroot
func SumSizesSqroot(len int64) rsync.SumHead {
func SumSizesSqroot(contentLen int64) rsync.SumHead {
// * The block size is a rounded square root of file length.

// The block size algorithm plays a crucial role in the protocol efficiency. In general, the block size is the rounded square root of the total file size. The minimum block size, however, is 700 B. Otherwise, the square root computation is simply sqrt(3) followed by ceil(3)

// For reasons unknown, the square root result is rounded up to the nearest multiple of eight.

// TODO: round this
blockLength := int32(math.Sqrt(float64(len)))
blockLength := int32(math.Sqrt(float64(contentLen)))
if blockLength < blockSize {
blockLength = blockSize
}
Expand All @@ -32,8 +32,8 @@ func SumSizesSqroot(len int64) rsync.SumHead {
const checksumLength = 16 // TODO?

return rsync.SumHead{
ChecksumCount: int32((len + (int64(blockLength) - 1)) / int64(blockLength)),
RemainderLength: int32(len % int64(blockLength)),
ChecksumCount: int32((contentLen + (int64(blockLength) - 1)) / int64(blockLength)),
RemainderLength: int32(contentLen % int64(blockLength)),
BlockLength: blockLength,
ChecksumLength: checksumLength,
}
Expand Down
2 changes: 1 addition & 1 deletion internal/rsyncd/flist.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

// rsync/flist.c:send_file_list
func (st *sendTransfer) sendFileList(c *rsyncwire.Conn, mod config.Module, opts *Opts, paths []string) (*fileList, error) {
func (st *sendTransfer) sendFileList(mod config.Module, opts *Opts, paths []string) (*fileList, error) {
var fileList fileList
fec := &rsyncwire.Buffer{}

Expand Down
4 changes: 3 additions & 1 deletion internal/rsyncd/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,14 @@ func (st *sendTransfer) matched(h hash.Hash, f *os.File, head rsync.SumHead, off
offset, st.lastMatch, i, head.Sums[i].Len, n)
}

/* FIXME: this is not used
l := int64(0)
if !transmitAccumulated {
l = head.Sums[i].Len
}
*/
stapelberg marked this conversation as resolved.
Show resolved Hide resolved

if err := st.sendToken(f, i, st.lastMatch, n, l); err != nil {
if err := st.sendToken(f, i, st.lastMatch, n); err != nil {
return fmt.Errorf("sendToken: %v", err)
}
// TODO: data_transfer += n;
Expand Down
11 changes: 1 addition & 10 deletions internal/rsyncd/rsyncd.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,6 @@ type fileList struct {
files []file
}

// rsync/rsync.h:struct sum_buf
type sumBuf struct {
offset int64
len int64
index int32
sum1 uint32
sum2 [16]byte
}

// rsync/rsync.h defines chunkSize as 32 * 1024, but increasing it to 256K
// increases throughput with “tridge” rsync as client by 50 Mbit/s.
const chunkSize = 256 * 1024
Expand Down Expand Up @@ -332,7 +323,7 @@ func (s *Server) HandleConn(module config.Module, rd io.Reader, crd *countingRea
// https://github.com/kristapsdz/openrsync/blob/master/rsync.5

// send file list
fileList, err := st.sendFileList(c, module, opts, paths)
fileList, err := st.sendFileList(module, opts, paths)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/rsyncd/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ func (st *sendTransfer) simpleSendToken(f *os.File, token int32, offset int64, n
}
}
if token != -2 {
return st.conn.WriteInt32(-(int32(token) + 1))
return st.conn.WriteInt32(-(token + 1))
}
return nil
}

// rsync/token.c:send_token
func (st *sendTransfer) sendToken(f *os.File, i int32, offset int64, n int64, toklen int64) error {
func (st *sendTransfer) sendToken(f *os.File, i int32, offset int64, n int64) error {
// TODO(compression): send deflated token
return st.simpleSendToken(f, i, offset, n)
}
1 change: 1 addition & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package rsync

import "github.com/gokrazy/rsync/internal/rsyncwire"

// rsync/rsync.h:struct sum_buf
stapelberg marked this conversation as resolved.
Show resolved Hide resolved
type SumBuf struct {
Offset int64
Len int64
Expand Down