Skip to content

Commit

Permalink
Merge pull request #111 from godcong/master
Browse files Browse the repository at this point in the history
fix #108
  • Loading branch information
Stebalien authored Sep 18, 2019
2 parents 5b1de2f + bbcf5cb commit 37eceec
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
44 changes: 44 additions & 0 deletions protocols.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ package multiaddr
const (
P_IP4 = 0x0004
P_TCP = 0x0006
P_DNS4 = 0x0036
P_DNS6 = 0x0037
P_DNSADDR = 0x0038
P_UDP = 0x0111
P_DCCP = 0x0021
P_IP6 = 0x0029
P_IP6ZONE = 0x002A
P_QUIC = 0x01CC
P_SCTP = 0x0084
P_CIRCUIT = 0x0122
P_UDT = 0x012D
P_UTP = 0x012E
P_UNIX = 0x0190
Expand All @@ -23,6 +27,7 @@ const (
P_GARLIC64 = 0x01BE
P_GARLIC32 = 0x01BF
P_P2P_WEBRTC_DIRECT = 0x0114
P_WS = 0x01DD
)

var (
Expand All @@ -42,6 +47,27 @@ var (
Path: false,
Transcoder: TranscoderPort,
}
protoDNS4 = Protocol{
Code: P_DNS4,
Size: LengthPrefixedVarSize,
Name: "dns4",
VCode: CodeToVarint(P_DNS4),
Transcoder: TranscoderDns,
}
protoDNS6 = Protocol{
Code: P_DNS6,
Size: LengthPrefixedVarSize,
Name: "dns6",
VCode: CodeToVarint(P_DNS6),
Transcoder: TranscoderDns,
}
protoDNSADDR = Protocol{
Code: P_DNSADDR,
Size: LengthPrefixedVarSize,
Name: "dnsaddr",
VCode: CodeToVarint(P_DNSADDR),
Transcoder: TranscoderDns,
}
protoUDP = Protocol{
Name: "udp",
Code: P_UDP,
Expand Down Expand Up @@ -81,6 +107,14 @@ var (
Size: 16,
Transcoder: TranscoderPort,
}

protoCIRCUIT = Protocol{
Code: P_CIRCUIT,
Size: 0,
Name: "p2p-circuit",
VCode: CodeToVarint(P_CIRCUIT),
}

protoONION2 = Protocol{
Name: "onion",
Code: P_ONION,
Expand Down Expand Up @@ -154,17 +188,26 @@ var (
Code: P_P2P_WEBRTC_DIRECT,
VCode: CodeToVarint(P_P2P_WEBRTC_DIRECT),
}
protoWS = Protocol{
Name: "ws",
Code: P_WS,
VCode: CodeToVarint(P_WS),
}
)

func init() {
for _, p := range []Protocol{
protoIP4,
protoTCP,
protoDNS4,
protoDNS6,
protoDNSADDR,
protoUDP,
protoDCCP,
protoIP6,
protoIP6ZONE,
protoSCTP,
protoCIRCUIT,
protoONION2,
protoONION3,
protoGARLIC64,
Expand All @@ -177,6 +220,7 @@ func init() {
protoP2P,
protoUNIX,
protoP2P_WEBRTC_DIRECT,
protoWS,
} {
if err := AddProtocol(p); err != nil {
panic(err)
Expand Down
17 changes: 17 additions & 0 deletions transcoders.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,20 @@ func unixStB(s string) ([]byte, error) {
func unixBtS(b []byte) (string, error) {
return string(b), nil
}

var TranscoderDns = NewTranscoderFromFunctions(dnsStB, dnsBtS, dnsVal)

func dnsVal(b []byte) error {
if bytes.IndexByte(b, '/') >= 0 {
return fmt.Errorf("domain name %q contains a slash", string(b))
}
return nil
}

func dnsStB(s string) ([]byte, error) {
return []byte(s), nil
}

func dnsBtS(b []byte) (string, error) {
return string(b), nil
}

0 comments on commit 37eceec

Please sign in to comment.