resourcePool

package
v0.0.0-...-12c2aea Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 22, 2020 License: MIT Imports: 13 Imported by: 0

README

Git 原理操作

修改一个文件并添加

echo "version 3" | git hash-object -w --stdin # 写入更改内容
# 7170a5278f42ea12d4b6de8ed1305af8c393e756
git update-index --add --cacheinfo 100644 7170a5278f42ea12d4b6de8ed1305af8c393e756 test.txt \
    # 更改内容与文件相关联,存储进暂存区
git write-tree # 记录暂存区,创建内容树
5bee27fca16056be0a14169ffef5b3eceb360028
echo "second commit" | git commit-tree 5bee27fca16056be0a14169ffef5b3eceb360028 -p 59536ed44ea9400a12e787a0f2049f3cc9f1f955 \
    # 提交更改,指定内容树和base提交
b41872763ca59a88411509d4aabe4d4fd56ac78e
  • 初加入

    • 对每个资源池内文件撕裂,分发到其他参与者
    • 每个有同一个资源的人有一样的该资源的checksum
  • 常态

    • 监听资源池内文件变化
    • 发布增量更新内容,同时发布新checksum

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToUInt32

func BytesToUInt32(b []byte) uint32

func DoZlibCompress

func DoZlibCompress(src []byte) []byte

func DoZlibUnCompress

func DoZlibUnCompress(compressSrc []byte) []byte

func IntTo3Bytes

func IntTo3Bytes(i int) [3]byte

func Sha1CheckSum

func Sha1CheckSum(u []byte) [20]byte

Types

type FilePointers

type FilePointers []*GFile

type FileType

type FileType byte

* echo "blob 13\0test content" | shasum d670460b4b4aece5915caf5c68d12f560a9fe3e4 echo 'test content' | git hash-object -w --stdin git cat-file -p d670460b4b4aece5915caf5c68d12f560a9fe3e4 test content

const (
	Blob FileType = 1 << iota
	Neighbor
)

func (FileType) String

func (t FileType) String() string

type GBase

type GBase struct {
	FileType
	FileNameLen uint16 // 文件名限长0xffff
	FileName    string // 变长,为fileNameLen
	Checksum    [20]byte
	// contains filtered or unexported fields
}

func (GBase) String

func (b GBase) String() string

type GBaseInterface

type GBaseInterface interface {
	MarshalJSON() ([]byte, error)
	Read(r io.Reader)
	Write(w io.Writer)
}

type GFile

type GFile struct {
	FileSize uint32 // 存储文件时文件大小占24位(16MB),但是在内存中时占32位(8G)
	GBase
}

func (GFile) MarshalJSON

func (file GFile) MarshalJSON() ([]byte, error)

func (*GFile) Read

func (file *GFile) Read(r io.Reader)

func (*GFile) ReadStash

func (file *GFile) ReadStash(stashDir string) bytes.Buffer

func (GFile) String

func (file GFile) String() string

func (*GFile) Write

func (file *GFile) Write(w io.Writer)

type GHash

type GHash struct {
	GType    FileType
	GLen     uint32
	GBin     []byte
	Mark     [20]byte
	MarkStr  string
	FullBody bytes.Buffer
}

func NewGHash

func NewGHash(content []byte) GHash

func (GHash) GitRecordFile

func (hash GHash) GitRecordFile()

func (GHash) String

func (hash GHash) String() string

type GNeighbor

type GNeighbor struct {
	GTree
	RemoteAddr *utils.UDPAddr
	BridgeAddr *utils.UDPAddr
	Bypass     string
	DivePass   []string
}

func (GNeighbor) BeforeMarshal

func (t GNeighbor) BeforeMarshal() JSlike.Object

func (GNeighbor) MarshalJSON

func (t GNeighbor) MarshalJSON() ([]byte, error)

type GTree

type GTree struct {
	Version   uint32
	FileCount uint32
	Files     FilePointers
	Checksum  [20]byte
	Neighbors []GNeighbor
}

func (GTree) BeforeMarshal

func (t GTree) BeforeMarshal() JSlike.Object

func (GTree) MarshalJSON

func (t GTree) MarshalJSON() ([]byte, error)

func (*GTree) Read

func (t *GTree) Read(r io.Reader)

func (*GTree) SearchFile

func (t *GTree) SearchFile(nameOrHashPrefix string) []GFile

func (*GTree) SearchFileByNameExactly

func (t *GTree) SearchFileByNameExactly(filename string) *GFile

func (*GTree) SearchFileHash

func (t *GTree) SearchFileHash(nameOrHashPrefix string) []string

func (GTree) String

func (t GTree) String() string

func (*GTree) UpdateChecksum

func (t *GTree) UpdateChecksum()

func (*GTree) UpdateFileCount

func (t *GTree) UpdateFileCount()

func (*GTree) Write

func (t *GTree) Write(w io.Writer)

func (*GTree) WriteSummary

func (t *GTree) WriteSummary(w io.Writer)

写入的Neighbors信息不包含Files

type GitIndex

type GitIndex struct {
	DIRC string // "DIRC"
	// contains filtered or unexported fields
}

* Git 暂存区 .git/index

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL