use multiaddr format to do validation of addresses
This commit is contained in:
parent
e7ff04cef6
commit
648902840d
|
@ -8,6 +8,7 @@ import (
|
||||||
|
|
||||||
lgbl "github.com/ipfs/go-libp2p/loggables"
|
lgbl "github.com/ipfs/go-libp2p/loggables"
|
||||||
manet "gx/ipfs/QmQB7mNP3QE7b4zP2MQmsyJDqG5hzYE2CL8k1VyLWky2Ed/go-multiaddr-net"
|
manet "gx/ipfs/QmQB7mNP3QE7b4zP2MQmsyJDqG5hzYE2CL8k1VyLWky2Ed/go-multiaddr-net"
|
||||||
|
mafmt "gx/ipfs/QmWLfU4tstw2aNcTykDm44xbSTCYJ9pUJwfhQCKGwckcHx/mafmt"
|
||||||
context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
|
context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
|
||||||
reuseport "gx/ipfs/QmaaC9QMYTQHCbMq3Ebr3uMaAR2ev4AVqMmsJpgQijAZbJ/go-reuseport"
|
reuseport "gx/ipfs/QmaaC9QMYTQHCbMq3Ebr3uMaAR2ev4AVqMmsJpgQijAZbJ/go-reuseport"
|
||||||
ma "gx/ipfs/QmcobAGsCjYt5DXoq9et9L8yR8er7o7Cu3DTvpaq12jYSz/go-multiaddr"
|
ma "gx/ipfs/QmcobAGsCjYt5DXoq9et9L8yR8er7o7Cu3DTvpaq12jYSz/go-multiaddr"
|
||||||
|
@ -103,7 +104,7 @@ func manetListen(addr ma.Multiaddr) (manet.Listener, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TcpTransport) Matches(a ma.Multiaddr) bool {
|
func (t *TcpTransport) Matches(a ma.Multiaddr) bool {
|
||||||
return IsTcpMultiaddr(a)
|
return mafmt.TCP.Matches(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
type tcpDialer struct {
|
type tcpDialer struct {
|
||||||
|
@ -199,7 +200,7 @@ func (d *tcpDialer) reuseDial(raddr ma.Multiaddr) (manet.Conn, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *tcpDialer) Matches(a ma.Multiaddr) bool {
|
func (d *tcpDialer) Matches(a ma.Multiaddr) bool {
|
||||||
return IsTcpMultiaddr(a)
|
return mafmt.TCP.Matches(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
type tcpListener struct {
|
type tcpListener struct {
|
||||||
|
|
|
@ -49,13 +49,3 @@ type TimeoutOpt time.Duration
|
||||||
type ReuseportOpt bool
|
type ReuseportOpt bool
|
||||||
|
|
||||||
var ReusePorts ReuseportOpt = true
|
var ReusePorts ReuseportOpt = true
|
||||||
|
|
||||||
func IsTcpMultiaddr(a ma.Multiaddr) bool {
|
|
||||||
p := a.Protocols()
|
|
||||||
return len(p) == 2 && (p[0].Name == "ip4" || p[0].Name == "ip6") && p[1].Name == "tcp"
|
|
||||||
}
|
|
||||||
|
|
||||||
func IsUtpMultiaddr(a ma.Multiaddr) bool {
|
|
||||||
p := a.Protocols()
|
|
||||||
return len(p) == 3 && p[2].Name == "utp"
|
|
||||||
}
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
manet "gx/ipfs/QmQB7mNP3QE7b4zP2MQmsyJDqG5hzYE2CL8k1VyLWky2Ed/go-multiaddr-net"
|
manet "gx/ipfs/QmQB7mNP3QE7b4zP2MQmsyJDqG5hzYE2CL8k1VyLWky2Ed/go-multiaddr-net"
|
||||||
mautp "gx/ipfs/QmQB7mNP3QE7b4zP2MQmsyJDqG5hzYE2CL8k1VyLWky2Ed/go-multiaddr-net/utp"
|
mautp "gx/ipfs/QmQB7mNP3QE7b4zP2MQmsyJDqG5hzYE2CL8k1VyLWky2Ed/go-multiaddr-net/utp"
|
||||||
utp "gx/ipfs/QmVs3wq4cN64TFCxANzgSHjGPrjMnRnwPrxU8bqc7YP42s/utp"
|
utp "gx/ipfs/QmVs3wq4cN64TFCxANzgSHjGPrjMnRnwPrxU8bqc7YP42s/utp"
|
||||||
|
mafmt "gx/ipfs/QmWLfU4tstw2aNcTykDm44xbSTCYJ9pUJwfhQCKGwckcHx/mafmt"
|
||||||
ma "gx/ipfs/QmcobAGsCjYt5DXoq9et9L8yR8er7o7Cu3DTvpaq12jYSz/go-multiaddr"
|
ma "gx/ipfs/QmcobAGsCjYt5DXoq9et9L8yR8er7o7Cu3DTvpaq12jYSz/go-multiaddr"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -22,8 +23,7 @@ func NewUtpTransport() *UtpTransport {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *UtpTransport) Matches(a ma.Multiaddr) bool {
|
func (d *UtpTransport) Matches(a ma.Multiaddr) bool {
|
||||||
p := a.Protocols()
|
return mafmt.UTP.Matches(a)
|
||||||
return len(p) == 3 && p[2].Name == "utp"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type UtpSocket struct {
|
type UtpSocket struct {
|
||||||
|
@ -129,8 +129,7 @@ func (s *UtpSocket) Accept() (Conn, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *UtpSocket) Matches(a ma.Multiaddr) bool {
|
func (s *UtpSocket) Matches(a ma.Multiaddr) bool {
|
||||||
p := a.Protocols()
|
return mafmt.UTP.Matches(a)
|
||||||
return len(p) == 3 && p[2].Name == "utp"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *UtpSocket) Close() error {
|
func (t *UtpSocket) Close() error {
|
||||||
|
|
|
@ -127,6 +127,12 @@
|
||||||
"name": "go-peerstream",
|
"name": "go-peerstream",
|
||||||
"hash": "QmQDPXRFzRcCGPbPViQCKjzbQBkZGpLV1f9KwXnksSNcTK",
|
"hash": "QmQDPXRFzRcCGPbPViQCKjzbQBkZGpLV1f9KwXnksSNcTK",
|
||||||
"version": "0.0.0"
|
"version": "0.0.0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"author": "whyrusleeping",
|
||||||
|
"name": "mafmt",
|
||||||
|
"hash": "QmWLfU4tstw2aNcTykDm44xbSTCYJ9pUJwfhQCKGwckcHx",
|
||||||
|
"version": "0.0.0"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"language": "go",
|
"language": "go",
|
||||||
|
|
Loading…
Reference in New Issue