Skip to content
This repository was archived by the owner on Jun 19, 2023. It is now read-only.

Commit e335def

Browse files
committed
wip
1 parent a6b1d49 commit e335def

File tree

10 files changed

+208
-92
lines changed

10 files changed

+208
-92
lines changed

filesystem/client.go

Lines changed: 0 additions & 1 deletion
This file was deleted.

filesystem/default.go renamed to filesystem/default/default.go

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
package fs
1+
package ipfs
22

33
import (
44
"context"
55
"time"
6-
"github.com/ipfs/go-ipfs/core"
6+
coreiface "github.com/ipfs/interface-go-ipfs-core"
7+
8+
9+
"github.com/ipfs/interface-go-ipfs-core/filesystem/node/soft"
10+
"github.com/ipfs/go-ipfs-http-client"
711
)
812

913
type defaultFs struct {
@@ -15,7 +19,8 @@ ctx context.Context
1519
epoch time.Time
1620

1721
//IPFS parser specifics
18-
ipfsNode core.IpfsNode
22+
//ipfsNode core.IpfsNode
23+
core coreiface.CoreAPI
1924
}
2025
/* From DRAFT
2126
func NewDefaultFileSystem(parentCtx context.Context) (FileSystem, error) {
@@ -27,23 +32,32 @@ func NewDefaultFileSystem(parentCtx context.Context) (FileSystem, error) {
2732
*/
2833

2934
func newDefaultFs() (FileSystem, error) {
30-
var root defaultFs
31-
root.epoch = time.Now()
35+
root := defaultFs {
36+
ctx:context.TODO(), // cancelable something or other
37+
epoch:time.Now(),
38+
}
3239

3340
// we depend on data from the coreapi to initalize our API nodes
3441
// so fetch it or something and store it on the FS
35-
daemon := fallbackApi()
36-
ctx := deriveCtx(daemon.ctx) // if the daemon cancels, so should we
42+
//daemon := fallbackApi()
43+
//ctx := deriveCtx(daemon.ctx) // if the daemon cancels, so should we
3744

38-
root.ipfsNode = daemon
45+
//root.ipfsNode = daemon
3946

4047
// mount base subsystems
48+
epoch := time.Now()
49+
50+
// TODO: connect to daemon or fallback [new constructor]
51+
core, err := httpapi.NewLocalApi()
52+
if err != nil {
53+
return nil, err
54+
}
4155
for _, pair := range [...]struct {
4256
string
4357
ParseFn
4458
}{
45-
{"/", rNode.Parser()},
46-
{"/ipfs", pinRootParser}, // requests for "/ipfs" are directed at pinRootParser(ctx, requestString)
59+
{"/", fsnode.RootParser(epoch)},
60+
{"/ipfs", inode.PinParser(core.Pin(), epoch)}, // requests for "/ipfs" are directed at pinRootParser(ctx, requestString)
4761
{"/ipfs/", coreAPIParser}, // all requests beneath "/ipfs/" are directed at coreAPIParser(ctx, requestString)
4862
{"/ipns", keyRootParser},
4963
{"/ipns/", nameAPIParser},
@@ -69,4 +83,5 @@ type DescriptorTable interface {
6983
}
7084

7185
func newDescriptorTable() {
72-
}
86+
}
87+

filesystem/index.go renamed to filesystem/default/index.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,40 @@
1-
package fs
1+
package ipfs
22

33
import (
44
"context"
5+
"encoding/binary"
56
"io"
67
"os"
78
"strings"
89
"sync"
910

11+
"github.com/ipfs/go-cid"
1012
"github.com/ipfs/go-unixfs"
11-
"github.com/multiformats/go-multihash"
12-
"github.com/ipfs/go-cid"
13+
fs "github.com/ipfs/interface-go-ipfs-core/filesystem/interface"
14+
"github.com/multiformats/go-multihash"
1315
)
1416

15-
func Lookup(ctx context.Context, name string) (FsNode, error) {
17+
func Lookup(ctx context.Context, name string) (fs.FsNode, error) {
1618
return pkgRoot.Lookup(ctx, name)
1719
}
1820

1921
// api's may define Metadata.Cid() however they like
2022
// for the default, we use this QID-like generator
21-
func GenQueryID(path string, md Metadata) (cid.Cid, error) {
23+
func GenQueryID(path string, md fs.Metadata) (cid.Cid, error) {
2224
mdBuf := make([]byte, 16)
23-
binary.LittleEndian.PutUint64(mdBuf, uint64(md.Size()))
24-
binary.LittleEndian.PutUint64(mdBuf[8:], uint64(md.Type()))
25+
binary.LittleEndian.PutUint64(mdBuf, uint64(md.Size()))
26+
binary.LittleEndian.PutUint64(mdBuf[8:], uint64(md.Type()))
2527

26-
prefix := cid.V1Builder{Codec: cid.DagCBOR, MhType: multihash.BLAKE2B_MIN}
27-
return prefix.Sum(append([]byte(path), mdBuf...))
28+
prefix := cid.V1Builder{Codec: cid.DagCBOR, MhType: multihash.BLAKE2B_MIN}
29+
return prefix.Sum(append([]byte(path), mdBuf...))
2830
}
2931

3032
type PathParserRegistry struct {
3133
sync.Mutex
32-
nodeParsers map[string]ParseFn
34+
nodeParsers map[string]fs.ParseFn
3335
}
3436

35-
func (rr *PathParserRegistry) Mount(subrootPath string, nodeParser ParseFn) (io.Closer, error) {
37+
func (rr *PathParserRegistry) Mount(subrootPath string, nodeParser fs.ParseFn) (io.Closer, error) {
3638
rr.Lock()
3739
val, ok := rr.nodeParsers[subrootPath]
3840
if ok || val != nil {

filesystem/init.go renamed to filesystem/default/init.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
package fs
1+
package ipfs
2+
3+
import "github.com/ipfs/interface-go-ipfs-core/filesystem/interface"
24

35
//TODO: store these in the daemon/ipfs-node scope, or elsewhere
46
// have something extract the FS from the daemon (`core.fsFrom(IpfsNode)``)
5-
var pkgRoot FileSystem
7+
var pkgRoot fs.FileSystem
68

79
func init() {
810
pkgRoot, err = newDefaultFs()

filesystem/interface.go renamed to filesystem/interface/interface.go

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,62 @@ package fs
22

33
import (
44
"context"
5+
"errors"
56
"io"
67
"os"
78
"sync"
89

9-
coreiface "github.com/ipfs/interface-go-ipfs-core"
10+
"github.com/ipfs/go-cid"
11+
"github.com/ipfs/go-unixfs"
1012
corepath "github.com/ipfs/interface-go-ipfs-core/path"
1113
)
1214

1315
type (
1416
ParseFn func(ctx context.Context, name string) (FsNode, error)
15-
FsType = coreiface.FileType
16-
OFlags = mfs.Flags
17+
Kind int
18+
Flag string
19+
Flags []struct{Flag;bool}
20+
)
21+
22+
const (
23+
FRead Flag ="File Read"
24+
FWrite = "File Write"
25+
FSync = "File Sync"
26+
)
27+
28+
const (
29+
UfsFile = Kind(unixfs.TFile)
30+
UfsDirectory = Kind(unixfs.TDirectory)
31+
UfsHAMT = Kind(unixfs.THAMTShard)
32+
UfsSymlink = Kind(unixfs.TSymlink)
33+
)
34+
35+
type FsError interface {
36+
error
37+
}
38+
39+
var (
40+
ErrNoLink = FsError(errors.New("not a symlink"))
41+
ErrInvalidHandle = FsError(errors.New("invalid handle"))
42+
ErrNoKey = FsError(errors.New("key not found"))
43+
ErrInvalidPath = FsError(errors.New("invalid path"))
44+
ErrInvalidArg = FsError(errors.New("invalid argument"))
45+
ErrReadOnly = FsError(errors.New("read only section"))
46+
ErrIOType = FsError(errors.New("node does not impliment requested interface"))
47+
ErrUnexpected = FsError(errors.New("unexpected node type"))
48+
ErrNotInitialized = FsError(errors.New("node metadata is not initialized"))
49+
ErrRoot = FsError(errors.New("root initialization exception"))
50+
ErrRecurse = FsError(errors.New("hit recursion limit"))
51+
//
52+
ErrNoHandler = FsError(errors.New("no handler registered for this request"))
1753
)
1854

1955
// Provides standard convention wrappers around an index
2056
type FileSystem interface {
2157
Index // a namespace registry that is used to parse `name` strings into `FsNode`s
2258

2359
// Create node using respective API for its namespace
24-
Create(ctx context.Context, name string, nodeType FsType) error
60+
Create(ctx context.Context, name string, nodeType Kind) error
2561

2662
/* XXX: see PR discussion; we should avoid context.Value if we can; different requests require different arity, which may be a problem
2763
Request specific parameters are passed via context key's and values, at an API level
@@ -38,7 +74,7 @@ type FileSystem interface {
3874
// caller provides values necessary to complete the request (if any), inside the context
3975
Remove(ctx context.Context, name string) error
4076

41-
OpenFile(name string, flags flags, perm os.FileMode) (FsFile, error)
77+
OpenFile(name string, flags Flags, perm os.FileMode) (FsFile, error)
4278
OpenDirectory(path string) (FsDirectory, error)
4379
OpenReference(string) (FsReference, error)
4480
}
@@ -47,6 +83,8 @@ type Index interface {
4783
sync.Locker
4884
// mounts the parser function on the filesystem at "namespace"
4985
// returns "unmount" closer
86+
87+
// rename consider: Bind(Plan9, Spring)
5088
Mount(namespace string, nodeParser ParseFn) (unmount io.Closer, err error)
5189
// NOTE: it may be better to return the equivalent of a "KeepAlive" function rather than a closer
5290
// if the caller disappears, we'll never release
@@ -77,6 +115,13 @@ type Index interface {
77115

78116
type FsNode interface {
79117
corepath.Path
118+
Version() uint
119+
// Cid shall return a cid for the FsNode itself
120+
// the purpose is to allow for cache coherency between API boundaries
121+
// simillar to Plan9's `qid` and `version` fields
122+
// if CID is the same between requests, assume cache safe
123+
Cid() cid.Cid
124+
80125
Metadata(context.Context) (Metadata, error)
81126
//RWLocker Maybe?
82127

@@ -87,7 +132,7 @@ type FsNode interface {
87132
YieldIo(ctx context.Context) (io interface{}, err error)
88133

89134
Remove(context.Context) error
90-
Create(context.Context, FsType) error // should this return an FsNode?
135+
Create(context.Context, Kind) error // should this return an FsNode?
91136
}
92137

93138
/* TODO: Move to fuse or delete
@@ -122,19 +167,13 @@ type Metadata interface {
122167
// Go-uint (4 byte minimum)
123168
// There's no reason for this to be signed outside of C and POSIX as far as I can tell
124169

125-
126-
// Cid shall return a cid for the FsNode itself
127-
// the purpose is to allow for cache coherency between API boundaries
128-
// simillar to Plan9's `version` field
129-
// if anything has changed, it is implied the Cid has changed
130-
Cid() cid.Cid
131-
132170
//TODO: rename? IPLD uses "kind" for these names; Kind() FsKind
133-
Type() FsType
171+
Type() Kind
172+
Flags() Flags
134173

135174
//TODO: consider renaming Cid() -> Version(); Type() -> Format()
136175
//lines up better with both Plan9 and IPLD
137-
176+
138177
//Cid() cid.Cid // can return nil
139178
}
140179

0 commit comments

Comments
 (0)