util

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2022 License: Apache-2.0, MIT Imports: 40 Imported by: 2

Documentation

Index

Constants

View Source
const (
	ERR_INVALID_TOKEN                                      = "ERR_INVALID_TOKEN"
	ERR_TOKEN_EXPIRED                                      = "ERR_TOKEN_EXPIRED"
	ERR_AUTH_MISSING                                       = "ERR_AUTH_MISSING"
	ERR_WRONG_AUTH_FORMAT                                  = "ERR_WRONG_AUTH_FORMAT"
	ERR_INVALID_AUTH                                       = "ERR_INVALID_AUTH"
	ERR_AUTH_MISSING_BEARER                                = "ERR_AUTH_MISSING_BEARER"
	ERR_NOT_AUTHORIZED                                     = "ERR_NOT_AUTHORIZED"
	ERR_MINER_NOT_OWNED                                    = "ERR_MINER_NOT_OWNED"
	ERR_INVALID_INVITE                                     = "ERR_INVALID_INVITE"
	ERR_USERNAME_TAKEN                                     = "ERR_USERNAME_TAKEN"
	ERR_USER_CREATION_FAILED                               = "ERR_USER_CREATION_FAILED"
	ERR_USER_NOT_FOUND                                     = "ERR_USER_NOT_FOUND"
	ERR_INVALID_PASSWORD                                   = "ERR_INVALID_PASSWORD"
	ERR_INVALID_FILTER                                     = "ERR_INVALID_FILTER"
	ERR_INVITE_ALREADY_USED                                = "ERR_INVITE_ALREADY_USED"
	ERR_CONTENT_ADDING_DISABLED                            = "ERR_CONTENT_ADDING_DISABLED"
	ERR_INVALID_INPUT                                      = "ERR_INVALID_INPUT"
	ERR_CONTENT_SIZE_OVER_LIMIT                            = "ERR_CONTENT_SIZE_OVER_LIMIT"
	ERR_PEERING_PEERS_ADD_ERROR                            = "ERR_PEERING_PEERS_ADD_ERROR"
	ERR_PEERING_PEERS_REMOVE_ERROR                         = "ERR_PEERING_PEERS_REMOVE_ERROR"
	ERR_PEERING_PEERS_START_ERROR                          = "ERR_PEERING_PEERS_START_ERROR"
	ERR_PEERING_PEERS_STOP_ERROR                           = "ERR_PEERING_PEERS_STOP_ERROR"
	ERR_CONTENT_NOT_FOUND                                  = "ERR_CONTENT_NOT_FOUND"
	ERR_RECORD_NOT_FOUND                                   = "ERR_RECORD_NOT_FOUND"
	ERR_INVALID_PINNING_STATUS                             = "ERR_INVALID_PINNING_STATUS"
	ERR_INVALID_QUERY_PARAM_VALUE                          = "ERR_INVALID_QUERY_PARAM_VALUE"
	ERR_CONTENT_LENGTH_REQUIRED                            = "ERR_CONTENT_LENGTH_REQUIRED"
	ERR_UNSUPPORTED_CONTENT_TYPE                           = "ERR_UNSUPPORTED_CONTENT_TYPE"
	ERR_VALUE_REQUIRED                                     = "ERR_VALUE_REQUIRED"
	ERR_INVALID_MINER_CLAIM_SIG                            = "ERR_INVALID_MINER_CLAIM_SIG"
	ERR_INVALID_MINER_SETUP                                = "ERR_INVALID_MINER_SETUP"
	ERR_INVALID_MINER_CLAIM_NO_PEER_ID                     = "ERR_INVALID_MINER_CLAIM_NO_PEER_ID"
	ERR_INVALID_MINER_CLAIM_NO_MULTI_ADDR                  = "ERR_INVALID_MINER_CLAIM_NO_MULTI_ADDR"
	ERR_INVALID_MINER_CLAIM_NO_POWER                       = "ERR_INVALID_MINER_CLAIM_NO_POWER"
	ERR_INVALID_MINER_CLAIM_POWER_BELOW_1TIB               = "ERR_INVALID_MINER_CLAIM_POWER_BELOW_1TIB"
	ERR_INVALID_MINER_CLAIM_NO_ASK                         = "ERR_INVALID_MINER_CLAIM_NO_ASK"
	ERR_INVALID_MINER_CLAIM_ASK_VERIFIED_PRICE_IS_NOT_ZERO = "ERR_INVALID_MINER_CLAIM_ASK_VERIFIED_PRICE_IS_NOT_ZERO"
)

#nosec G101 -- This is a false positive

View Source
const (
	ERR_AUTH_MISSING_DETAILS        = "no api key was specified"
	ERR_AUTH_MISSING_BEARER_DETAILS = "" //#nosec G101 -- This is a false positive and example API KEY
	/* 186-byte string literal not displayed */
	ERR_INVALID_AUTH_DETAILS = "" //#nosec G101 -- This is a false positive and example API KEY
	/* 236-byte string literal not displayed */
)
View Source
const (
	PermLevelUpload = 1
	PermLevelUser   = 2
	PermLevelAdmin  = 10
)

Variables

View Source
var DefaultHashFunction = uint64(mh.SHA2_256)
View Source
var FlagLogLevel = &cli.StringFlag{
	Name:        "log-level",
	Usage:       "sets the log level, defaults to INFO",
	Value:       "INFO",
	Destination: &LogLevel,
}
View Source
var LogLevel string

Functions

func AppVersionMiddleware

func AppVersionMiddleware(appVersion string) echo.MiddlewareFunc

func CalculateCarSize

func CalculateCarSize(data cid.Cid, objects []CarObject) (uint64, error)

func CanRestartTransfer added in v0.1.9

func CanRestartTransfer(st *filclient.ChannelState) bool

func CidIsUnwalkable

func CidIsUnwalkable(c cid.Cid) bool

func CreateDwebRetrievalURL added in v0.2.0

func CreateDwebRetrievalURL(cid string) string

func CreateEstuaryRetrievalURL added in v0.2.0

func CreateEstuaryRetrievalURL(cid string) string

func DirsFromPath

func DirsFromPath(collectionPath string, filename string) ([]string, error)

DirsFromPath splits a path into a list of directories

func DumpBlockstoreTo added in v0.2.0

func DumpBlockstoreTo(ctx context.Context, tc trace.Tracer, from, to blockstore.Blockstore) error

func EnsurePathIsLinked

func EnsurePathIsLinked(dirs []string, rootNode *merkledag.ProtoNode, ds format.DAGService) (*merkledag.ProtoNode, error)

func ErrorHandler

func ErrorHandler(err error, ctx echo.Context)

func ErrorIfContentAddingDisabled added in v0.1.5

func ErrorIfContentAddingDisabled(isContentAddingDisabled bool) error

func ExtractAuth

func ExtractAuth(c echo.Context) (string, error)
func FilterUnwalkableLinks(links []*ipld.Link) []*ipld.Link

func GetPasswordHash added in v0.1.8

func GetPasswordHash(password, salt string, dialector string) string

func GetPasswordHashBase added in v0.1.10

func GetPasswordHashBase(password, salt string) string

func GetPasswordHashBase64 added in v0.1.10

func GetPasswordHashBase64(password, salt string) string

func GetTokenHash added in v0.1.11

func GetTokenHash(token string) string

func ImportFile

func ImportFile(dserv ipld.DAGService, fi io.Reader) (ipld.Node, error)

func IsCollectionOwner added in v0.1.4

func IsCollectionOwner(uID, entityID uint) error

func IsContentOwner added in v0.1.4

func IsContentOwner(uID, entityID uint) error

func JSONPayloadMiddleware added in v0.1.10

func JSONPayloadMiddleware(next echo.HandlerFunc) echo.HandlerFunc

func ParseDealLabel

func ParseDealLabel(s string) (cid.Cid, error)

func SetupDatabase

func SetupDatabase(dbval string) (*gorm.DB, error)

func TransferFailed added in v0.1.9

func TransferFailed(st *filclient.ChannelState) (bool, string)

func TryExtractFSNode

func TryExtractFSNode(nd ipld.Node) (*unixfs.FSNode, error)

func WithContentLengthCheck added in v0.1.8

func WithContentLengthCheck(f func(echo.Context) error) func(echo.Context) error

required for car uploads

Types

type AuthToken added in v0.1.10

type AuthToken struct {
	gorm.Model
	Token      string `gorm:"unique;->"` // read only to prevent storing new tokens but not break existing tokens
	TokenHash  string `gorm:"unique"`
	Label      string
	User       uint
	UploadOnly bool
	Expiry     time.Time
}

type Binder added in v0.1.10

type Binder struct{}

func (Binder) Bind added in v0.1.10

func (b Binder) Bind(i interface{}, c echo.Context) error

type CarObject added in v0.1.8

type CarObject struct {
	Cid  cid.Cid
	Size uint64
}

type ChanTrack

type ChanTrack struct {
	Dbid uint
	Last *filclient.ChannelState
}

type Content added in v0.1.8

type Content struct {
	ID        uint           `gorm:"primarykey" json:"id"`
	CreatedAt time.Time      `json:"-"`
	UpdatedAt time.Time      `json:"updatedAt"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`

	Cid         DbCID       `json:"cid"`
	Name        string      `json:"name"`
	UserID      uint        `json:"userId" gorm:"index"`
	Description string      `json:"description"`
	Size        int64       `json:"size"`
	Type        ContentType `json:"type"`
	Active      bool        `json:"active"`
	Offloaded   bool        `json:"offloaded"`
	Replication int         `json:"replication"`

	// TODO: shift most of the 'state' booleans in here into a single state
	// field, should make reasoning about things much simpler
	AggregatedIn uint `json:"aggregatedIn" gorm:"index:,option:CONCURRENTLY"`
	Aggregate    bool `json:"aggregate"`

	Pinning bool   `json:"pinning"`
	PinMeta string `json:"pinMeta"`
	Replace bool   `json:"replace" gorm:"default:0"`
	Origins string `json:"origins"`

	Failed bool `json:"failed"`

	Location string `json:"location"`

	// If set, this content is part of a split dag.
	// In such a case, the 'root' content should be advertised on the dht, but
	// not have deals made for it, and the children should have deals made for
	// them (unlike with aggregates)
	DagSplit  bool `json:"dagSplit"`
	SplitFrom uint `json:"splitFrom"`
}

func GetContent added in v0.1.10

func GetContent(contentid string, db *gorm.DB, u *User) (Content, error)

type ContentAddIpfsBody

type ContentAddIpfsBody struct {
	ContentInCollection
	Root  string   `json:"root"`
	Name  string   `json:"filename"`
	Peers []string `json:"peers"`
}

type ContentAddResponse

type ContentAddResponse struct {
	Cid                 string   `json:"cid"`
	RetrievalURL        string   `json:"retrieval_url"`
	EstuaryRetrievalURL string   `json:"estuary_retrieval_url"`
	EstuaryId           uint     `json:"estuaryId"`
	Providers           []string `json:"providers"`
}

type ContentCreateBody

type ContentCreateBody struct {
	ContentInCollection

	Root     string      `json:"root"`
	Name     string      `json:"name"`
	Location string      `json:"location"`
	Type     ContentType `json:"type"`
}

type ContentCreateResponse

type ContentCreateResponse struct {
	ID uint `json:"id"`
}

type ContentInCollection

type ContentInCollection struct {
	CollectionID  string `json:"coluuid"`
	CollectionDir string `json:"dir"`
}

type ContentType

type ContentType int64
const (
	Unknown ContentType = iota
	File
	Directory
)

func FindCIDType

func FindCIDType(ctx context.Context, root cid.Cid, dserv ipld.NodeGetter) (contentType ContentType)

FindCIDType checks if a pinned CID (root) is a file, a dir or unknown Returns dbmgr.File or dbmgr.Directory on success Returns dbmgr.Unknown otherwise

type ContentWithPath added in v0.1.8

type ContentWithPath struct {
	Content
	Path string `json:"path"`
}

type DbAddr

type DbAddr struct {
	Addr address.Address
}

func (*DbAddr) Scan

func (dba *DbAddr) Scan(v interface{}) error

func (DbAddr) Value

func (dba DbAddr) Value() (driver.Value, error)

type DbCID

type DbCID struct {
	CID cid.Cid
}

func (DbCID) MarshalJSON

func (dbc DbCID) MarshalJSON() ([]byte, error)

func (*DbCID) Scan

func (dbc *DbCID) Scan(v interface{}) error

func (*DbCID) UnmarshalJSON

func (dbc *DbCID) UnmarshalJSON(b []byte) error

func (DbCID) Value

func (dbc DbCID) Value() (driver.Value, error)

type GenericResponse added in v0.1.1

type GenericResponse struct {
	Message string `json:"message"`
}

generic response models

type HttpError

type HttpError struct {
	Code    int    `json:"code,omitempty"`
	Reason  string `json:"reason"`
	Details string `json:"details"`
}

func (HttpError) Error

func (he HttpError) Error() string

type HttpErrorResponse added in v0.1.1

type HttpErrorResponse struct {
	Error HttpError `json:"error"`
}

type InitShuttleResponse

type InitShuttleResponse struct {
	Handle string `json:"handle"`
	Token  string `json:"token"`
}

type InviteCode added in v0.1.10

type InviteCode struct {
	gorm.Model
	Code      string `gorm:"unique"`
	CreatedBy uint
	ClaimedBy uint
}

type ObjRef added in v0.1.8

type ObjRef struct {
	ID        uint `gorm:"primarykey"`
	Content   uint `gorm:"index:,option:CONCURRENTLY"`
	Object    uint `gorm:"index:,option:CONCURRENTLY"`
	Offloaded uint
}

type Object

type Object struct {
	ID         uint  `gorm:"primarykey"`
	Cid        DbCID `gorm:"index"`
	Size       int
	Reads      int
	LastAccess time.Time
}

type PeeringPeerAddMessage added in v0.1.1

type PeeringPeerAddMessage struct {
	Message  string                `json:"message"`
	PeersAdd []peering.PeeringPeer `json:"peers"`
}

type PeeringPeerRemoveMessage added in v0.1.1

type PeeringPeerRemoveMessage struct {
	Message     string    `json:"message"`
	PeersRemove []peer.ID `json:"peers"`
}

type RetrievalFailureRecord

type RetrievalFailureRecord struct {
	gorm.Model
	Miner   string `json:"miner"`
	Phase   string `json:"phase"`
	Message string `json:"message"`
	Content uint   `json:"content"`
	Cid     DbCID  `json:"cid"`
}

type RetrievalProgress

type RetrievalProgress struct {
	Wait   chan struct{}
	EndErr error
}

type ShuttleCreateContentBody

type ShuttleCreateContentBody struct {
	ContentCreateBody
	Collections  []string `json:"collections"`
	DagSplitRoot uint     `json:"dagSplitRoot"`
	User         uint     `json:"user"`
}

type ShuttleListResponse

type ShuttleListResponse struct {
	Handle         string          `json:"handle"`
	Token          string          `json:"token"`
	Online         bool            `json:"online"`
	LastConnection time.Time       `json:"lastConnection"`
	AddrInfo       *peer.AddrInfo  `json:"addrInfo"`
	Address        address.Address `json:"address"`
	Hostname       string          `json:"hostname"`

	StorageStats *ShuttleStorageStats `json:"storageStats"`
}

type ShuttleStorageStats

type ShuttleStorageStats struct {
	BlockstoreSize uint64 `json:"blockstoreSize"`
	BlockstoreFree uint64 `json:"blockstoreFree"`
	PinCount       int64  `json:"pinCount"`
	PinQueueLength int64  `json:"pinQueueLength"`
}

type TrackingBlockstore added in v0.2.0

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

func NewTrackingBlockstore added in v0.2.0

func NewTrackingBlockstore(bs blockstore.Blockstore, db *gorm.DB) *TrackingBlockstore

func (*TrackingBlockstore) AllKeysChan added in v0.2.0

func (tbs *TrackingBlockstore) AllKeysChan(context.Context) (<-chan cid.Cid, error)

func (*TrackingBlockstore) DeleteBlock added in v0.2.0

func (tbs *TrackingBlockstore) DeleteBlock(ctx context.Context, _ cid.Cid) error

func (*TrackingBlockstore) Get added in v0.2.0

func (tbs *TrackingBlockstore) Get(ctx context.Context, c cid.Cid) (blocks.Block, error)

func (*TrackingBlockstore) GetCounts added in v0.2.0

func (tbs *TrackingBlockstore) GetCounts(objects []Object) ([]int, error)

func (*TrackingBlockstore) GetSize added in v0.2.0

func (tbs *TrackingBlockstore) GetSize(ctx context.Context, c cid.Cid) (int, error)

func (*TrackingBlockstore) Has added in v0.2.0

func (tbs *TrackingBlockstore) Has(ctx context.Context, c cid.Cid) (bool, error)

func (*TrackingBlockstore) HashOnRead added in v0.2.0

func (tbs *TrackingBlockstore) HashOnRead(hashOnRead bool)

func (*TrackingBlockstore) LastAccess added in v0.2.0

func (tbs *TrackingBlockstore) LastAccess(ctx context.Context, c cid.Cid) (time.Time, error)

func (*TrackingBlockstore) Put added in v0.2.0

func (tbs *TrackingBlockstore) Put(ctx context.Context, blk blocks.Block) error

func (*TrackingBlockstore) PutMany added in v0.2.0

func (tbs *TrackingBlockstore) PutMany(ctx context.Context, blks []blocks.Block) error

func (*TrackingBlockstore) SetCidReqFunc added in v0.2.0

func (tbs *TrackingBlockstore) SetCidReqFunc(f func(context.Context, cid.Cid) (blocks.Block, error))

func (*TrackingBlockstore) Under added in v0.2.0

type User added in v0.1.10

type User struct {
	gorm.Model
	UUID     string `gorm:"unique"`
	Username string `gorm:"unique"`
	Salt     string
	PassHash string
	DID      string

	UserEmail string

	Address   DbAddr
	AuthToken AuthToken `gorm:"-"`
	Perm      int
	Flags     int

	StorageDisabled bool
}

func (*User) FlagSplitContent added in v0.1.10

func (u *User) FlagSplitContent() bool

type UserSettings

type UserSettings struct {
	Replication           int            `json:"replication"`
	Verified              bool           `json:"verified"`
	DealDuration          abi.ChainEpoch `json:"dealDuration"`
	FileStagingThreshold  int64          `json:"fileStagingThreshold"`
	ContentAddingDisabled bool           `json:"contentAddingDisabled"`
	DealMakingDisabled    bool           `json:"dealMakingDisabled"`
	UploadEndpoints       []string       `json:"uploadEndpoints"`
	Flags                 int            `json:"flags"`
}

type ViewerResponse

type ViewerResponse struct {
	Username   string       `json:"username"`
	Perms      int          `json:"perms"`
	ID         uint         `json:"id"`
	Address    string       `json:"address,omitempty"`
	Miners     []string     `json:"miners,omitempty"`
	AuthExpiry time.Time    `json:"auth_expiry,omitempty"`
	Settings   UserSettings `json:"settings"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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