@@ -24,9 +24,23 @@ type (
24
24
Host struct {
25
25
Maddr multiaddr.Multiaddr `json:"maddr,omitempty"`
26
26
}
27
+ // Guest holds metadata required to establish
28
+ // a client connection to an NFS server.
29
+ Guest struct {
30
+ Maddr multiaddr.Multiaddr `json:"maddr,omitempty"`
31
+ Hostname string `json:"hostname,omitempty"`
32
+ Dirpath string `json:"dirpath,omitempty"`
33
+ LinkSeparator string `json:"linkSeparator,omitempty"`
34
+ LinkLimit uint `json:"linkLimit,omitempty"`
35
+ UID uint32 `json:"uid,omitempty"`
36
+ GID uint32 `json:"gid,omitempty"`
37
+ }
27
38
)
28
39
29
- const HostID filesystem.Host = "NFS"
40
+ const (
41
+ HostID filesystem.Host = "NFS"
42
+ GuestID filesystem.ID = "NFS"
43
+ )
30
44
31
45
func (* Host ) HostID () filesystem.Host { return HostID }
32
46
@@ -76,3 +90,41 @@ func (nh *Host) Mount(fsys fs.FS) (io.Closer, error) {
76
90
go func () { errsCh <- nfs .Serve (goListener , cachedHandler ) }()
77
91
return closerFn , nil
78
92
}
93
+
94
+ func (* Guest ) GuestID () filesystem.ID { return GuestID }
95
+ func (gn * Guest ) UnmarshalJSON (b []byte ) error {
96
+ // multiformats/go-multiaddr issue #100
97
+ var maddrWorkaround struct {
98
+ Maddr maddrc.Multiaddr `json:"maddr,omitempty"`
99
+ }
100
+ if err := json .Unmarshal (b , & maddrWorkaround ); err != nil {
101
+ return err
102
+ }
103
+ gn .Maddr = maddrWorkaround .Maddr .Multiaddr
104
+ return json .Unmarshal (b , & struct {
105
+ Hostname * string `json:"hostname,omitempty"`
106
+ Dirpath * string `json:"dirpath,omitempty"`
107
+ LinkSeparator * string `json:"linkSeparator,omitempty"`
108
+ LinkLimit * uint `json:"linkLimit,omitempty"`
109
+ UID * uint32 `json:"uid,omitempty"`
110
+ GID * uint32 `json:"gid,omitempty"`
111
+ }{
112
+ Hostname : & gn .Hostname ,
113
+ Dirpath : & gn .Dirpath ,
114
+ LinkSeparator : & gn .LinkSeparator ,
115
+ LinkLimit : & gn .LinkLimit ,
116
+ UID : & gn .UID ,
117
+ GID : & gn .GID ,
118
+ })
119
+ }
120
+
121
+ func (gn * Guest ) MakeFS () (fs.FS , error ) {
122
+ return NewNFSGuest (gn .Maddr ,
123
+ WithHostname (gn .Hostname ),
124
+ WithDirpath (gn .Dirpath ),
125
+ WithLinkSeparator (gn .LinkSeparator ),
126
+ WithLinkLimit (gn .LinkLimit ),
127
+ WithUID (gn .UID ),
128
+ WithGID (gn .GID ),
129
+ )
130
+ }
0 commit comments