Documentation ¶
Index ¶
- Constants
- func SplitURI(uri string) (string, string, string, error)
- func SplitURIS(uri string) (string, int, string, string, error)
- func SplitURL(url *url.URL) (string, string, string, error)
- func TrimPrepath(prepath string) string
- type Attribs
- type ClientAuth
- type ClientOption
- type Conn
- func (conn *Conn) Close() error
- func (conn *Conn) Read(p []byte) (n int, err error)
- func (conn *Conn) ReadByte() (byte, error)
- func (conn *Conn) ReadInt() (int32, error)
- func (conn *Conn) ReadLong() (int64, error)
- func (conn *Conn) ReadShort() (int16, error)
- func (conn *Conn) ReadVarint() (int64, error)
- func (conn *Conn) Write(p []byte) (n int, err error)
- func (conn *Conn) WriteByte(data byte) error
- func (conn *Conn) WriteInt(data int32) error
- func (conn *Conn) WriteLong(data int64) error
- func (conn *Conn) WriteShort(data int16) error
- type ExclusionList
- type FS
- type File
- type FileInfo
- type FileList
- type FileMetadata
- type FileMode
- type FlatedtokenReader
- type MuxReader
- type Receiver
- func (r *Receiver) FileCleaner(localList FileList, deleteList []int) error
- func (r *Receiver) FileDownloader(localList FileList) error
- func (r *Receiver) FinalPhase() error
- func (r *Receiver) Generator(remoteList FileList, downloadList []int, symlinks map[string][]byte) error
- func (r *Receiver) GetSyncPlan() (*SyncPlan, error)
- func (r *Receiver) List() error
- func (r *Receiver) RecvFileList() (FileList, map[string][]byte, error)
- func (r *Receiver) Sync() error
- type SSH
- type SendReceiver
- type Sender
- type SumChunk
- type SumStruct
- type SyncPlan
Constants ¶
const ( END_FLAG = 0 TOKEN_LONG = 0x20 TOKENRUN_LONG = 0x21 DEFLATED_DATA = 0x40 TOKEN_REL = 0x80 TOKENRUN_REL = 0xc0 )
const ( RSYNC_VERSION = "@RSYNCD: 27.0\n" RSYNC_AUTHREQD = "@RSYNCD: AUTHREQD" RSYNCD_OK = "@RSYNCD: OK" RSYNC_EXIT = "@RSYNCD: EXIT" K = 1 << 10 M = 1 << 20 G = 1 << 30 MAXPATHLEN = 1024 INDEX_END = int32(-1) EXCLUSION_END = int32(0) END1 = '\n' END2 = '\x00' PHASE_END = int32(-1) // ARGUMENTS ARG_SERVER = "--server" ARG_SENDER = "--sender" ARG_SYMLINK = "-l" ARG_RECURSIVE = "-r" ARG_PERMS = "-p" SAMPLE_ARGS = "--server\n--sender\n-l\n-p\n-r\n-t\n.\n" SAMPLE_LIST_ARGS = "--server\n--sender\n--list-only\n-l\n-p\n-r\n-t\n.\n" // For Multiplex(1 byte) MUX_BASE = 7 MSG_DATA = 0 MSG_ERROR_XFER = 1 MSG_INFO = 2 MSG_ERROR = 3 MSG_WARNING = 4 MSG_IO_ERROR = 22 MSG_NOOP = 42 MSG_SUCCESS = 100 MSG_DELETED = 101 MSG_NO_SEND = 102 // For FILE LIST(1 byte) FLIST_END = 0x00 FLIST_TOP_LEVEL = 0x01 /* needed for remote --delete */ FLIST_MODE_SAME = 0x02 /* mode is repeat */ FLIST_RDEV_SAME = 0x04 /* rdev is repeat */ FLIST_UID_SAME = 0x08 /* uid is repeat */ FLIST_GID_SAME = 0x10 /* gid is repeat */ FLIST_NAME_SAME = 0x20 /* name is repeat */ FLIST_NAME_LONG = 0x40 /* name >255 bytes */ FLIST_TIME_SAME = 0x80 /* time is repeat */ // File type S_IFMT = 0o170000 /* Type of file */ S_IFREG = 0o100000 /* Regular file. */ S_IFDIR = 0o040000 /* Directory. */ S_IFLNK = 0o120000 /* Symbolic link. */ S_IFCHR = 0o020000 /* Character device. */ S_IFBLK = 0o060000 /* Block device. */ S_IFIFO = 0o010000 /* FIFO. */ S_IFSOCK = 0o140000 /* Socket. */ )
Variables ¶
This section is empty.
Functions ¶
func TrimPrepath ¶
The path always has a trailing slash appended
Types ¶
type Attribs ¶
type ClientAuth ¶
type ClientOption ¶
type ClientOption func(*clientOptions)
func WithClientAuth ¶
func WithClientAuth(username, password string) ClientOption
func WithExclusionList ¶
func WithExclusionList(exclusionList ExclusionList) ClientOption
func WithLogger ¶
func WithLogger(logger *slog.Logger) ClientOption
type Conn ¶
type Conn struct { Writer io.WriteCloser // Write only Reader io.ReadCloser // Read only Bytespool []byte // Anti memory-wasted, default size: 8 bytes }
io.ReadWriteCloser This struct has two main attributes, both of them can be used for a plain socket or an SSH
func (*Conn) Close ¶
TODO: If both writer and reader are based on a same Connection (socket, SSH), how to close them twice?
func (*Conn) ReadVarint ¶
func (*Conn) WriteShort ¶
type ExclusionList ¶
type ExclusionList []string
Filter List
func (ExclusionList) SendExlusionList ¶
func (e ExclusionList) SendExlusionList(conn *Conn) error
This is only called by the client
type FS ¶
type FS interface { Put(fileName string, content io.Reader, fileSize int64, metadata FileMetadata) (written int64, err error) // Get(fileName string, metadata FileMetadata) (File, error) Delete(fileName string, mode FileMode) error List() (FileList, error) }
File System: need to handle all type of files: regular, folder, symlink, etc
type FileList ¶
type FileList []FileInfo
type FileMetadata ¶
type FlatedtokenReader ¶
type FlatedtokenReader struct { In Conn Flatedwraper *flatedWraper Decompressor io.ReadCloser Savedflag byte Flag byte Remains uint32 }
RFC 1951: https://tools.ietf.org/html/rfc1951
func NewflatedtokenReader ¶
func NewflatedtokenReader(reader Conn) *FlatedtokenReader
func (*FlatedtokenReader) Close ¶
func (f *FlatedtokenReader) Close() error
func (*FlatedtokenReader) ReadFlag ¶
func (f *FlatedtokenReader) ReadFlag() error
Update flag & len of remain data
type MuxReader ¶
type MuxReader struct { In io.ReadCloser Remain uint32 // Default value: 0 Header []byte // Size: 4 bytes Logger *slog.Logger }
func NewMuxReader ¶
func NewMuxReader(reader io.ReadCloser, logger *slog.Logger) *MuxReader
type Receiver ¶
type Receiver struct { Conn *Conn Module string Path string Seed int32 LVer int32 RVer int32 Storage FS Logger *slog.Logger }
Receiver:
1. Receive File list 2. Request files by sending files' index 3. Receive Files, pass the files to Storage
func (*Receiver) FileCleaner ¶
Clean up local files
func (*Receiver) FileDownloader ¶
TODO: It is better to update files in goroutine
func (*Receiver) FinalPhase ¶
func (*Receiver) Generator ¶
func (r *Receiver) Generator(remoteList FileList, downloadList []int, symlinks map[string][]byte) error
Generator: handle files: if it's a regular file, send its index. Otherwise, put them to Storage
func (*Receiver) GetSyncPlan ¶
func (*Receiver) RecvFileList ¶
Return a filelist from remote
type SendReceiver ¶
func SSHClient ¶
func SSHClient(storage FS, address string, module string, path string, _ map[string]string) (SendReceiver, error)
Connect to sshd, and start a rsync server on remote
func SocketClient ¶
func SocketClient(storage FS, address string, module string, path string, opts ...ClientOption) (SendReceiver, error)
TODO: passes more arguments: cmd Connect to rsync daemon
type Sender ¶
type Sender struct { Conn *Conn Module string Path string Seed int32 LVer int32 RVer int32 Storage FS }