Skip to content

Commit d08775f

Browse files
committed
nfs: implement Guest mountpoint
1 parent 4ef4fc1 commit d08775f

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

internal/filesystem/nfs/mountpoint.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,17 @@ type (
2424
Host struct {
2525
Maddr multiaddr.Multiaddr `json:"maddr,omitempty"`
2626
}
27+
// Guest holds metadata required to establish
28+
// a client connection to an NFS server.
29+
Guest struct {
30+
Maddr multiaddr.Multiaddr
31+
}
2732
)
2833

29-
const HostID filesystem.Host = "NFS"
34+
const (
35+
HostID filesystem.Host = "NFS"
36+
GuestID filesystem.ID = "NFS"
37+
)
3038

3139
func (*Host) HostID() filesystem.Host { return HostID }
3240

@@ -76,3 +84,21 @@ func (nh *Host) Mount(fsys fs.FS) (io.Closer, error) {
7684
go func() { errsCh <- nfs.Serve(goListener, cachedHandler) }()
7785
return closerFn, nil
7886
}
87+
88+
func (*Guest) GuestID() filesystem.ID { return GuestID }
89+
func (gn *Guest) UnmarshalJSON(b []byte) error {
90+
// multiformats/go-multiaddr issue #100
91+
var maddrWorkaround struct {
92+
Maddr maddrc.Multiaddr `json:"maddr,omitempty"`
93+
}
94+
if err := json.Unmarshal(b, &maddrWorkaround); err != nil {
95+
return err
96+
}
97+
gn.Maddr = maddrWorkaround.Maddr.Multiaddr
98+
return nil
99+
}
100+
101+
func (gn *Guest) MakeFS() (fs.FS, error) {
102+
// TODO: fields to options.
103+
return NewNFSGuest(gn.Maddr)
104+
}

0 commit comments

Comments
 (0)