@@ -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 )
@@ -96,7 +99,8 @@ func FromIP(ip net.IP) (ma.Multiaddr, error) {
96
99
97
100
// DialArgs is a convenience function that returns network and address as
98
101
// expected by net.Dial. See https://godoc.org/net#Dial for an overview of
99
- // possible return values (we do not support the unix* ones yet).
102
+ // possible return values (we do not support the unixpacket ones yet). Unix
103
+ // addresses do not, at present, compose.
100
104
func DialArgs (m ma.Multiaddr ) (string , string , error ) {
101
105
var (
102
106
zone , network , ip , port string
@@ -137,6 +141,10 @@ func DialArgs(m ma.Multiaddr) (string, string, error) {
137
141
hostname = true
138
142
ip = c .Value ()
139
143
return true
144
+ case ma .P_UNIX :
145
+ network = "unix"
146
+ ip = c .Value ()
147
+ return false
140
148
}
141
149
case "ip4" :
142
150
switch c .Protocol ().Code {
@@ -184,6 +192,8 @@ func DialArgs(m ma.Multiaddr) (string, string, error) {
184
192
return network , ip + ":" + port , nil
185
193
}
186
194
return network , "[" + ip + "]" + ":" + port , nil
195
+ case "unix" :
196
+ return network , ip , nil
187
197
default :
188
198
return "" , "" , fmt .Errorf ("%s is not a 'thin waist' address" , m )
189
199
}
@@ -248,3 +258,12 @@ func parseIPPlusNetAddr(a net.Addr) (ma.Multiaddr, error) {
248
258
}
249
259
return FromIP (ac .IP )
250
260
}
261
+
262
+ func parseUnixNetAddr (a net.Addr ) (ma.Multiaddr , error ) {
263
+ ac , ok := a .(* net.UnixAddr )
264
+ if ! ok {
265
+ return nil , errIncorrectNetAddr
266
+ }
267
+ cleaned := filepath .Clean (ac .Name )
268
+ return ma .NewComponent ("unix" , cleaned )
269
+ }
0 commit comments