@@ -10,22 +10,19 @@ import (
10
10
"fmt"
11
11
"io"
12
12
"os"
13
-
14
- core "github.com/ipfs/go-ipfs/core"
15
- namesys "github.com/ipfs/go-ipfs/namesys"
16
- resolve "github.com/ipfs/go-ipfs/namesys/resolve"
13
+ "strings"
17
14
18
15
dag "github.com/ipfs/go-merkledag"
19
- path "github.com/ipfs/go-path"
20
16
ft "github.com/ipfs/go-unixfs"
17
+ path "github.com/ipfs/interface-go-ipfs-core/path"
21
18
22
19
fuse "bazil.org/fuse"
23
20
fs "bazil.org/fuse/fs"
24
21
cid "github.com/ipfs/go-cid"
25
22
logging "github.com/ipfs/go-log"
26
23
mfs "github.com/ipfs/go-mfs"
27
- ci "github.com/libp2p/ go-libp2p -core/crypto "
28
- peer "github.com/libp2p/ go-libp2p -core/peer "
24
+ iface "github.com/ipfs/interface- go-ipfs -core"
25
+ options "github.com/ipfs/interface- go-ipfs -core/options "
29
26
)
30
27
31
28
func init () {
@@ -40,17 +37,17 @@ var log = logging.Logger("fuse/ipns")
40
37
41
38
// FileSystem is the readwrite IPNS Fuse Filesystem.
42
39
type FileSystem struct {
43
- Ipfs * core. IpfsNode
40
+ Ipfs iface. CoreAPI
44
41
RootNode * Root
45
42
}
46
43
47
44
// NewFileSystem constructs new fs using given core.IpfsNode instance.
48
- func NewFileSystem (ipfs * core. IpfsNode , sk ci. PrivKey , ipfspath , ipnspath string ) (* FileSystem , error ) {
49
-
50
- kmap := map [ string ]ci. PrivKey {
51
- "local" : sk ,
45
+ func NewFileSystem (ctx context. Context , ipfs iface. CoreAPI , ipfspath , ipnspath string ) (* FileSystem , error ) {
46
+ key , err := ipfs . Key (). Self ( ctx )
47
+ if err != nil {
48
+ return nil , err
52
49
}
53
- root , err := CreateRoot (ipfs , kmap , ipfspath , ipnspath )
50
+ root , err := CreateRoot (ctx , ipfs , map [ string ]iface. Key { "local" : key } , ipfspath , ipnspath )
54
51
if err != nil {
55
52
return nil , err
56
53
}
@@ -73,80 +70,62 @@ func (f *FileSystem) Destroy() {
73
70
74
71
// Root is the root object of the filesystem tree.
75
72
type Root struct {
76
- Ipfs * core. IpfsNode
77
- Keys map [string ]ci. PrivKey
73
+ Ipfs iface. CoreAPI
74
+ Keys map [string ]iface. Key
78
75
79
76
// Used for symlinking into ipfs
80
77
IpfsRoot string
81
78
IpnsRoot string
82
79
LocalDirs map [string ]fs.Node
83
- Roots map [string ]* keyRoot
80
+ Roots map [string ]* mfs. Root
84
81
85
82
LocalLinks map [string ]* Link
86
83
}
87
84
88
- func ipnsPubFunc (ipfs * core. IpfsNode , k ci. PrivKey ) mfs.PubFunc {
85
+ func ipnsPubFunc (ipfs iface. CoreAPI , key iface. Key ) mfs.PubFunc {
89
86
return func (ctx context.Context , c cid.Cid ) error {
90
- return ipfs .Namesys .Publish (ctx , k , path .FromCid (c ))
87
+ _ , err := ipfs .Name ().Publish (ctx , path .IpfsPath (c ), options .Name .Key (key .Name ()))
88
+ return err
91
89
}
92
90
}
93
91
94
- func loadRoot (ctx context.Context , rt * keyRoot , ipfs * core.IpfsNode , name string ) (fs.Node , error ) {
95
- p , err := path .ParsePath ("/ipns/" + name )
96
- if err != nil {
97
- log .Errorf ("mkpath %s: %s" , name , err )
98
- return nil , err
99
- }
100
-
101
- node , err := resolve .Resolve (ctx , ipfs .Namesys , ipfs .Resolver , p )
92
+ func loadRoot (ctx context.Context , ipfs iface.CoreAPI , key iface.Key ) (* mfs.Root , fs.Node , error ) {
93
+ node , err := ipfs .ResolveNode (ctx , key .Path ())
102
94
switch err {
103
95
case nil :
104
- case namesys .ErrResolveFailed :
96
+ case iface .ErrResolveFailed :
105
97
node = ft .EmptyDirNode ()
106
98
default :
107
- log .Errorf ("looking up %s: %s" , p , err )
108
- return nil , err
99
+ log .Errorf ("looking up %s: %s" , key . Path () , err )
100
+ return nil , nil , err
109
101
}
110
102
111
103
pbnode , ok := node .(* dag.ProtoNode )
112
104
if ! ok {
113
- return nil , dag .ErrNotProtobuf
105
+ return nil , nil , dag .ErrNotProtobuf
114
106
}
115
107
116
- root , err := mfs .NewRoot (ctx , ipfs .DAG , pbnode , ipnsPubFunc (ipfs , rt . k ))
108
+ root , err := mfs .NewRoot (ctx , ipfs .Dag () , pbnode , ipnsPubFunc (ipfs , key ))
117
109
if err != nil {
118
- return nil , err
110
+ return nil , nil , err
119
111
}
120
112
121
- rt .root = root
122
-
123
- return & Directory {dir : root .GetDirectory ()}, nil
124
- }
125
-
126
- type keyRoot struct {
127
- k ci.PrivKey
128
- alias string
129
- root * mfs.Root
113
+ return root , & Directory {dir : root .GetDirectory ()}, nil
130
114
}
131
115
132
- func CreateRoot (ipfs * core. IpfsNode , keys map [string ]ci. PrivKey , ipfspath , ipnspath string ) (* Root , error ) {
116
+ func CreateRoot (ctx context. Context , ipfs iface. CoreAPI , keys map [string ]iface. Key , ipfspath , ipnspath string ) (* Root , error ) {
133
117
ldirs := make (map [string ]fs.Node )
134
- roots := make (map [string ]* keyRoot )
118
+ roots := make (map [string ]* mfs. Root )
135
119
links := make (map [string ]* Link )
136
120
for alias , k := range keys {
137
- pid , err := peer . IDFromPrivateKey ( k )
121
+ root , fsn , err := loadRoot ( ctx , ipfs , k )
138
122
if err != nil {
139
123
return nil , err
140
124
}
141
- name := pid .Pretty ()
142
125
143
- kr := & keyRoot {k : k , alias : alias }
144
- fsn , err := loadRoot (ipfs .Context (), kr , ipfs , name )
145
- if err != nil {
146
- return nil , err
147
- }
126
+ name := k .ID ().String ()
148
127
149
- roots [name ] = kr
128
+ roots [name ] = root
150
129
ldirs [name ] = fsn
151
130
152
131
// set up alias symlink
@@ -199,25 +178,22 @@ func (s *Root) Lookup(ctx context.Context, name string) (fs.Node, error) {
199
178
200
179
// other links go through ipns resolution and are symlinked into the ipfs mountpoint
201
180
ipnsName := "/ipns/" + name
202
- resolved , err := s .Ipfs .Namesys .Resolve (s . Ipfs . Context () , ipnsName )
181
+ resolved , err := s .Ipfs .Name () .Resolve (ctx , ipnsName )
203
182
if err != nil {
204
183
log .Warnf ("ipns: namesys resolve error: %s" , err )
205
184
return nil , fuse .ENOENT
206
185
}
207
186
208
- segments := resolved .Segments ()
209
- if segments [0 ] == "ipfs" {
210
- p := path .Join (resolved .Segments ()[1 :])
211
- return & Link {s .IpfsRoot + "/" + p }, nil
187
+ if resolved .Namespace () != "ipfs" {
188
+ return nil , errors .New ("invalid path from ipns record" )
212
189
}
213
190
214
- log .Error ("Invalid path.Path: " , resolved )
215
- return nil , errors .New ("invalid path from ipns record" )
191
+ return & Link {s .IpfsRoot + "/" + strings .TrimPrefix ("/ipfs/" , resolved .String ())}, nil
216
192
}
217
193
218
194
func (r * Root ) Close () error {
219
195
for _ , mr := range r .Roots {
220
- err := mr .root . Close ()
196
+ err := mr .Close ()
221
197
if err != nil {
222
198
return err
223
199
}
@@ -241,12 +217,8 @@ func (r *Root) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
241
217
242
218
var listing []fuse.Dirent
243
219
for alias , k := range r .Keys {
244
- pid , err := peer .IDFromPrivateKey (k )
245
- if err != nil {
246
- continue
247
- }
248
220
ent := fuse.Dirent {
249
- Name : pid .Pretty (),
221
+ Name : k . ID () .Pretty (),
250
222
Type : fuse .DT_Dir ,
251
223
}
252
224
link := fuse.Dirent {
0 commit comments