node

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2025 License: Apache-2.0 Imports: 45 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MSG_OK = "ok"

	ERR_SystemErr = "system error"

	ERR_ServerBusy = "Server busy"

	ERR_InvalidFormFile   = "invalid form file"
	ERR_NoPermission      = "No permission"
	ERR_InvalidFid        = "invalid fid"
	ERR_InvalidRangeValue = "invalid range value"
	ERR_InvalidRangeStart = "invalid range start"
	ERR_InvalidRangeEnd   = "invalid range end"
	ERR_ReceiveData       = "network error"
	ERR_UnknownFileFormat = "Unknown file format"
)
View Source
const (
	HTTPHeader_Territory       = "Territory"
	HTTPHeader_Account         = "Account"
	HTTPHeader_EthAccount      = "EthAcc"
	HTTPHeader_Message         = "Message"
	HTTPHeader_Signature       = "Signature"
	HTTPHeader_Miner           = "Miner"
	HTTPHeader_Longitude       = "Longitude"
	HTTPHeader_Latitude        = "Latitude"
	HTTPHeader_Fid             = "Fid"
	HTTPHeader_Cipher          = "Cipher"
	HTTPHeader_Filename        = "Filename"
	HTTPHeader_Format          = "Format"
	HTTPHeader_Range           = "Range"
	HTTPHeader_X_Forwarded_For = "X_Forwarded_For"
)

HTTP HEADER

View Source
const (
	Active = iota
	Calculate
	Missing
	Recovery
)
View Source
const (
	HTTP_ParameterName     = "name"
	HTTP_ParameterName_Fid = "fid"
)
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_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_NotEnoughSpace             = "not enough account space"
	ERR_InsufficientTerritorySpace = "insufficient territory space"

	ERR_InternalServer   = "Internal system error"
	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"

	ERR_MissingContentRange = "Content-Range is missing from the request header"
	ERR_IllegalContentRange = "Illegal Content-Range content"
	ERR_FailedToRecvData    = "Failed to receive data"

	ERR_RPCConnection = "Failed to connect to rpc, please try again later."
	ERR_RPCSyncing    = "Syncing the latest blocks"
	ERR_EmptyFileName = "Empty file name"
)
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 will expire 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

Variables

This section is empty.

Functions

func CheckAuthorize added in v0.4.0

func CheckAuthorize(cli chain.Chainer, c *gin.Context, pkey []byte) error

func CheckChainSt added in v0.4.0

func CheckChainSt(cli chain.Chainer, c *gin.Context) error

func CheckFileType added in v0.4.0

func CheckFileType(cli chain.Chainer, fid string, account string) (string, error)

func CheckFilename added in v0.4.0

func CheckFilename(c *gin.Context, filename string) error

func CheckMinerLocation added in v0.4.0

func CheckMinerLocation(cli chain.Chainer, puk []byte) (float64, float64, error)

func CheckPermissionsMdl added in v0.4.0

func CheckPermissionsMdl(account string, accessmode string, priority, blackwhite []string) bool

func CheckTerritory added in v0.4.0

func CheckTerritory(cli chain.Chainer, c *gin.Context, pkey []byte, territoryName string) (uint64, error)

func CreateTmpPath added in v0.4.0

func CreateTmpPath(c *gin.Context, dir, account string) (string, string, error)

string: tmp dir string: tmp file path error: error

func DownloadFileFromGW added in v0.4.0

func DownloadFileFromGW(url, fpath, account, message, signature string) (uint64, error)

func FindFileFromGW added in v0.4.0

func FindFileFromGW(cli chain.Chainer, fid string, fpath string) (uint64, error)

func FindLocalFile added in v0.4.0

func FindLocalFile(fid string, dirs ...string) (uint64, string, error)

func GetCoordinate added in v0.4.0

func GetCoordinate(addr string) (coordinate.Coordinate, error)

func GetGWVersion added in v0.4.0

func GetGWVersion(url string) error

func InitMiddlewares added in v0.4.0

func InitMiddlewares() []gin.HandlerFunc

func IsComplete added in v0.4.0

func IsComplete(index int, completeInfo []schain.CompleteInfo) (string, bool)

func IsStoraged added in v0.4.0

func IsStoraged(account string, complete []string) bool

func OtherHeader added in v0.3.7

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

func ParseCity added in v0.4.0

func ParseCity(addr string) (float64, float64, bool)

func ReturnFileRangeStream added in v0.4.0

func ReturnFileRangeStream(c *gin.Context, rng string, content_type string, file string) error

func ReturnFileStream added in v0.4.0

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

func ReturnJSON added in v0.4.0

func ReturnJSON(c *gin.Context, code int, msg string, data any)

func VerifyEthSign added in v0.3.6

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

func VerifySignatureMdl added in v0.4.0

func VerifySignatureMdl(c *gin.Context) (string, []byte, bool)

func VerifySignatureMdl2 added in v0.4.0

func VerifySignatureMdl2(account, ethAccount, message, signature string) (string, []byte, bool)

func VideoAndAudioHeader added in v0.3.7

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

Types

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 FileHandler added in v0.4.0

func NewFileHandler added in v0.4.0

func NewFileHandler(cli chain.Chainer, track tracker.Tracker, ws workspace.Workspace, lg logger.Logger, cfg *confile.Config, lru *lru.LRUCache) *FileHandler

func (*FileHandler) DeleteFileHandle added in v0.4.0

func (f *FileHandler) DeleteFileHandle(c *gin.Context)

func (*FileHandler) DownloadFileHandle added in v0.4.0

func (f *FileHandler) DownloadFileHandle(c *gin.Context)

func (*FileHandler) GetLocationhandle added in v0.4.0

func (f *FileHandler) GetLocationhandle(c *gin.Context)

func (*FileHandler) GetMetadataHandle added in v0.4.0

func (f *FileHandler) GetMetadataHandle(c *gin.Context)

func (*FileHandler) OpenFileHandle added in v0.4.0

func (f *FileHandler) OpenFileHandle(c *gin.Context)

func (*FileHandler) RegisterRoutes added in v0.4.0

func (f *FileHandler) RegisterRoutes(server *gin.Engine)

func (*FileHandler) UploadFormFileHandle added in v0.4.0

func (f *FileHandler) UploadFormFileHandle(c *gin.Context)

type FilesHandler added in v0.4.0

func NewFilesHandler added in v0.4.0

func NewFilesHandler(cli chain.Chainer, track tracker.Tracker, ws workspace.Workspace, lg logger.Logger, cfg *confile.Config, lru *lru.LRUCache) *FilesHandler

func (*FilesHandler) RegisterRoutes added in v0.4.0

func (f *FilesHandler) RegisterRoutes(server *gin.Engine)

func (*FilesHandler) UploadFormFilesHandle added in v0.4.0

func (f *FilesHandler) UploadFormFilesHandle(c *gin.Context)

type Handler added in v0.4.0

type Handler struct {
	*FileHandler
	*ResumeHandler
	*ObjectHandler
	*FilesHandler
}

func NewHandler added in v0.4.0

func NewHandler(cli chain.Chainer, track tracker.Tracker, ws workspace.Workspace, lg logger.Logger, cfg *confile.Config, lru *lru.LRUCache) *Handler

func (*Handler) RegisterRoutes added in v0.4.0

func (h *Handler) RegisterRoutes(server *gin.Engine)

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 MultiFormFiles added in v0.4.0

type MultiFormFiles struct {
	SegmentDataInfo []chain.SegmentDataInfo `json:"-"`
	Fapth           string                  `json:"-"`
	Name            string                  `json:"name"`
	Fid             string                  `json:"fid"`
	Result          string                  `json:"result"`
	Reason          string                  `json:"reason"`
	Size            int64                   `json:"size"`
}

type Node

func NewEmptyNode added in v0.4.0

func NewEmptyNode() *Node

func NewNodeWithConfig added in v0.4.0

func NewNodeWithConfig(cfg *confile.Config) *Node

func (*Node) AccessControl added in v0.3.3

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

func (*Node) InitCache added in v0.4.0

func (n *Node) InitCache()

func (*Node) InitChainClient added in v0.4.0

func (n *Node) InitChainClient()

func (*Node) InitChainclient added in v0.4.0

func (n *Node) InitChainclient(cli chain.Chainer)

func (*Node) InitLRUCache added in v0.4.0

func (n *Node) InitLRUCache(lru *lru.LRUCache)

func (*Node) InitLogger added in v0.4.0

func (n *Node) InitLogger(lg logger.Logger)

func (*Node) InitLogs added in v0.4.0

func (n *Node) InitLogs()

func (*Node) InitMinerRecord added in v0.4.0

func (n *Node) InitMinerRecord(r record.MinerRecorder)

func (*Node) InitNode added in v0.4.0

func (n *Node) InitNode() *Node

func (*Node) InitServer added in v0.4.0

func (n *Node) InitServer(s *gin.Engine)

func (*Node) InitTracker added in v0.4.0

func (n *Node) InitTracker(t tracker.Tracker)

func (*Node) InitWebServer added in v0.4.0

func (n *Node) InitWebServer(mdls []gin.HandlerFunc, hdl *Handler)

func (*Node) InitWorkspace added in v0.4.0

func (n *Node) InitWorkspace(ws string)

func (*Node) RefreshBlacklist added in v0.4.0

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

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) Start added in v0.4.0

func (n *Node) Start()

func (*Node) StoragePartAssignment added in v0.4.0

func (n *Node) StoragePartAssignment(ch chan<- bool, data StorageDataType, assignments []string)

func (*Node) StoragePartFixed added in v0.4.0

func (n *Node) StoragePartFixed(data StorageDataType, assignments []string) (StorageDataType, error)

func (*Node) StorageRangeAssignment added in v0.4.0

func (n *Node) StorageRangeAssignment(ch chan<- bool, data StorageDataType)

func (*Node) TrackerV2 added in v0.4.0

func (n *Node) TrackerV2()

tracker

func (*Node) UploadFragmentToMiner added in v0.4.0

func (n *Node) UploadFragmentToMiner(addr, fid, fragmentHash, fragmentPath string) error

func (*Node) VerifyAccountSignature added in v0.3.6

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

type NodeInfo added in v0.3.7

type NodeInfo struct {
	Account  string   `json:"account"`
	Location Location `json:"location"`
}

location info

type ObjectHandler added in v0.4.0

func NewObjectHandler added in v0.4.0

func NewObjectHandler(cli chain.Chainer, track tracker.Tracker, ws workspace.Workspace, lg logger.Logger, lru *lru.LRUCache) *ObjectHandler

func (*ObjectHandler) RegisterRoutes added in v0.4.0

func (o *ObjectHandler) RegisterRoutes(server *gin.Engine)

func (*ObjectHandler) UploadObjectHandle added in v0.4.0

func (o *ObjectHandler) UploadObjectHandle(c *gin.Context)

type RespType added in v0.4.0

type RespType struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data any    `json:"data"`
}

type ResumeHandler added in v0.4.0

func NewResumeHandler added in v0.4.0

func NewResumeHandler(cli chain.Chainer, track tracker.Tracker, ws workspace.Workspace, lg logger.Logger) *ResumeHandler

func (*ResumeHandler) RegisterRoutes added in v0.4.0

func (r *ResumeHandler) RegisterRoutes(server *gin.Engine)

func (*ResumeHandler) ResumeHandle added in v0.4.0

func (r *ResumeHandler) ResumeHandle(c *gin.Context)

type RtnUserBrief

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

type StorageDataType added in v0.4.0

type StorageDataType struct {
	Fid         string
	Complete    []string
	Data        [][]string
	StorageType StorageType
	Assignments []string
	Range       coordinate.Range
}

type StorageType added in v0.4.0

type StorageType uint8
const (
	Storage_NoAssignment StorageType = iota
	Storage_PartAssignment
	Storage_FullAssignment
	Storage_RangeAssignment
)

Jump to

Keyboard shortcuts

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