node

package
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2024 License: Apache-2.0 Imports: 52 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CANS_PROTO_FLAG            = "CANS_PROTO_"
	CHUNK_FILE_FLAG            = "--CESS-chunk-file--"
	CANS_PROTO_HEADER          = "CanProtocol"
	CANS_SPLIT_FILE_HEADER     = "FileSplit"
	CANS_ARCHIVE_FORMAT_HEADER = "ArchiveFormat"
	FILE_METADATA_KEY          = "_file_metadata_"
)
View Source
const (
	HTTPHeader_Authorization = "Authorization"
	HTTPHeader_Bucket        = "Bucket"
	HTTPHeader_Territory     = "Territory"
	HTTPHeader_Account       = "Account"
	HTTPHeader_EthAccount    = "EthAcc"
	HTTPHeader_Digest        = "Digest"
	HTTPHeader_Operation     = "Operation"
	HTTPHeader_Message       = "Message"
	HTTPHeader_Signature     = "Signature"
	HTTPHeader_Fid           = "Fid"
	HTTPHeader_Cipher        = "Cipher"
	HTTPHeader_BIdx          = "BlockIndex"
	HTTPHeader_BNum          = "BlockNumber"
	HTTPHeader_Fname         = "FileName"
	HTTPHeader_TSize         = "TotalSize"
	HTTPHeader_Format        = "Format"
)

HTTP HEADER

View Source
const (
	Active = iota
	Calculate
	Missing
	Recovery
)
View Source
const (
	HTTP_ParameterName       = "name"
	HTTP_ParameterName_Fid   = "fid"
	HTTP_Parameter_BucketNme = "bucket_name"
	FormFileKey1             = "file"
	FormFileKey2             = "File"
	FormFileKey3             = "FILE"
)
View Source
const (
	INFO_PutRequest         = "PutRequest"
	INFO_PostRestoreRequest = "PostRestoreRequest"
	INFO_GetRequest         = "GetRequest"
	INFO_GetRestoreRequest  = "GetRestoreRequest"
	INFO_DelRequest         = "DelRequest"

	ERR_DuplicateOrder        = "duplicate order"
	ERR_MissToken             = "InvalidHead.MissToken"
	ERR_EmptySeed             = "InvalidProfile.EmptySeed"
	ERR_MissingAccount        = "InvalidHead.MissingAccount"
	ERR_InvalidAccount        = "InvalidHead.Account"
	ERR_NoPermission          = "InvalidToken.NoPermission"
	ERR_InvalidToken          = "InvalidHead.Token"
	ERR_InvalidName           = "InvalidParameter.Name"
	ERR_InvalidFilehash       = "InvalidParameter.FileHash"
	ERR_InvalidParaBucketName = "InvalidParameter.BucketName"
	ERR_InvalidBucketName     = "InvalidHead.BucketName"
	ERR_EmptyBucketName       = "Invalid.EmptyBucketName"
	ERR_UnauthorizedSpace     = "UnauthorizedSpace"
	ERR_EmptyFile             = "InvalidBody.EmptyFile"
	ERR_EmptyBody             = "InvalidBody.EmptyBody"
	ERR_ReadBody              = "InvalidBody.ReadErr"
	ERR_ParseBody             = "InvalidBody.ParseErr"
	//ERR_SpaceExpired          = "space expired"
	ERR_NotEnoughSpace             = "not enough account space"
	ERR_InsufficientTerritorySpace = "insufficient territory space"

	ERR_InternalServer   = "InternalError"
	ERR_FileNameTooLang  = "The file name length cannot exceed 63 characters"
	ERR_FileNameTooShort = "The file name must be at least 3 characters long"
	ERR_NoSpace          = "please purchase space first"
	ERR_NoTerritory      = "please purchase territory first"
)
View Source
const (
	ERR_Authorization = "HeaderErr_Invalid_Authorization"

	ERR_HeadOperation = "HeaderErr_Invalid_Operation"

	ERR_NotFound  = "Not found"
	ERR_Forbidden = "no permission"

	ERR_BodyFormat         = "BodyErr_InvalidDataFormat"
	ERR_BodyFieldAccount   = "BodyErr_InvalidField_account"
	ERR_BodyFieldMessage   = "BodyErr_InvalidField_message"
	ERR_BodyFieldSignature = "BodyErr_InvalidField_signature"
	ERR_BodyEmptyFile      = "BodyErr_EmptyFile"

	ERR_HeaderFieldBucketName = "HeaderErr_InvalidBucketName"

	ERR_AccountNotExist      = "account does not exist"
	ERR_RpcFailed            = "rpc connection failed"
	ERR_SpaceExpiresSoon     = "space expires soon"
	ERR_TerritoryExpiresSoon = "territory expires soon"
	ERR_SpaceNotAuth         = "space is not authorized"
	ERR_DeviceSpaceNoLeft    = "no space left on the server device"

	ERR_SysMemNoLeft = "server unsupported file size"

	ERR_ReceiveFile = "InternalError"
)
View Source
const (
	Cache_SyncBlock       = "syncblock"
	Cache_UserFiles       = "userfiles:"
	Cache_UserDeleteFiles = "userdeletefiles:"
	Cache_WantFiles       = "wantfiles:"
)
View Source
const MaxMemUsed = 512 << 20
View Source
const MinRecordInfoLength = 132

MinRecordInfoLength = len(json.Marshal(RecordInfo{}))

View Source
const Notfound = `` /* 1534-byte string literal not displayed */
View Source
const TokenDated = 60 * 60 * 24 * 30

Variables

This section is empty.

Functions

func DecryptSegment added in v0.3.7

func DecryptSegment(fpath, cipher string) error

func OtherHeader added in v0.3.7

func OtherHeader(c *gin.Context, fname string)

func Subscribe added in v0.3.7

func Subscribe(ctx context.Context, h host.Host, bootnode string, callback func(p peer.AddrInfo))

func VerifyEthSign added in v0.3.6

func VerifyEthSign(message string, sign string) (string, error)

func VideoAndAudioHeader added in v0.3.7

func VideoAndAudioHeader(c *gin.Context, fname string)

Types

type CansRequestParams added in v0.3.7

type CansRequestParams struct {
	SegmentIndex int    `json:"segment_index"`
	SubFile      string `json:"sub_file"`
	Cipher       string `json:"cipher"`
}

type ChunksInfo added in v0.3.7

type ChunksInfo struct {
	BlockNum      int       `json:"block_num"`
	SavedBlocks   []bool    `json:"saved_blocks"`
	Finished      int       `json:"finished"`
	SavedFileSize int64     `json:"saved_file_size"`
	FileName      string    `json:"file_name"`
	TotalSize     int64     `json:"total_size"`
	FlushTime     time.Time `json:"flush_time"`
}

type DuplicateType added in v0.3.7

type DuplicateType uint8
const (
	// not duplicate
	Duplicate0 DuplicateType = 0

	// not in file.owners
	Duplicate1 DuplicateType = 1

	// in file.owners
	Duplicate2 DuplicateType = 2
)

type Location added in v0.3.7

type Location struct {
	Longitude float64 `json:"longitude"`
	Latitude  float64 `json:"latitude"`
}

type Metadata added in v0.3.7

type Metadata struct {
	Fid   string         `json:"fid"`
	Size  uint64         `json:"size"`
	Owner []RtnUserBrief `json:"owner"`
}

file meta info

type Node

type Node struct {
	inter.TrackFile
	confile.Confile
	logger.Logger
	db.Cache
	PeerRecord
	cacher.FileCache
	scheduler.Selector
	*chain.ChainClient
	*core.PeerNode
	*gin.Engine
	// contains filtered or unexported fields
}

func New

func New() *Node

New is used to build a node instance

func (*Node) AccessControl added in v0.3.3

func (n *Node) AccessControl(account string) error

func (*Node) CheckLocalFile added in v0.3.7

func (n *Node) CheckLocalFile(fid string) (int64, string, error)

func (*Node) DeleteStoragePeer added in v0.3.3

func (n *Node) DeleteStoragePeer(peerid string)

func (*Node) DeleteTrackFile

func (n *Node) DeleteTrackFile(filehash string)

func (*Node) Delete_bucket added in v0.3.7

func (n *Node) Delete_bucket(c *gin.Context)

func (*Node) Delete_file added in v0.3.7

func (n *Node) Delete_file(c *gin.Context)

delHandle is used to delete buckets or files

func (*Node) Download_file added in v0.3.7

func (n *Node) Download_file(c *gin.Context)

func (*Node) FeedbackLog added in v0.3.7

func (n *Node) FeedbackLog(c *gin.Context)

func (*Node) GetAllStoragePeerId added in v0.3.3

func (n *Node) GetAllStoragePeerId() []string

func (*Node) GetCanFileHandle added in v0.3.7

func (n *Node) GetCanFileHandle(c *gin.Context)

func (*Node) GetRestoreHandle added in v0.3.7

func (n *Node) GetRestoreHandle(c *gin.Context)

getHandle

func (*Node) GetSegment added in v0.3.7

func (n *Node) GetSegment(fdir, fhash, cipher string, sid int) (fpath string, err error)

func (*Node) Get_bucket added in v0.3.7

func (n *Node) Get_bucket(c *gin.Context)

func (*Node) Get_location added in v0.3.7

func (n *Node) Get_location(c *gin.Context)

func (*Node) Get_metadata added in v0.3.7

func (n *Node) Get_metadata(c *gin.Context)

func (*Node) Get_version added in v0.3.7

func (n *Node) Get_version(c *gin.Context)

getHandle

func (*Node) HasStoragePeer added in v0.3.3

func (n *Node) HasStoragePeer(peerid string) bool

func (*Node) HasTrackFile

func (n *Node) HasTrackFile(filehash string) bool

func (*Node) InitFileCache added in v0.3.7

func (n *Node) InitFileCache(exp time.Duration, maxSpace int64, cacheDir string)

func (*Node) InitNodeSelector added in v0.3.7

func (n *Node) InitNodeSelector(strategy string, nodeFilePath string, maxNodeNum int, maxTTL, flushInterval int64) error

func (*Node) ListTrackFiles

func (n *Node) ListTrackFiles() ([]string, error)

func (*Node) NotFound added in v0.3.7

func (n *Node) NotFound(c *gin.Context)

func (*Node) ParseTrackFile added in v0.3.3

func (n *Node) ParseTrackFile(filehash string) (RecordInfo, error)

func (*Node) Preview_file added in v0.3.7

func (n *Node) Preview_file(c *gin.Context)

func (*Node) PutChunksHandle added in v0.3.7

func (n *Node) PutChunksHandle(c *gin.Context)

func (*Node) Put_bucket added in v0.3.7

func (n *Node) Put_bucket(c *gin.Context)

func (*Node) Put_file added in v0.3.7

func (n *Node) Put_file(c *gin.Context)

func (*Node) Put_object added in v0.3.7

func (n *Node) Put_object(c *gin.Context)

func (*Node) QueryFileType added in v0.3.7

func (n *Node) QueryFileType(fid string, account string) (string, string, int, error)

func (*Node) RebuildDirs

func (n *Node) RebuildDirs()

func (*Node) RefreshMiner added in v0.3.7

func (n *Node) RefreshMiner(ch chan<- bool)

func (*Node) RefreshSelf added in v0.3.7

func (n *Node) RefreshSelf() error

func (*Node) RestoreFile added in v0.3.7

func (n *Node) RestoreFile(c *gin.Context)

getHandle

func (*Node) ReturnFile added in v0.3.7

func (n *Node) ReturnFile(c *gin.Context, reader io.Reader, fid, contenttype, format string, size int64)

func (*Node) Run

func (n *Node) Run()

func (*Node) SaveStoragePeer added in v0.3.3

func (n *Node) SaveStoragePeer(peerid string)

func (*Node) SetFadebackDir added in v0.3.1

func (n *Node) SetFadebackDir(dir string)

func (*Node) SetSignkey

func (n *Node) SetSignkey(signkey []byte)

func (*Node) SetTrackDir added in v0.2.4

func (n *Node) SetTrackDir(dir string)

func (*Node) TaskMgt

func (n *Node) TaskMgt()

func (*Node) Tracker added in v0.3.7

func (n *Node) Tracker(ch chan<- bool)

tracker

func (*Node) VerifyAccountSignature added in v0.3.6

func (n *Node) VerifyAccountSignature(account, msg, signature string) ([]byte, error)

func (*Node) WriteTrackFile

func (n *Node) WriteTrackFile(fid string, data []byte) error

type NodeInfo added in v0.3.7

type NodeInfo struct {
	PeerId   string   `json:"peer_id"`
	Location Location `json:"location"`
}

type PeerRecord added in v0.3.7

type PeerRecord interface {
	// SavePeer saves or updates peer information
	SavePeer(addr peer.AddrInfo) error
	//
	SavePeerAccount(account string, peerid string) error
	//
	HasPeer(peerid string) bool
	//
	GetPeer(peerid string) (peer.AddrInfo, bool)
	//
	GetPeerByAccount(account string) (peer.AddrInfo, bool)
	//
	GetAllPeerId() []string
	//
	BackupPeer(path string) error
	//
	LoadPeer(path string) error
}

func NewPeerRecord added in v0.3.7

func NewPeerRecord() PeerRecord

type PeerRecordType added in v0.3.7

type PeerRecordType struct {
	// contains filtered or unexported fields
}

func (*PeerRecordType) BackupPeer added in v0.3.7

func (p *PeerRecordType) BackupPeer(path string) error

func (*PeerRecordType) GetAllPeerId added in v0.3.7

func (p *PeerRecordType) GetAllPeerId() []string

func (*PeerRecordType) GetPeer added in v0.3.7

func (p *PeerRecordType) GetPeer(peerid string) (peer.AddrInfo, bool)

func (*PeerRecordType) GetPeerByAccount added in v0.3.7

func (p *PeerRecordType) GetPeerByAccount(account string) (peer.AddrInfo, bool)

func (*PeerRecordType) HasPeer added in v0.3.7

func (p *PeerRecordType) HasPeer(peerid string) bool

func (*PeerRecordType) LoadPeer added in v0.3.7

func (p *PeerRecordType) LoadPeer(path string) error

func (*PeerRecordType) SavePeer added in v0.3.7

func (p *PeerRecordType) SavePeer(addr peer.AddrInfo) error

func (PeerRecordType) SavePeerAccount added in v0.3.7

func (p PeerRecordType) SavePeerAccount(account string, peerid string) error

type RecordInfo

type RecordInfo struct {
	Segment       []chain.SegmentDataInfo `json:"segment"`
	Owner         []byte                  `json:"owner"`
	Fid           string                  `json:"fid"`
	FileName      string                  `json:"file_name"`
	BucketName    string                  `json:"bucket_name"`
	TerritoryName string                  `json:"territory_name"`
	CacheDir      string                  `json:"cache_dir"`
	Cipher        string                  `json:"cipher"`
	FileSize      uint64                  `json:"file_size"`
	PutFlag       bool                    `json:"put_flag"`
}

type RestoreList added in v0.3.2

type RestoreList struct {
	Files []string `json:"files"`
}

type RtnUserBrief

type RtnUserBrief struct {
	User       string `json:"user"`
	FileName   string `json:"file_name"`
	BucketName string `json:"bucket_name"`
}

Jump to

Keyboard shortcuts

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