mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-26 23:53:19 +08:00
chore(deps:go-multiaddr) update to b90678896b52c
procedure is to execute ``` cd my/github.com/jbenet/go-multiaddr git pull cd my/github.com/jbenet/go-ipfs godep update github.com/jbenet/go-multiaddr ```
This commit is contained in:
4
Godeps/Godeps.json
generated
4
Godeps/Godeps.json
generated
@ -55,8 +55,8 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/jbenet/go-multiaddr",
|
"ImportPath": "github.com/jbenet/go-multiaddr",
|
||||||
"Comment": "0.1.0-1-g99196c0",
|
"Comment": "0.1.2",
|
||||||
"Rev": "99196c0d231f83eea7f6e47cf59cbb5a0b86b358"
|
"Rev": "b90678896b52c3e5a4c8176805c6facc3fe3eb82"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/jbenet/go-multihash",
|
"ImportPath": "github.com/jbenet/go-multihash",
|
||||||
|
16
Godeps/_workspace/src/github.com/jbenet/go-multiaddr/codec.go
generated
vendored
16
Godeps/_workspace/src/github.com/jbenet/go-multiaddr/codec.go
generated
vendored
@ -8,10 +8,14 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func StringToBytes(s string) ([]byte, error) {
|
func stringToBytes(s string) ([]byte, error) {
|
||||||
b := []byte{}
|
b := []byte{}
|
||||||
sp := strings.Split(s, "/")
|
sp := strings.Split(s, "/")
|
||||||
|
|
||||||
|
if sp[0] != "" {
|
||||||
|
return nil, fmt.Errorf("invalid multiaddr, must begin with /")
|
||||||
|
}
|
||||||
|
|
||||||
// consume first empty elem
|
// consume first empty elem
|
||||||
sp = sp[1:]
|
sp = sp[1:]
|
||||||
|
|
||||||
@ -22,7 +26,7 @@ func StringToBytes(s string) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
b = append(b, byte(p.Code))
|
b = append(b, byte(p.Code))
|
||||||
|
|
||||||
a := AddressStringToBytes(p, sp[1])
|
a := addressStringToBytes(p, sp[1])
|
||||||
b = append(b, a...)
|
b = append(b, a...)
|
||||||
|
|
||||||
sp = sp[2:]
|
sp = sp[2:]
|
||||||
@ -30,7 +34,7 @@ func StringToBytes(s string) ([]byte, error) {
|
|||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func BytesToString(b []byte) (ret string, err error) {
|
func bytesToString(b []byte) (ret string, err error) {
|
||||||
// panic handler, in case we try accessing bytes incorrectly.
|
// panic handler, in case we try accessing bytes incorrectly.
|
||||||
defer func() {
|
defer func() {
|
||||||
if e := recover(); e != nil {
|
if e := recover(); e != nil {
|
||||||
@ -49,7 +53,7 @@ func BytesToString(b []byte) (ret string, err error) {
|
|||||||
s = strings.Join([]string{s, "/", p.Name}, "")
|
s = strings.Join([]string{s, "/", p.Name}, "")
|
||||||
b = b[1:]
|
b = b[1:]
|
||||||
|
|
||||||
a := AddressBytesToString(p, b[:(p.Size/8)])
|
a := addressBytesToString(p, b[:(p.Size/8)])
|
||||||
if len(a) > 0 {
|
if len(a) > 0 {
|
||||||
s = strings.Join([]string{s, "/", a}, "")
|
s = strings.Join([]string{s, "/", a}, "")
|
||||||
}
|
}
|
||||||
@ -59,7 +63,7 @@ func BytesToString(b []byte) (ret string, err error) {
|
|||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddressStringToBytes(p *Protocol, s string) []byte {
|
func addressStringToBytes(p *Protocol, s string) []byte {
|
||||||
switch p.Code {
|
switch p.Code {
|
||||||
|
|
||||||
// ipv4,6
|
// ipv4,6
|
||||||
@ -79,7 +83,7 @@ func AddressStringToBytes(p *Protocol, s string) []byte {
|
|||||||
return []byte{}
|
return []byte{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddressBytesToString(p *Protocol, b []byte) string {
|
func addressBytesToString(p *Protocol, b []byte) string {
|
||||||
switch p.Code {
|
switch p.Code {
|
||||||
|
|
||||||
// ipv4,6
|
// ipv4,6
|
||||||
|
15
Godeps/_workspace/src/github.com/jbenet/go-multiaddr/index.go
generated
vendored
15
Godeps/_workspace/src/github.com/jbenet/go-multiaddr/index.go
generated
vendored
@ -5,22 +5,26 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Multiaddr is the data structure representing a multiaddr
|
||||||
type Multiaddr struct {
|
type Multiaddr struct {
|
||||||
Bytes []byte
|
Bytes []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewMultiaddr parses and validates an input string, returning a *Multiaddr
|
||||||
func NewMultiaddr(s string) (*Multiaddr, error) {
|
func NewMultiaddr(s string) (*Multiaddr, error) {
|
||||||
b, err := StringToBytes(s)
|
b, err := stringToBytes(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &Multiaddr{Bytes: b}, nil
|
return &Multiaddr{Bytes: b}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// String returns the string representation of a Multiaddr
|
||||||
func (m *Multiaddr) String() (string, error) {
|
func (m *Multiaddr) String() (string, error) {
|
||||||
return BytesToString(m.Bytes)
|
return bytesToString(m.Bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Protocols returns the list of protocols this Multiaddr has.
|
||||||
func (m *Multiaddr) Protocols() (ret []*Protocol, err error) {
|
func (m *Multiaddr) Protocols() (ret []*Protocol, err error) {
|
||||||
|
|
||||||
// panic handler, in case we try accessing bytes incorrectly.
|
// panic handler, in case we try accessing bytes incorrectly.
|
||||||
@ -44,12 +48,14 @@ func (m *Multiaddr) Protocols() (ret []*Protocol, err error) {
|
|||||||
return ps, nil
|
return ps, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Encapsulate wraps a given Multiaddr, returning the resulting joined Multiaddr
|
||||||
func (m *Multiaddr) Encapsulate(o *Multiaddr) *Multiaddr {
|
func (m *Multiaddr) Encapsulate(o *Multiaddr) *Multiaddr {
|
||||||
b := make([]byte, len(m.Bytes)+len(o.Bytes))
|
b := make([]byte, len(m.Bytes)+len(o.Bytes))
|
||||||
b = append(m.Bytes, o.Bytes...)
|
b = append(m.Bytes, o.Bytes...)
|
||||||
return &Multiaddr{Bytes: b}
|
return &Multiaddr{Bytes: b}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Decapsulate unwraps Multiaddr up until the given Multiaddr is found.
|
||||||
func (m *Multiaddr) Decapsulate(o *Multiaddr) (*Multiaddr, error) {
|
func (m *Multiaddr) Decapsulate(o *Multiaddr) (*Multiaddr, error) {
|
||||||
s1, err := m.String()
|
s1, err := m.String()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -68,9 +74,10 @@ func (m *Multiaddr) Decapsulate(o *Multiaddr) (*Multiaddr, error) {
|
|||||||
return NewMultiaddr(s1[:i])
|
return NewMultiaddr(s1[:i])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DialArgs is a convenience function returning arguments for use in net.Dial
|
||||||
func (m *Multiaddr) DialArgs() (string, string, error) {
|
func (m *Multiaddr) DialArgs() (string, string, error) {
|
||||||
if !m.IsThinWaist() {
|
if !m.IsThinWaist() {
|
||||||
return "", "", fmt.Errorf("%s is not a 'thin waist' address.", m)
|
return "", "", fmt.Errorf("%s is not a 'thin waist' address", m)
|
||||||
}
|
}
|
||||||
|
|
||||||
str, err := m.String()
|
str, err := m.String()
|
||||||
@ -84,6 +91,8 @@ func (m *Multiaddr) DialArgs() (string, string, error) {
|
|||||||
return network, host, nil
|
return network, host, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsThinWaist returns whether this multiaddr includes "Thin Waist" Protocols.
|
||||||
|
// This means: /{IP4, IP6}/{TCP, UDP}
|
||||||
func (m *Multiaddr) IsThinWaist() bool {
|
func (m *Multiaddr) IsThinWaist() bool {
|
||||||
p, err := m.Protocols()
|
p, err := m.Protocols()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
4
Godeps/_workspace/src/github.com/jbenet/go-multiaddr/multiaddr_test.go
generated
vendored
4
Godeps/_workspace/src/github.com/jbenet/go-multiaddr/multiaddr_test.go
generated
vendored
@ -14,7 +14,7 @@ func TestStringToBytes(t *testing.T) {
|
|||||||
t.Error("failed to decode hex", h)
|
t.Error("failed to decode hex", h)
|
||||||
}
|
}
|
||||||
|
|
||||||
b2, err := StringToBytes(s)
|
b2, err := stringToBytes(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("failed to convert", s)
|
t.Error("failed to convert", s)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func TestBytesToString(t *testing.T) {
|
|||||||
t.Error("failed to decode hex", h)
|
t.Error("failed to decode hex", h)
|
||||||
}
|
}
|
||||||
|
|
||||||
s2, err := BytesToString(b)
|
s2, err := bytesToString(b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("failed to convert", b)
|
t.Error("failed to convert", b)
|
||||||
}
|
}
|
||||||
|
5
Godeps/_workspace/src/github.com/jbenet/go-multiaddr/protocols.go
generated
vendored
5
Godeps/_workspace/src/github.com/jbenet/go-multiaddr/protocols.go
generated
vendored
@ -1,5 +1,6 @@
|
|||||||
package multiaddr
|
package multiaddr
|
||||||
|
|
||||||
|
// Protocol is a Multiaddr protocol description structure.
|
||||||
type Protocol struct {
|
type Protocol struct {
|
||||||
Code int
|
Code int
|
||||||
Size int
|
Size int
|
||||||
@ -10,7 +11,6 @@ type Protocol struct {
|
|||||||
// 1. avoid parsing the csv
|
// 1. avoid parsing the csv
|
||||||
// 2. ensuring errors in the csv don't screw up code.
|
// 2. ensuring errors in the csv don't screw up code.
|
||||||
// 3. changing a number has to happen in two places.
|
// 3. changing a number has to happen in two places.
|
||||||
|
|
||||||
const (
|
const (
|
||||||
P_IP4 = 4
|
P_IP4 = 4
|
||||||
P_TCP = 6
|
P_TCP = 6
|
||||||
@ -20,6 +20,7 @@ const (
|
|||||||
P_SCTP = 132
|
P_SCTP = 132
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Protocols is the list of multiaddr protocols supported by this module.
|
||||||
var Protocols = []*Protocol{
|
var Protocols = []*Protocol{
|
||||||
&Protocol{P_IP4, 32, "ip4"},
|
&Protocol{P_IP4, 32, "ip4"},
|
||||||
&Protocol{P_TCP, 16, "tcp"},
|
&Protocol{P_TCP, 16, "tcp"},
|
||||||
@ -32,6 +33,7 @@ var Protocols = []*Protocol{
|
|||||||
// {443, 0, "https"},
|
// {443, 0, "https"},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ProtocolWithName returns the Protocol description with given string name.
|
||||||
func ProtocolWithName(s string) *Protocol {
|
func ProtocolWithName(s string) *Protocol {
|
||||||
for _, p := range Protocols {
|
for _, p := range Protocols {
|
||||||
if p.Name == s {
|
if p.Name == s {
|
||||||
@ -41,6 +43,7 @@ func ProtocolWithName(s string) *Protocol {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ProtocolWithCode returns the Protocol description with given protocol code.
|
||||||
func ProtocolWithCode(c int) *Protocol {
|
func ProtocolWithCode(c int) *Protocol {
|
||||||
for _, p := range Protocols {
|
for _, p := range Protocols {
|
||||||
if p.Code == c {
|
if p.Code == c {
|
||||||
|
Reference in New Issue
Block a user