util

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2023 License: Apache-2.0, MIT Imports: 49 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"
	ERR_INTERNAL_SERVER                                    = "ERR_INTERNAL_SERVER"
	ERR_BAD_REQUEST                                        = "ERR_BAD_REQUEST"
	ERR_CONTENT_IN_COLLECTION                              = "ERR_CONTENT_IN_COLLECTION"
)

#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
)
View Source
const DefaultBatchSize int = 100000

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 CacheKey added in v0.3.9

func CacheKey(c echo.Context, u *User, tags ...string) string

cacheKey returns a key based on the request being made, the user associated to it, and optional tags this key is used when calling Get or Add from a cache

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 ConfigureRateLimiter added in v0.3.5

func ConfigureRateLimiter(rateLimit rate.Limit) middleware.RateLimiterConfig

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 FindAndProcessLargeRequests added in v0.2.5

func FindAndProcessLargeRequests(db *gorm.DB, fc func(tx *gorm.DB, batch int) error, dest interface{}, query ...interface{}) (tx *gorm.DB)

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 NewBinder added in v0.4.1

func NewBinder(log *zap.SugaredLogger) binder

func OpenApiMiddleware added in v0.2.3

func OpenApiMiddleware(log *zap.SugaredLogger) echo.MiddlewareFunc

this is required as ipfs pinning spec has strong requirements on response format

func ParseDealLabel

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

func SetupDatabase

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

func ToMultiAddress added in v0.4.1

func ToMultiAddress(addr string) (multiaddr.Multiaddr, error)

Converting the public key to a multiaddress.

func ToMultiAddresses added in v0.4.1

func ToMultiAddresses(addrs []string) ([]multiaddr.Multiaddr, error)

It takes a slice of strings and returns a slice of multiaddresses

func TracingMiddleware added in v0.2.3

func TracingMiddleware(tcr trace.Tracer) echo.MiddlewareFunc

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

func WithMultipartFormDataChecker added in v0.2.3

func WithMultipartFormDataChecker(next echo.HandlerFunc) echo.HandlerFunc

func WithUser added in v0.3.9

func WithUser(f func(echo.Context, *User) error) func(echo.Context) error

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
	IsSession  bool
}

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        uint64         `gorm:"primarykey" json:"id"`
	CreatedAt time.Time      `json:"createdAt"`
	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 uint64 `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 uint64 `json:"splitFrom"`

	PinningStatus string `json:"pinningStatus" gorm:"-"`
	DealStatus    string `json:"dealStatus" gorm:"-"`
}

func GetContent added in v0.1.10

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

type ContentAddResponse

type ContentAddResponse struct {
	Cid                 string   `json:"cid"`
	RetrievalURL        string   `json:"retrieval_url"`
	EstuaryRetrievalURL string   `json:"estuary_retrieval_url"`
	EstuaryId           uint64   `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 uint64 `json:"id"`
}

type ContentInCollection

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

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 DbAddrInfo added in v0.3.7

type DbAddrInfo struct {
	AddrInfo peer.AddrInfo
}

func (*DbAddrInfo) Scan added in v0.3.7

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

func (DbAddrInfo) Value added in v0.3.7

func (dba DbAddrInfo) 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        uint64 `gorm:"primarykey"`
	Content   uint64 `gorm:"index:,option:CONCURRENTLY"`
	Object    uint64 `gorm:"index:,option:CONCURRENTLY"`
	Offloaded uint
}

type Object

type Object struct {
	ID         uint64 `gorm:"primarykey"`
	Cid        DbCID  `gorm:"index"`
	Size       uint64
	Reads      uint64
	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 uint64 `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 uint64   `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