@@ -3,6 +3,7 @@ package manet
3
3
import (
4
4
"fmt"
5
5
"net"
6
+ "path/filepath"
6
7
7
8
ma "github.com/multiformats/go-multiaddr"
8
9
madns "github.com/multiformats/go-multiaddr-dns"
@@ -61,6 +62,8 @@ func parseBasicNetMaddr(maddr ma.Multiaddr) (net.Addr, error) {
61
62
return net .ResolveUDPAddr (network , host )
62
63
case "ip" , "ip4" , "ip6" :
63
64
return net .ResolveIPAddr (network , host )
65
+ case "unix" :
66
+ return net .ResolveUnixAddr (network , host )
64
67
}
65
68
66
69
return nil , fmt .Errorf ("network not supported: %s" , network )
@@ -137,6 +140,10 @@ func DialArgs(m ma.Multiaddr) (string, string, error) {
137
140
hostname = true
138
141
ip = c .Value ()
139
142
return true
143
+ case ma .P_UNIX :
144
+ network = "unix"
145
+ ip = c .Value ()
146
+ return false
140
147
}
141
148
case "ip4" :
142
149
switch c .Protocol ().Code {
@@ -184,6 +191,8 @@ func DialArgs(m ma.Multiaddr) (string, string, error) {
184
191
return network , ip + ":" + port , nil
185
192
}
186
193
return network , "[" + ip + "]" + ":" + port , nil
194
+ case "unix" :
195
+ return network , ip , nil
187
196
default :
188
197
return "" , "" , fmt .Errorf ("%s is not a 'thin waist' address" , m )
189
198
}
@@ -248,3 +257,12 @@ func parseIPPlusNetAddr(a net.Addr) (ma.Multiaddr, error) {
248
257
}
249
258
return FromIP (ac .IP )
250
259
}
260
+
261
+ func parseUnixNetAddr (a net.Addr ) (ma.Multiaddr , error ) {
262
+ ac , ok := a .(* net.UnixAddr )
263
+ if ! ok {
264
+ return nil , errIncorrectNetAddr
265
+ }
266
+ cleaned := filepath .Clean (ac .Name )
267
+ return ma .NewComponent ("unix" , cleaned )
268
+ }
0 commit comments